var ImageFilter_MultiCombine = function(){
	var ViewId = "#MainView_Area";	
	var html;
	var Fname;
	var html2;
	
	//一つずつ表示する時の時間と間隔
	var Timer = 200;		
	var TimeInterval = 100;
	//イッキに表示するときの時間
	var Timer_all = 800;

	//画像分割　変更しないでください。
	var x_split = 5;
	var y_split = 5;
		
	//表示順番	
	var num_ary_1 = new Array(); 
	var num_ary_2 = new Array();
	var num_ary_3 = new Array(); 
	
	//座標保管用
	var x_posi = new Array();
	var y_posi = new Array();
	
	//移動方向
	var direction;

	// controlがtrueの時に処理を開始する
	var control=false;	
	this.check_action = function(){
		return control;
	}
	
	this.set_action =function(co){
		if(co == true){
			control = true;
		}else{
			control = false;
		}
	}
			
	this.cover = function(Vname,Vhtml,Vdirection){		
		if(control!=true){ return false; }	
		if(Vname){ Fname = Vname; }else{ return false; }				
		if(Vhtml){ html = Vhtml; }else{ return false; }		
		if(Vdirection){ direction = Vdirection; }else{direction ="";}

		switch(Vname){
			case "MyPattern_1":
			case "301":
				this.MyPattern_1();
			break;
			
			case "MyPattern_2":
			case "302":
				this.MyPattern_2();
			break;			

			case "MyPattern_3":
			case "303":
				this.MyPattern_3();
			break;	
			
			case "MyPattern_4":
			case "304":
				this.MyPattern_4();
			break;	

			case "MyPattern_5":
			case "305":
				this.MyPattern_5();
			break;	
			
			case "MyPattern_6":
			case "306":
				this.MyPattern_6();
			break;	
			
			case "MyPattern_7":
			case "307":
				this.MyPattern_7();
			break;	
			
			case "MyPattern_8":
			case "308":
				this.MyPattern_8();
			break;	
			
			case "MyPattern_9":
			case "309":
				this.MyPattern_9();
			break;	
		
			case "MyPattern_10":
			case "310":
				this.MyPattern_10();
			break;	
		
			case "MyPattern_11":
			case "311":
				this.MyPattern_11();
			break;	
		
			case "MyPattern_12":
			case "312":
				this.MyPattern_12();
			break;							
																															
			default:
			this.MyPattern_1();		
		}
	}
	
	this.MyPattern_1 = function(){
		create_image();
		num_ary_1 = [0,1,2,3,4,9,14,19,24,23,22,21,20,15,10,5,6,7,8,13,18,17,16,11,12];
		animate_view_only(num_ary_1);		
	}
	
	this.MyPattern_2 = function(){
		create_image();	
		num_ary_1 = [12,13,8,7,6,11,16,17,18,19,14,9,4,3,2,1,0,5,10,15,20,21,22,23,24];
		animate_view_only(num_ary_1);
	}

	this.MyPattern_3 = function(){
		create_image();	
		num_ary_1 = [0,1,2,3,4,9,8,7,6,5,10,11,12,13,14,19,18,17,16,15,20,21,22,23,24];
		animate_view_only(num_ary_1);	
	}		

	this.MyPattern_4 = function(){
		create_image();	
		num_ary_1 = [0,5,10,15,20,21,16,11,6,1,2,7,12,17,22,23,18,13,8,3,4,9,14,19,24];
		animate_view_only(num_ary_1);
	}	
	
	this.MyPattern_5 = function(){
		create_image();
		num_ary_1 = [0,24,5,19,1,23,10,14,6,18,2,22,15,9,11,13,7,17,3,21,20,4,16,8,12];
		animate_view_only(num_ary_1);	
	}	
	
	this.MyPattern_6 = function(){
		create_image();
		num_ary_1 = [12,7,17,11,13,6,18,8,16,2,22,10,14,0,24,4,20,1,23,3,21,5,19,15,9];
		animate_view_only(num_ary_1);					
	}	
	
	this.MyPattern_7 = function(){		
		create_image();
		num_ary_1 = [0,5,10,15,20,4,9,14,19,24];
		num_ary_2 = [1,6,11,16,21,3,8,13,18,23];
		num_ary_3 = [2,7,15,17,22,12];
		animate_view_all();						
	}	
	
	this.MyPattern_8 = function(){
		create_image();	
		num_ary_1 = [0,20,1,21,2,22,3,23,4,24];
		num_ary_2 = [5,15,6,16,7,17,8,18,9,19];
		num_ary_3 = [10,11,12,13,14];
		animate_view_all();			
	}
	
	this.MyPattern_9 = function(){
		create_image();
		num_ary_1 = [12,6,18,8,16,2,22,0,24,4,20,10,14];
		num_ary_2 = [7,13,17,11,1,23,3,21,5,19,9,15];
		num_ary_3 = "";
		animate_view_all();					
	}		
	
	this.MyPattern_10 = function(){
		create_image();
		num_ary_1 = [0,1,5,19,23,24];
		num_ary_2 = [2,6,7,10,11,13,14,17,18,22];
		num_ary_3 = [3,4,8,9,12,15,16,20,21];
		animate_view_all();					
	}		
	
	this.MyPattern_11 = function(){
		create_image();
		num_ary_1 = [0,1,2,5,6,10];
		num_ary_2 = [3,7,11,15,4,8,12,16,20];
		num_ary_3 = [9,13,17,21,14,18,19,22,23,24];
		animate_view_all(); 				
	}		
	
	this.MyPattern_12 = function(){
		num_ary_1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
		num_ary_1 = ary_random(num_ary_1);
		animate_view_only(num_ary_1);	
		create_image();		
	}											
			
		
	//初期の画像の生成と位置のセット
	function create_image(){
		control=false;				
		if($(ViewId+' div').size()==0){
			$(ViewId).wrapInner('<div></div>');
		}
		//最初の画像
		$(ViewId+' div:eq(0)').css({'float':'left','position':'absolute','top':'0px','left':'0px','z-index':'10'});		
	
		//最終表示画像
		$(ViewId).append('<div>'+html+'</div>');
		$(ViewId+' div:eq(1)').css({'float':'left','position':'absolute','top':'0px','left':'0px','z-index':'5'});		
		IW = $(ViewId+' div:eq(1)').outerWidth();		
		IH = $(ViewId+' div:eq(1)').outerHeight();	
		
		//フィルター時の画像インスタンス分割数
		IWS = Math.ceil(IW/x_split);
		IHS = Math.ceil(IH/y_split);
		$(ViewId).append('<div></div>');
			
		var y=0;
		var x=0;
		var z=0;
		for(y=0;y<y_split;y++){
			for(x=0;x<x_split;x++) {				
				z = (x_split*y)+x;				
				$(ViewId+' div:eq(2)').append('<div>'+html+'</div>');
				
				switch(direction){
					case "top":
						IWP = IWS*x+'px';
						IHP = IHS*(y-1)+'px';
					break;
					
					case "right":
						IWP = IWS*(x+1)+'px';
						IHP = IHS*y+'px';
					break;
					
					case "bottom":
						IWP = IWS*x+'px';
						IHP = IHS*(y+1)+'px';
					break;										
					
					case "left":
						IWP = IWS*(x-1)+'px';
						IHP = IHS*y+'px';					
					break;					
																								
					default:
						IWP = IWS*x+'px';
						IHP = IHS*y+'px';
				}				
				
									
				if(x==x_split-1){
					$(ViewId+' div:eq(2) div:eq('+z+')').css({'position':'absolute','top':IHP,'left':IWP,'width':IW-(IWS*x)+'px','height':IHS+'px','overflow':'hidden','z-index':'20','opacity':'0'});	
				}else if(y==y_split-1){
				
					$(ViewId+' div:eq(2) div:eq('+z+')').css({'position':'absolute','top':IHP,'left':IWP,'width':IWS+'px','height':IH-(IHS*y)+'px','overflow':'hidden','z-index':'20','opacity':'0'});	
				}else{
					$(ViewId+' div:eq(2) div:eq('+z+')').css({'position':'absolute','top':IHP,'left':IWP,'width':IWS+'px','height':IHS+'px','overflow':'hidden','z-index':'20','opacity':'0'});	
				}
			
				x_posi[z] =IWS*x;				
				y_posi[z] =IHS*y;
				
				$(ViewId+' div:eq(2) div:eq('+z+') img').css({'position':'absolute','top':'-'+IHS*y+'px','left':'-'+IWS*x+'px','z-index':'20'});			
			}
		}	
	}	
				
	//画像をイッキに表示
	function animate_view_all(){
		if(num_ary_1){
			var n = 0;
			var i = 0;
			for(i=0;i<num_ary_1.length;i++){
				$(ViewId+' div:eq(2) div:eq('+num_ary_1[i]+')').animate({
					'opacity':'1',
					'top':y_posi[num_ary_1[i]],
					'left':x_posi[num_ary_1[i]]
				},{
					queue: true,
					duration: Timer_all,
					easing: "easeOutQuad",
					complete: function(){
						if(n>=num_ary_1.length-1){
							if(num_ary_2){
								animate_view_all_2();
							}else{
								remove_image();
							}				
						}else{
							n=n+1;	
						}
					}
				});					
			}
		}else{
			return false;
		}
	}

	function animate_view_all_2(){
		if(num_ary_2){
			var n = 0;
			var i = 0;			
			for(i=0;i<num_ary_2.length;i++){
				$(ViewId+' div:eq(2) div:eq('+num_ary_2[i]+')').animate({
					'opacity':'1',
					'top':y_posi[num_ary_2[i]],
					'left':x_posi[num_ary_2[i]]
				},{
					queue: true,
					duration: Timer_all,
					easing: "easeOutQuad",
					complete: function(){
						if(n>=num_ary_2.length-1){
							if(num_ary_3){
								animate_view_all_3();
							}else{
								remove_image();
							}			
						}else{
							n=n+1;	
						}
					}
				});					
			}
		}else{
			return false;
		}
	}
	
	function animate_view_all_3(){
		if(num_ary_3){
			var n = 0;
			for(i=0;i<num_ary_3.length;i++){
				$(ViewId+' div:eq(2) div:eq('+num_ary_3[i]+')').animate({
					'opacity':'1',
					'top':y_posi[num_ary_3[i]],
					'left':x_posi[num_ary_3[i]]
				},{
					queue: true,
					duration: Timer_all,
					easing: "easeOutQuad",
					complete: function(){
						if(n>=num_ary_3.length-1){
							remove_image();
						}else{
							n=n+1;	
						}
					}
				});					
			}
		}else{
			return false;
		}
	}					
	
	//タイマーで画像を一つずつ表示する
	function animate_view_only(num_ary_1){
		if(num_ary_1){
			var i= 0;
			var n = 0;				
			timerViewId = setInterval(function(){
				$(ViewId+' div:eq(2) div:eq('+num_ary_1[i]+')').animate({
					'opacity':'1',
					'top':y_posi[num_ary_1[i]],
					'left':x_posi[num_ary_1[i]]
				},{
					queue: true,
					duration: Timer,
					easing: "easeOutQuad",
					complete: function(){
						if(n>=num_ary_1.length-1){
							remove_image();
							return true;					
						}else{
							n=n+1;							
						}
					}
				});		
				i= i+1;					
				if(i>=num_ary_1.length){
					clearInterval(timerViewId);					
				}	
			},TimeInterval)			
		}else{
			return false;
		}
	}
	
	//処理終了後の画像を削除
	function remove_image(){
		$(ViewId+' div:eq(2)').remove();					
		$(ViewId+' div:eq(0)').remove();
		control=true;				
	}

	//配列をランダムに並び替える
	function ary_random(array, num) {
		var a = array;
		var t = [];
		var r = [];
		var l = a.length;
		var n = num < l ? num : l;
		while (n-- > 0) {
		var i = Math.random() * l | 0;
			r[n] = t[i] || a[i];
			--l;
			t[i] = t[l] || a[l];
		}
		return r;
	}
}


