$(function(){
	var I = new ImageFilter();
	var IC = new ImageFilter_Combine();
	var IMC = new ImageFilter_MultiCombine ();
	var IRC = new ImageFilter_RandomCombine();	
	var control=true;	
	
	//表示ID
	var ViewId = "#MainView_Area";	
	//初期スピード（タイマー当たりの移動 px）	
	var Speed = 0.5;
	//マウスをオーバーしたとき（タイマー当たりの移動 px）	
	var Speed_m = 3;
	//タイマーの設定
	var TimeInterval=25;
	//進行方向（top、down）
	var ScrollDirection = "down";
	//
	var ImgCount = $('#ScrollArea li').length;
	var ImgHeight = $('#ScrollArea li').outerHeight();
	//表示エリアの高さ
	$('#ScrollArea').css('height',(ImgCount+2)*ImgHeight+"px");
	//表示エリアの位置
	$('#ScrollArea').css('top',"-"+ImgHeight+"px");
	var y=0;
	var s=Speed;
	
	//メイン画像の表示番号
	var Max_num = $('#Hidden_imgs li').length-1;
	var num = 0;

	//上下ボタンのマウスオーバー時のメイン画像の変更
	var over=0;	

	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){
			$('#ScrollArea li:first').before($('#ScrollArea li:last').clone());
			$('#ScrollArea li:last').remove();
			y=0;			
			num = num - 1;
			num = check_num(num);
			main_image_change();
			Image_MouseOver();
		}		
		y = y + s;
		$('#ScrollArea li').css('top',y+"px");
	}
		
	//上スクロール
	function timer_action_toT(){
		if(y<=0){
			$('#ScrollArea li:last').after($('#ScrollArea li:first').clone());
			$('#ScrollArea li:first').remove();
			y= ImgHeight;
			num = num + 1;
			num = check_num(num);
			main_image_change();
			Image_MouseOver();			
		}		
		y = y - s;
		$('#ScrollArea li').css('top',y+"px");
	}
	
	//画像をクリックしたとき
	function Image_MouseOver(){
		$('#ScrollArea li img').bind('click',function(){
			num = $(this).attr('name');
			num = check_num(num);
			main_image_change_over();
		});				
	}	
	
	function check_num(num){
		num = parseInt(num);
		if(!isNaN(num)){
			if(num < 0){
				num = Max_num;
			}else if(num > Max_num){
				num = 0;
			}
			return num;	
		}else{
			return false;
		}		
	}
	
	//タイマーでの画像の切替
	function main_image_change(){
		if(!isNaN(num) && over==0){			
		if(control==false){
			if(control==false){control = I.check_action();}			
			if(control==false){control = IC.check_action();}		
			if(control==false){control = IMC.check_action();}
			if(control==false){control = IRC.check_action();}	
		}
			
		if(control==true){
			//フィルターのオブジェクトを呼び出す	
			Vhtml = $('#Hidden_imgs li:eq('+num+')').html();	
			Vname = $('#Hidden_imgs li:eq('+num+') input').val();		

			if(Vname >= 100 && Vname < 200){
				I.set_action(true);
				IC.set_action(false);
				IMC.set_action(false);
				IRC.set_action(false);				
				I.cover(Vname,Vhtml,1500);
				control = I.check_action();	
			}else if(Vname >= 200 && Vname < 300){
				I.set_action(false);
				IC.set_action(true);
				IMC.set_action(false);
				IRC.set_action(false);	
				IC.cover(Vname,Vhtml,3000,7);
				control = IC.check_action();					
			}else if(Vname >= 300 && Vname < 400){
				I.set_action(false);
				IC.set_action(false);
				IMC.set_action(true);
				IRC.set_action(false);
				IMC.cover(Vname,Vhtml);
				control = IMC.check_action();					
			}else if(Vname >= 400 && Vname < 500){
				I.set_action(false);
				IC.set_action(false);
				IMC.set_action(false);
				IRC.set_action(true);
				IRC.cover(Vname,Vhtml);
				control = IRC.check_action();					
			}else{
				I.set_action(true);
				IC.set_action(false);
				IMC.set_action(false);
				IRC.set_action(false);	
				I.cover("101",Vhtml,1000);
				control = I.check_action();					
			}
		}
		}else{
			return false;
		}			
	}	
	
	//画像をクリックしたときの切替
	function main_image_change_over(){
		if(!isNaN(num)){		
			if(control==false){
				if(control==false){control = I.check_action();}			
				if(control==false){control = IC.check_action();}		

				if(control==false){control = IMC.check_action();}
				if(control==false){control = IRC.check_action();}	
			}
				
			if(control==true){
				//フィルターのオブジェクトを呼び出す	
				Vhtml = $('#Hidden_imgs li:eq('+num+')').html();	
				Vname = "101";		
				
				I.set_action(true);
				IC.set_action(false);
				IMC.set_action(false);
				IRC.set_action(false);
				I.cover("101",Vhtml,1000);
				control = I.check_action();
			}
		}else{
			return false;
		}			
	}		
	
	//上のボタン制御
	$('#Topbtn').hover(function(){
		over=1;			
		clear_timer();
		s= Speed_m;
		ScrollDirection="top";
		set_timer();
	},
	function(){
		over=0;
		clear_timer();
		s= Speed;		

		ScrollDirection="top";
		set_timer();			
	});

	//下ボタン制御
	$('#Bottombtn').hover(function(){
		over=1;			
		clear_timer();
		s= Speed_m;
		ScrollDirection="down";
		set_timer();
	},
	function(){
		over=0;		
		clear_timer();
		s= Speed;
		ScrollDirection="down";
		set_timer();			
	});
	
	//スクロールエリアをマウスオーバーしたとき
	$('#ScrollArea').hover(function(){
		clear_timer();
	},
	function(){
		s= Speed;		
		set_timer();			
	});
		
	//自動スタート開始
	if(Max_num==-1){
		$(ViewId).html('<img src="/pickup/img/now.jpg" alt="大阪　風俗　難波秘密倶楽部" />');
	}else if(Max_num==0){
		$(ViewId).html($('#Hidden_imgs li').eq(num).html());
	}else{
		$(ViewId).html($('#Hidden_imgs li').eq(num).html());
		Image_MouseOver();
		set_timer();				
	}	

});




