jQuery(function(){
//初期スピード（タイマー当たりの移動 px）	
var Speed = 1;
//マウスをオーバーしたとき（タイマー当たりの移動 px）	
var Speed_m = 3;
//タイマーの設定
var TimeInterval=25;
//進行方向（top、down）
var ScrollDirection = "down";
//
var ImgCount = jQuery('#ScrollArea li').length;
var ImgHeight = jQuery('#ScrollArea li').outerHeight();
//表示エリアの幅
jQuery('#ScrollArea').css('height',(ImgCount+2)*ImgHeight);
//表示エリアの位置
jQuery('#ScrollArea').css('top',"-"+ImgHeight+"px");
var y=0;
var s=Speed;

	function set_timer(){
		timerID = setInterval(function(){
			if(ScrollDirection =="down"){
				timer_action_toD();				
			}else if(ScrollDirection =="top"){
				timer_action_toT();				
			}else{
				timer_action_toD();
			}
		},TimeInterval);
	}
	
	function clear_timer(){
		clearInterval(timerID);
	}
	
	//下スクロール
	function timer_action_toD(){
		if(y>=ImgHeight){
			jQuery('#ScrollArea li:first').before(jQuery('#ScrollArea li:last').clone());
			jQuery('#ScrollArea li:last').remove();
			y=0;
		}		
		y = y + s;
		jQuery('#ScrollArea li').css('top',y+"px");
	}	
	//上スクロール
	function timer_action_toT(){
		if(y<=0){
			jQuery('#ScrollArea li:last').after(jQuery('#ScrollArea li:first').clone());
			jQuery('#ScrollArea li:first').remove();
			y= ImgHeight;
		}		
		y = y - s;
		jQuery('#ScrollArea li').css('top',y+"px");
	}
	
	//左のボタン制御
	jQuery('#Topbtn').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="top";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;		
		ScrollDirection="top";
		set_timer();			
	});

	//右ボタン制御
	jQuery('#Bottombtn').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="down";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;
		ScrollDirection="down";
		set_timer();			
	});
	
	//スクロールエリアをマウスオーバーしたとき
	jQuery('#ScrollArea').hover(function(){
		clear_timer();
	},
	function(){
		s= Speed;		
		set_timer();			
	});
	
	//移動開始		
	set_timer();

});




