(function($) {
	$(function() {
		var openclose = 1;/* 開いた状態か閉じた状態かを切り替え */
		$('.newsbtn').prepend('<img class="openbtn" src="images/btn_newsopen.gif" alt="全て表示" />');
		
		if(openclose ==0){  
				
						  		function IntervalFn(onoff){
						  			var count = 0,
										end = $("#sg_news ul li").length-1;
									var interval = 5000;
										
									
						  			if($("#sg_news ul li").length<=1) return false;
						  			
						  			if(onoff == 0){	
						  				$("#sg_news ul li").each(
						  					function(i){
						      					$(this).attr("id","news-"+i);
						     					if(i!=0) $(this).hide();
						     				}
						     			);
						     			
						     			fadeTimer = setInterval(function(){
						     				if(count != end){
						      					$("li#news-"+count).hide();
						     					$("li#news-"+(++count)).fadeIn("slow");
						     				}else{
						     					count=0;
						     					$("li#news-"+end).hide();
						     					$("li#news-"+count).fadeIn("slow");
						     				}
						    			},interval);
						    			
						     			//window.alert(onoff);
						     		}else{
						     			$("#sg_news ul li").each(
						  					function(i){
						      					$(this).removeAttr("id");
						     					if(i!=-1) $(this).fadeIn();
						     				}
						     			);
						     			count = 0;
						     			clearInterval(fadeTimer);
						     			//window.alert(onoff);
						     		};
						  		};
								
								$('.newsbtn').toggle(
								
									function(){
										$('.openbtn').fadeTo("normal",1.0);
						  				$('#sg_news ul li').css({
						  					position:"absolute",
						  					top:"5px",
						  					left:"80px"
						  					//opacity:"0",
						  					//filter:"alpha(opacity=0)"
						  				});
						  				$('.newsplace ul').insertBefore('.newsplace');
						  				
						  				$('.newsplace').slideUp('normal',IntervalFn(0));
						  				
						  			},
						  			
						  			function(){
										$('.openbtn').fadeTo("normal",0);
						  				$('#sg_news ul li').css({
						  					position:"static",
						  					top:"0",
						  					left:"0",
						  					opacity:"1",
						  					filter:"alpha(opacity=100)"
						  				});
						  				$('#sg_news ul').prependTo('.newsplace');
						  				
						  				$('.newsplace').slideDown('normal',IntervalFn(1));
						  				
						  			}
								);
			
		}else{

						  		
						  		function IntervalFn(onoff){
						  			var count = 0,
										end = $("#sg_news ul li").length-1;
									var interval = 5000;
										
									
						  			if($("#sg_news ul li").length<=1) return false;
						  			
						  			if(onoff == 0){	
						  				$("#sg_news ul li").each(
						  					function(i){
						      					$(this).attr("id","news-"+i);
						     					if(i!=0) $(this).hide();
						     				}
						     			);
						     			
						     			fadeTimer = setInterval(function(){
						     				if(count != end){
						      					$("li#news-"+count).hide();
						     					$("li#news-"+(++count)).fadeIn("slow");
						     				}else{
						     					count=0;
						     					$("li#news-"+end).hide();
						     					$("li#news-"+count).fadeIn("slow");
						     				}
						    			},interval);
						    			
						     			//window.alert(onoff);
						     		}else{
						     			$("#sg_news ul li").each(
						  					function(i){
						      					$(this).removeAttr("id");
						     					if(i!=-1) $(this).fadeIn();
						     				}
						     			);
						     			count = 0;
						     			clearInterval(fadeTimer);
						     			//window.alert(onoff);
						     		};
						  		};
								
								$('.newsbtn').toggle(
								
									function(){
										
						  				$('.openbtn').fadeTo("normal",0);
						  				$('#sg_news ul li').css({
						  					position:"static",
						  					top:"0",
						  					left:"0",
						  					opacity:"1",
						  					filter:"alpha(opacity=100)"
						  				});
						  				$('#sg_news ul').prependTo('.newsplace');
						  				
						  				$('.newsplace').slideDown('normal',IntervalFn(1));
						  				
						  			},
						  			
						  			function(){
						  				
						  				$('.openbtn').fadeTo("normal",1.0);
						  				$('#sg_news ul li').css({
						  					position:"absolute",
						  					top:"5px",
						  					left:"80px"
						  					//opacity:"0",
						  					//filter:"alpha(opacity=0)"
						  				});
						  				$('.newsplace ul').insertBefore('.newsplace');
						  				
						  				$('.newsplace').slideUp('normal',IntervalFn(0));						  				
						  			}
								);
								
								
								$('.openbtn').fadeTo("normal",1.0);
						  		$('#sg_news ul li').css({
						  			position:"absolute",
						  			top:"5px",
						  			left:"80px"
						  			//opacity:"0",
						  			//filter:"alpha(opacity=0)"
						  		});
						  		$('.newsplace ul').insertBefore('.newsplace');
						  				
						  		$('.newsplace').slideUp('normal',IntervalFn(0));
		
		}
	});
		
})(jQuery);
