$(function(){
//初期スピード（タイマー当たりの移動 px）	
var Speed = 1;
//マウスをオーバーしたとき（タイマー当たりの移動 px）	
var Speed_m = 3;
//タイマーの設定
var TimeInterval=10;
//進行方向（right、left）
var ScrollDirection = "left";
//
var ImgCount = $('#special div').length;
var ImgWidth = $('#special div').outerWidth();
// alert(ImgCount + " / " + ImgWidth);
//表示エリアの幅
$('#special').css('width',(ImgCount+2)*ImgWidth+"px");
//表示エリアの位置
$('#special').css('left',"-"+ImgWidth+"px");

var x=0;
var s=Speed;

	function set_timer(){
		timerID = setInterval(function(){
			if(ScrollDirection =="left"){
				timer_action_toL();				
			}else if(ScrollDirection =="right"){
				timer_action_toR();				
			}else{
				timer_action_toL();
			}
		},TimeInterval);
	}
	
	function clear_timer(){
		clearInterval(timerID);
	}
	
	//左スクロール
	function timer_action_toL(){
		if(x<=0){
			$('#special div:last').after($('#special div:first').clone());
			$('#special div:first').remove();
			x= ImgWidth;
		}		
		x = x - s;
		$('#special div').css('left',x+"px");
	}
	
	//右スクロール
	function timer_action_toR(){
		if(x>=ImgWidth){
			$('#special div:first').before($('#special div:last').clone());
			$('#special div:last').remove();
			x=0;
		}		
		x = x + s;
		$('#special div').css('left',x+"px");
	}
	
	//左のボタン制御
	$('#Leftbtn').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="left";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;		
		ScrollDirection="left";
		set_timer();			
	});

	//右ボタン制御
	$('#Rightbtn').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="right";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;
		ScrollDirection="right";
		set_timer();			
	});
	
	//スクロールエリアをマウスオーバーしたとき
	$('#special').hover(function(){
		clear_timer();
	},
	function(){
		s= Speed;		
		set_timer();			
	});
	
	//移動開始		
	set_timer();
});




