jQuery(function(){
	//初期スピード（タイマー当たりの移動 px）
	var Speed = 0.5;
	//マウスをオーバーしたとき（タイマー当たりの移動 px）
	var Speed_m = 3;
	//タイマーの設定
	var TimeInterval=25;
	//進行方向（top、bottom）
	var ScrollDirection = "bottom";
	
	var ImgCount = jQuery('#ScrollArea li').length;
	var ImgHeight = jQuery('#ScrollArea li').outerHeight();
	var MaxHeight = 0;
	var TotalHeight = 0;
	for (i=0;i<ImgCount;i++){
		h = jQuery('#ScrollArea li:eq('+i+')').outerHeight();
		if (h>MaxHeight) MaxHeight=h;
		TotalHeight+=h;
	}
	
	//表示エリアの高さ
	jQuery('#ScrollArea').css('height',ImgCount*ImgHeight+MaxHeight*2+"px");
	//表示エリアの位置
	jQuery('#ScrollArea').css('top',"-"+MaxHeight+"px");
	var y=0;
	var s=Speed;
	function set_timer(){
		timerID = setInterval(function(){
			if(ScrollDirection =="top"){
				timer_action_toT();				
			}else if(ScrollDirection =="bottom"){
				timer_action_toB();				
			}else{
				timer_action_toT();
			}
		},TimeInterval);
	}
	
	function clear_timer(){
		clearInterval(timerID);
	}
	
	//上スクロール
	function timer_action_toT(){
		if(y<=MaxHeight-jQuery('#ScrollArea li:first').outerHeight()){
			jQuery('#ScrollArea li:last').after(jQuery('#ScrollArea li:first').clone());
			jQuery('#ScrollArea li:first').remove();
			y=MaxHeight;
		}		
		y = y - s;
		jQuery('#ScrollArea li').css('top',y+"px");
	}
	
	//下スクロール
	function timer_action_toB(){
		if(y>=MaxHeight){
			jQuery('#ScrollArea li:first').before(jQuery('#ScrollArea li:last').clone());
			jQuery('#ScrollArea li:last').remove();
			y=MaxHeight-jQuery('#ScrollArea li:first').outerHeight();
		}
		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="bottom";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;
		ScrollDirection="bottom";
		set_timer();			
	});
	
	//スクロールエリアをマウスオーバーしたとき
	jQuery('#ScrollArea').hover(function(){
		clear_timer();
	},
	function(){
		s= Speed;
		set_timer();
	});
	
	//移動開始
	set_timer();

});



