var stopTime = 3;		//	停止時間(秒)
var firstStop = 6;		//	初回停止時間(秒)
var secondStop = 20;	//	初回停止時間(秒)
var turnSpeed = 80;		//	移動距離
var turnDirection = 1	//	方向 [1] L->R [-1] R->L
var banerWidth = 950;	//	バナーサイズ

var nowMove = 0;		//	現在移動距離
var stopFlg = false;	//	停止フラグ
var mainStop = false;	//	停止フラグ他
var slideMargin = 0;	//	スクロール位置
var goPosition = 0;		
var timeId,timeId2;

$(document).ready(function(){

	//	CSS初期設定
	var total = $("#slideShow .slideBox").length * banerWidth;
	
	$("#slideShowMain").css('overflow', 'hidden' );
	$("#slideShow").css('width', total + 'px' );
	$("#slideShow .slideBox").css('float', 'left' );
	
	if( turnDirection == 1 ){		$("#slideShow").css('margin-left', '0px' );
	}else{
		slideMargin = total - banerWidth;
		$("#slideShow").css('margin-left', slideMargin + 'px' );
	}
	
	//	カウンタースタート
	timeId = setTimeout("slide()", firstStop * 1000);
	
	$("#titleLine a").mouseover( function(){
		var id = $(this).attr('id');
		id = id.substring(id.length-2,id.length)
		
		slideMargin = id * -banerWidth;
		goPosition = slideMargin;
		$("#slideShow").css('margin-left', slideMargin + 'px' );
		if(!mainStop){
				
			$(this).mouseleave(function(){
				mainStop = true;
				goPosition = 0;
				timeId2 = setTimeout("slideGo()", 0);
			});
		}
		return false;
	});
	
	
});

function slideGo(){
	clearTimeout( timeId2 ); 
	clearTimeout( timeId ); 
	if( goPosition != slideMargin ){
		if( goPosition > slideMargin ){
			slideMargin += turnSpeed;
			
			if( slideMargin >= goPosition ){
				slideMargin = goPosition;
				stopFlg = false;
				mainStop = false;
				nowMove = 0;
			}else	timeId2 = setTimeout("slideGo()", 10);
			
		}else{
			slideMargin -= turnSpeed;

			if( goPosition >= slideMargin ){
				slideMargin = goPosition;
				stopFlg = false;
				mainStop = false;
				nowMove = 0;
			}else	timeId2 = setTimeout("slideGo()", 10);

		}
		$("#slideShow").css('margin-left', slideMargin + 'px' );
	
	}else{
		stopFlg = true;
		nowMove = 0;
		mainStop = false;
//		timeId = setTimeout("slide()", 0);
	}
	
}


function slide(){

	clearTimeout( timeId );
	if(mainStop)	return;
	
	if( stopFlg ){
		stopFlg = false;
		timeId = setTimeout("slide()", stopTime * 1000);
	}else{
		slideMargin += turnSpeed * turnDirection * -1;
		nowMove += turnSpeed;
		if( nowMove >= banerWidth ){
			slideMargin += (nowMove - banerWidth) * turnDirection;
			stopFlg = true;
			
			if(turnDirection == -1 ){
				if(slideMargin < 0)	timeId = setTimeout("slide()", 0);
			}else{
				var i = banerWidth * ($("#slideShow .slideBox").length-1) * -1;
				if(slideMargin > i)	timeId = setTimeout("slide()", 0);
			}
			nowMove = 0;
			
		}else{
		
			timeId = setTimeout("slide()", 10);
			
		}
		
		$("#slideShow").css('margin-left', slideMargin + 'px' );

	}
	
}
