var sSpeed ='slow'; //スライドアニメーションスピード(ミリ秒)
var sTime = 5000; //ローテーション時間(ミリ秒)
var play;
var n=0;

$(document).ready(function() {
	$("#headlineS ul li:first").addClass("active");
		
	var imageWidth = $("#headlineL").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	rotate = function(){
		var triggerID = $active.find("a").attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;
		$('.active').removeClass('active');
		
		$(".image_reel").animate({
			left: -image_reelPosition,
			opacity:1
		}, {
			duration: sSpeed,
			easing: "swing",
			complete: function(){$active.addClass('active');}
		}
		);
		return false;
	}; 
	
	rotateSwitch = function(){	
		if(play!=undefined) clearInterval(play);
		play = setInterval(function(){
			$active = $('#headlineS ul li.active').next();
			if ( $active.length === 0) {
				$active = $('#headlineS ul li:first');
				$(".image_reel").fadeTo(1500,0.25,function(){
																	clearInterval(play);
																	rotateSwitch();
																	return false;
																});
			}
			rotate();
		}, sTime);
		return false;
	};
	loading();
	
	//On Hover
	$(".image_reel a,#headlineS ul li a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
	
	//On Click
	$("#headlineS ul li a").click(function() {	
		$active = $(this).parent();
		//Reset Timer
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});	
});

function loading() {
	setTimeout(function(){
											$("#loader").hide();
											$("#headlineS ul li").each(function(){
																													$(this).show('slow');
																													});
											$(".image_reel").fadeTo('fast',1,rotateSwitch);
											},1000);
	return false;
}
