$(function(){
//初期スピード（タイマー当たりの移動 px）	
var Speed = 0.7;
//マウスをオーバーしたとき（タイマー当たりの移動 px）	
var Speed_m = 2;
//タイマーの設定
var TimeInterval=25;
//進行方向（top、down）
//var ScrollDirection = "down";

aaa = "test";
var ScrollDirection = ScrollDirection;
//
var ImgCount = $('#RSIDE li').length;
var ImgHeight = $('#RSIDE li').outerHeight();
//表示エリアの幅
//$('#RSIDE').css('height',(ImgCount+2)*ImgHeight);
//表示エリアの位置
$('#RSIDE').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_toNone();
			}
		},TimeInterval);
	}
	
	function clear_timer(){
		clearInterval(timerID);
	}
set_timer();

clear_timer();


	//下スクロール
	function timer_action_toD(){
		if(y>=ImgHeight){
			$('#RSIDE li:first').before($('#RSIDE li:last').clone());
			$('#RSIDE li:last').remove();
			y=0;
		}		
		y = y + s;
		$('#RSIDE li').css('top',y+"px");
	}	
	//上スクロール
	function timer_action_toT(){
		if(y<=0){
			$('#RSIDE li:last').after($('#RSIDE li:first').clone());
			$('#RSIDE li:first').remove();
			y= ImgHeight;
		}		
		y = y - s;
		$('#RSIDE li').css('top',y+"px");
	}
	//スクロールなし
	function timer_action_toNone(){
		if(y<=0){
			$('#RSIDE li:last').after($('#RSIDE li:first').clone());
			$('#RSIDE li:first').remove();
			y= ImgHeight;
		}		
		y = y;
		$('#RSIDE li').css('top',y+"px");
	}
	
	//左のボタン制御
	$('.btnT').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="top";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;		
		ScrollDirection="top";
		//set_timer();			
	});

	//右ボタン制御
	$('.btnB').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="down";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;
		ScrollDirection="down";
		//set_timer();			
	});








	//左のボタン制御
	$('.btnL').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="left";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;		
		ScrollDirection="left";
		//set_timer();			
	});

	//右ボタン制御
	$('.btnR').hover(function(){
		clear_timer();
		s= Speed_m;
		ScrollDirection="right";
		set_timer();
	},
	function(){
		clear_timer();
		s= Speed;
		ScrollDirection="right";
		//set_timer();			
	});







	//スクロールエリアをマウスオーバーしたとき
	$('#RSIDE ul').hover(function(){
		clear_timer();
	},
	function(){
		s= Speed;		
		//set_timer();			
	});
	
	//移動開始		
	set_timer();

});



