$(function(){
//初期スピード（タイマー当たりの移動 px）	
var Speed2 = 2;
//マウスをオーバーしたとき（タイマー当たりの移動 px）	
var Speed_m2 = 4;
//タイマーの設定
var TimeInterval2 = 25;
//進行方向（right、left）
var ScrollDirection2 = "left";
//
var ImgCount2 = $('#ScrollArea2 li').length;
var ImgWidth2 = $('#ScrollArea2 li').outerWidth();
//表示エリアの幅
$('#ScrollArea2').css('width',(ImgCount2+2)*ImgWidth2+"px");
//表示エリアの位置
$('#ScrollArea2').css('left',"-"+ImgWidth2+"px");
var x=0;
var s=Speed2;

	function set_timer2(){
		timerID = setInterval(function(){
			if(ScrollDirection2 =="left"){
				timer_action_toL2();				
			}else if(ScrollDirection2 =="right"){
				timer_action_toR2();				
			}else{
				timer_action_toL2();
			}
		},TimeInterval2);
	}
	
	function clear_timer2(){
		clearInterval(timerID);
	}
	
	//左スクロール
	function timer_action_toL2(){
		if(x<=0){
			$('#ScrollArea2 li:last').after($('#ScrollArea2 li:first').clone());
			$('#ScrollArea2 li:first').remove();
			x= ImgWidth2;
		}		
		x = x - s;
		$('#ScrollArea2 li').css('left',x+"px");
	}
	
	//右スクロール
	function timer_action_toR2(){
		if(x>=ImgWidth2){
			$('#ScrollArea2 li:first').before($('#ScrollArea2 li:last').clone());
			$('#ScrollArea2 li:last').remove();
			x=0;
		}		
		x = x + s;
		$('#ScrollArea2 li').css('left',x+"px");
	}
	
	//左のボタン制御
	$('#Leftbtn2').hover(function(){
		clear_timer2();
		s= Speed_m2;
		ScrollDirection2="left";
		set_timer2();
	},
	function(){
		clear_timer2();
		s= Speed2;		
		ScrollDirection2="left";
		set_timer2();			
	});

	//右ボタン制御
	$('#Rightbtn2').hover(function(){
		clear_timer2();
		s= Speed_m2;
		ScrollDirection2="right";
		set_timer2();
	},
	function(){
		clear_timer2();
		s= Speed2;
		ScrollDirection2="right";
		set_timer2();			
	});
	
	//スクロールエリアをマウスオーバーしたとき
	$('#ScrollArea2').hover(function(){
		clear_timer2();
	},
	function(){
		s= Speed2;
		set_timer2();
	});
	
	//移動開始
	set_timer2();
});




