
var ok = true;
var htime = null;
var e_q=0;
var e_qc=0;  // Сигнализатор раскрытия гармошки
var e_all=0;  // Сигнализатор запуска любого эффекта
var e_start_ok=0; // Сигнализатор окончания демонстрации
var setLang=1;

var e_s = new Array(10);  // Сигнализатор запуска какого-нибудь эффекта
var e_sc = new Array(10);  // Сигнализатор наведения на область эффекта

	ml_=new Array(13);
	ml_[1]="1EN";
	ml_[2]="1DE";
	ml_[3]="1ES";
	ml_[4]="1FR";
	ml_[5]="1PT";
	ml_[6]="1IT";
	ml_[7]="1PL";
	ml_[8]="1TR";
	ml_[9]="1ZH";
	ml_[10]="1JA";
	ml_[11]="1RU";
	ml_[12]="1AR";
							
	 var lang1="21"+navigator.language;
	 var lang2="21"+navigator.systemLanguage;
	 var lang3="21"+navigator.userLanguage;
	 var lang4=(lang1+"="+lang2+"="+lang3).toUpperCase() ;
	 var setLang=1;
   for (i=1; i<13; ++i) {
      if(lang4.indexOf(ml_[i])>0)setLang=i;
   }
for(var i=1;i<10;i++){
	e_s[i]=0;
	e_sc[i]=0;	
}

MN_a=new Array(21);
for (i=0; i<22; ++i) {
	MN_a[i]=new Array(7);
		for (j=0; j<8; ++j) {
			MN_a[i][j]="#";
		}
}
MN_a[0][0]="0.jpg";
MN_a[1][0]="q0.png";
MN_a[1][1]="q1.png";
MN_a[1][2]="q2.png";
MN_a[1][3]="q3.png";
MN_a[1][4]="q4.png";
MN_a[1][5]="q5.png";
MN_a[1][6]="q6.png";
MN_a[1][7]="q7.png";
MN_a[1][8]="q8.png";
MN_a[2][1]="q00.jpg";
MN_a[2][2]="q01.jpg";
MN_a[2][3]="q02.jpg";
MN_a[2][4]="q03.jpg";
MN_a[3][1]="h1.png";
MN_a[3][2]="h2.png";
MN_a[4][1]="r1.jpg";
MN_a[4][2]="r2.jpg";
MN_a[4][3]="r3.jpg";
MN_a[4][4]="r4.jpg";
MN_a[5][1]="r1b.jpg";
MN_a[5][2]="r2b.jpg";
MN_a[5][3]="r3b.jpg";
MN_a[5][4]="r4b.jpg";
MN_a[6][0]="b0.gif";
MN_a[6][1]="b1.png";
MN_a[6][2]="b2.png";
MN_a[6][3]="b3.png";
MN_a[7][1]="f01.jpg";
MN_a[7][2]="f02.jpg";
MN_a[7][3]="f03.jpg";
MN_a[7][4]="f04.jpg";
MN_a[8][1]="c1.gif";
MN_a[8][2]="c2.gif";
MN_a[9][1]="x1.png";
MN_a[9][2]="x2.png";
MN_a[10][1]="z1.png";
MN_a[10][2]="z2.png";
MN_a[11][1]="s1.png";
MN_a[11][2]="s2.png";
MN_a[12][1]="l1.png";
MN_a[13][1]="k1.png";
MN_a[13][2]="k2.png";
MN_a[14][1]="n1.jpg";
MN_a[14][2]="n2.jpg";
MN_a[15][1]="o1.png";
MN_a[17][1]="e.png";
MN_a[18][0]="y.png";
MN_a[18][1]="y1.png";
MN_a[19][0]="a5.png";
MN_a[19][1]="a2.png";
MN_a[19][2]="a3.png";
MN_a[20][1]="t1-1.jpg";

function MM_preloadImages() { //v3.0
     var i,j,x;
     	for(i=0; i<(MN_a.length-1); i++){     		
	     	for(j=0; j<7; j++){
	     		if (MN_a[i][j].indexOf("#")!=0){ x=new Image; x.src=MN_a[i][j];}
	     }
	}
   //loadTxt(setLang);
}

function loadTxt(i){
	for(j=1; j<10; j++){
   	var nfile='/txt/'+i+'/ff'+j+'.txt';
   	var di='d4'+j;
	   $(di).load(nfile);	
	}
}

function myRider(){
	// по каждому эффекту  с не моментальным исполением проверка
	//разъезд-съезд QO--OL
	//открытие
	if((e_q==0)&&(e_qc==1)){
		myEffect0(1);	
	}	
	//закрытие
	if((e_q == 2)&&(e_qc==2)){
		myEffect0(2);
	}
	//эффекты по снежинкам и 3D блоку
	for(var i=1;i<10;i++){
	//	if((e_q == 2)&&(e_sc[i]==1)&&(e_s[i]==0)){
		if((e_all == 0)&&(e_sc[i]==1)&&(e_start_ok==1)){	
			e_all=1;
			eval('myEffect'+i+'()');
		}
	}
	//эффекты по картине
	for(var i=1;i<9;i++){
		if((e_all == 0)&&(e_sc[i]==1)){
			//e_all=1;
			//eval('myEffect'+i+'()');
		}
	}
	htime = setTimeout("myRider()", 100);
}


function myEffect0(ee){
	//движение qo и снежинок	
	if(ee==1){
		e_q=1;
		var myFx1 = new Fx.Morph('i01', {duration: 1200});
		myFx1.start({'left':0});
		var l_s=45;
		for(var i=1;i<9;i++){
		      var a = new Array(i,(l_s+i*45),1);
		      myFunc.delay(50*i,"this",a);
		}
		//открытие снежинок
		for(var i=1;i<9;i++){
		      var tt = 2000*1+50*i;
			mySnow1.delay(tt,'this',i);
		}
		myFuncOk.delay(1800,'this','2');
	}
	else{
		//закрытие снежинок
		for(var i=1;i<9;i++){
		      var tt = 100*1+50*i;
			mySnow2.delay(tt,'this',i);
		}
		e_q=1;
		for(var i=8;i>0;i--){
		      var a = new Array(i,450,0);
		      myFunc.delay(10*(8-i),"this",a);
		}
		var myFx1 = new Fx.Morph('i01', {duration: 1200});
		myFx1.start({'left':360});
		myFuncOk.delay(1200,'this','0');
	}
}
function myFuncOk(w){
	e_q=w;
}
function myFuncStartOk(){
	e_start_ok=1;
}
function myFunc(id,w,o){
	$('i'+id).set('morph', {duration: 1200, transition: 'sine:in'});
	$('i'+id).morph({left: w, opacity: o});
}

function myEffect1(){//цвет волос
	 e_s[1]=1;
//	myTxtImg('d4',1);
	myEffect1b.delay(300,this,1);	 	
	myEffect1b.delay(1900,this,0);
	myEffect1b.delay(3600,this,3);

}

function myEffect1b(el){
	if (el==1){
		$('h2').get('tween', {property: 'opacity', duration: 1500}).start(1);		
	}	

	if (el==0){
		$('h2').get('tween', {property: 'opacity', duration: 1500}).start(0);		
	}
	if (el==3){e_s[1]=0; e_all=0;}	
}	

function myEffect2(){		//безопасность
	 e_s[2]=1;
	myEffect2b.delay(300,this,1);	 	
	myEffect2b.delay(1300,this,0);
	myEffect2b.delay(2800,this,3);

}

function myEffect2b(el){
	if(el==1){	
		$('z1').get('tween', {property: 'opacity', duration:1000}).start(0);
		$('z2').get('tween', {property: 'opacity', duration:1000}).start(1);		
	}
	if(el==0){
		$('z1').get('tween', {property: 'opacity', duration:1000}).start(1);
		$('z2').get('tween', {property: 'opacity', duration:1000}).start(0);		
	}
	if(el==3){e_s[2]=0; e_all=0;}

}	
	 	

function myEffect3(){		//цвет кожи
	 e_s[3]=1;
	myEffect3b.delay(300,this,1);	 	
	myEffect3b.delay(1900,this,0);
	myEffect3b.delay(3600,this,3);

}

function myEffect3b(el){
	if (el==1){
		$('b2').get('tween', {property: 'opacity', duration: 1500}).start(1);
	}
	if (el==0){
		$('b2').get('tween', {property: 'opacity', duration: 1500}).start(0);
	}		
	if (el==3){   e_s[3]=0;	 e_all=0;}
}	



function myEffect4(){		//долгосрочность
	 e_s[4]=1;
	var aa = new Array('400px -80px','650px 180px',1);
	var ab = new Array('300px -120px','650px -50px',2);	
	var ac = new Array('0px 120px','400px -80px',3);	
	var ad = new Array('0px 120px','400px -80px',4);
	myEffect4b.delay(300,this,aa);	 	
	myEffect4b.delay(3000,this,ab);
	myEffect4b.delay(5000,this,ac);	
	myEffect4b.delay(7000,this,ad);
	myEffect4c.delay(3000,this,1);	
	myEffect4c.delay(6000,this,0);	
	  	
}
function myEffect4b(f,t,el){	//движение солнца и луны
	if(el==4){e_s[4]=0; e_all=0;}
	else{
		if (el==2){
			$('sl').setStyle('background',' url('+MN_a[12][1]+')');
			$('sl').setStyle('background-position','100px -120px');
			$('sl').setStyle('background-repeat','no-repeat');
		}
		if (el==3){
			$('sl').setStyle('background',' url('+MN_a[11][1]+')');
			$('sl').setStyle('background-position','0px 120px');
			$('sl').setStyle('background-repeat','no-repeat');
		
		}
		
		$('sl').get('tween', {property: 'background-position', duration:2000}).start(f,t);
	}
}

function myEffect4c(el){	//звезды на небе
	$('e1').get('tween', {property: 'opacity', duration:500}).start(el);
}


function myEffect5(){	//загар
	 e_s[5]=1;
	myEffect5b.delay(200,this,1);
	myEffect5b.delay(1200,this,0);
	myEffect5b.delay(2200,this,3);	
}

function myEffect5b(el){	//загар
	if(el==3){e_s[5]=0; e_all=0;}
	if(el==1){
		$('s2').get('tween', {property: 'opacity', duration:300}).start(el);
	}
	if(el==0){
		$('s2').get('tween', {property: 'opacity', duration:600}).start(el);	
	}

}



function myEffect6(){	//не  требует охлаждения
	e_s[6]=1;
	myEffect6b.delay(300,this,1);	 	
	myEffect6b.delay(800,this,0);
}


function myEffect6b(el){	//не  требует охлаждения
	if(el==0){e_s[6]=0; e_all=0;}
	$('c2').get('tween', {property: 'opacity', duration:500}).start(el);
}

function myEffect7(){	//нет ограничений
	 e_s[7]=1;
	  myEffect7b.delay(300,this,1);
	  myEffect7b.delay(1800,this,0);	
	  myEffect7b.delay(3300,this,3);
 	
}
function myEffect7b(el){
	if (el==1){
		$('x1').get('tween', {property: 'opacity', duration: 1500}).start(0);
		$('x2').get('tween', {property: 'opacity', duration: 1500}).start(1);
	}	
	if(el==0){
		$('x1').get('tween', {property: 'opacity', duration: 1500}).start(1);
		$('x2').get('tween', {property: 'opacity', duration: 1500}).start(0);
	}
	if(el==3){   e_s[7]=0; e_all=0;}
}	

function myEffect8(){	// безболезненность
	 e_s[8]=1;
	myEffect8b.delay(600,this,1);	 	
	myEffect8b.delay(1200,this,0);	
}

function myEffect8b(el){
	if(el==0){e_s[8]=0;  e_all=0;
		$('k2').set('opacity', 0);
		$('k1').set('opacity', 1);
	}
	else{
		$('k1').set('opacity', 0);
		$('k2').set('opacity', 1);
	}
}

function myEffect9(){	// 3D анимация во 2 блоке
	 e_s[9]=1;
	myEffect9b.delay(200,this,1);	 	
	myEffect9b.delay(3200,this,0);	
}

function myEffect9b(el){
	if(el==0){e_s[9]=0;  e_all=0;
		$('d21').set('opacity', 1);
		$('y1').get('tween', {property: 'opacity', duration:300}).start(el);		
	}
	else{
		$('d21').set('opacity', 0);
		$('y1').get('tween', {property: 'opacity', duration:300}).start(el);
	}
}

function showFoto(id){
	var nname='/photo/201005212/'+id.name+'b.jpg';
   $('d5u').set('src',nname);
}

function myImgOn(id){
	var nname=id.name+'b.jpg';
	id.src=nname;
	id.style.cursor="pointer";
}

function myImgOff(id){
	var nname=id.name+'.jpg';
	id.src=nname;
	id.style.cursor="default";	
}

function myBlock(id){
	var nname=id.name;	
	if (nname!='r2'){
		$('d5').set('opacity', 0.7);
		$('dclose').set('src','a5.png');
	}
	if (nname=='r1'){
		$('d5txt').set('opacity', 0.9);
           	$('dclose').set('opacity', 1);	
		myTxt('d5txt', 'doc');		
	}
	if (nname=='r2'){
		//$('d5faq').set('opacity', 0.9);
		//$('dclose').set('opacity', 1);	
		//myTxt('d5faq', 'faq');		
	}	
	if (nname=='r3'){
		$('d5img').set('opacity', 0.8);		
		$('d5s').set('opacity', 1);
		$('d5u').set('opacity', 1);					
		$('dclose').set('opacity', 1);	
	}
	if (nname=='w0'){
		$('d5video').set('opacity', 0.7);
		$('d5player').set('opacity', 0.9);
		$('dclose').set('opacity', 1);	

		if (setLang == 11) 
                s1.addVariable('file', '/video/!playlist_rus.xml');
                else 
                s1.addVariable('file', '/video/!playlist_eng.xml');
                s1.write('d5player');
	}
	
}


function mySnow(id, ee){
	var nef=id.name;
	e_sc[nef]=ee;
	$('d40').set('html', $('d4'+nef).get('html'));	
}

function mySnow1(nef){
	$('i'+nef).src=MN_a[1][nef];
}
function mySnow2(nef){
	$('i'+nef).src=MN_a[1][0];
}

function myTxt(di, id){
	if(di=='d4')$(di).setStyle('background','none');
	else{
   	var nfile='/txt/'+setLang+'/ff'+id+'.txt';
   	$(di).load(nfile);
	  $(di).set('opacity', 0.8);		
	}
}

function myTxtImg(di, id){
	$(di).set('text', '');
	$(di).setStyle('background',' url('+MN_a[20][id]+')');
}

function player1hide(){
      	$('player1').set('opacity', 0);
}

function sendEvent(typ,prm) { thisMovie('mpl').sendEvent(typ,prm); };

function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
function liMenu(id){
   var cur=id.id.substring(2);
   setLang=cur;
   loadTxt(cur);
   $each($('d234').getElements('li'),function(value, key){
			value.setStyles({color:'#FBFFE4'});
			});
	id.tween('color','#E50000');	
 	var nfile='/txt/'+setLang+'/ff9.txt';
  	$('d40').load(nfile);		
playRmenu(0);  	
}

function playRmenu(tm){
$('r1').fireEvent('mouseenter',1, tm+5000);
$('r1').fireEvent('mouseleave',1, tm+6000);
$('r2').fireEvent('mouseenter',1, tm+5250);
$('r2').fireEvent('mouseleave',1, tm+6250);
$('r3').fireEvent('mouseenter',1, tm+5500);
$('r3').fireEvent('mouseleave',1, tm+6500);
$('d3').fireEvent('mouseenter',1, tm+500);
$('d3').fireEvent('mouseleave',1, tm+3000);
}


function myInitFunction(){
$('d6s').set('morph', {duration: 2000, transition:Fx.Transitions.Back.easeOut});
$('d6s').morph({
	left: 540,
	top: 380
	});
$('d6').get('tween', {property: 'opacity', duration: 3000}).start(0);
playRmenu(3000);
myFuncStartOk.delay(10000);
}



window.addEvent('domready', function() {
	for(var i=1;i<3;i++){
		$('n'+i).src=MN_a[14][i];
	}		
	for(var i=1;i<3;i++){
		$('h'+i).src=MN_a[3][i];
	}		
	for(var i=0;i<4;i++){
		$('b'+i).src=MN_a[6][i];
	}		
	for(var i=1;i<3;i++){
		$('c'+i).src=MN_a[8][i];
	}		
	for(var i=1;i<3;i++){
		$('k'+i).src=MN_a[13][i];
	}		
	for(var i=1;i<3;i++){
		$('x'+i).src=MN_a[9][i];
	}
	for(var i=1;i<3;i++){
		$('z'+i).src=MN_a[10][i];
	}		
	$('o1').src=MN_a[15][1];
	$('e1').src=MN_a[17][1];	
	
	for(var i=2;i<3;i++){
		$('s'+i).src=MN_a[11][i];
	}		
	
      // разкомментировали отсюда 
      $('a1').addEvents({	
		mouseenter: function(){
			e_sc[1]=1;
			$('d40').set('html', $('d41').get('html'));	
		},
		mouseleave: function(){
			e_sc[1]=0;
		}
	});
	$('a3').addEvents({	
		mouseenter: function(){
			e_sc[3]=1;
			$('d40').set('html', $('d43').get('html'));				
		},
		mouseleave: function(){
			e_sc[3]=0;
		}
	});
	$('a6').addEvents({	
		mouseenter: function(){
			e_sc[6]=1;
			$('d40').set('html', $('d46').get('html'));				
		},
		mouseleave: function(){
			e_sc[6]=0;
		}
	});
	$('a7').addEvents({	
		mouseenter: function(){
			e_sc[7]=1;
			$('d40').set('html', $('d47').get('html'));				
		},
		mouseleave: function(){
			e_sc[7]=0;
		}
	});
	$('a2').addEvents({	
		mouseenter: function(){
			e_sc[2]=1;
			$('d40').set('html', $('d42').get('html'));				
		},
		mouseleave: function(){
			e_sc[2]=0;
		}
	});
	$('a5').addEvents({	
		mouseenter: function(){
			e_sc[5]=1;
			$('d40').set('html', $('d45').get('html'));				
		},
		mouseleave: function(){
			e_sc[5]=0;
		}
	});

	$('a8').addEvents({	
		mouseenter: function(){
	      	e_sc[8]=1;
			$('d40').set('html', $('d48').get('html'));				
		},
		mouseleave: function(){
			e_sc[8]=0;
		}
	});
	$('d3').addEvents({
		mouseenter: function(){
			e_qc=1;
		},
		mouseleave: function(){
			e_qc=2;
		}
	});

	$('d49').set('opacity', 0);

   for(var i=1;i<9;i++){
	$('i'+i).src=MN_a[1][0];
	$('d4'+i).set('opacity', 0);
	$('i'+i).set('opacity', 0).addEvents({
		mouseenter: function(){
			mySnow(this,1);
		},
		mouseleave: function(){
			mySnow(this,0);		
		},
		click: function(){                                                                                                                                                                                                                                                                                           	
		}
	});
	};

	for(var i=1;i<4;i++){
	$('r'+i).src=MN_a[4][i];
	$('r'+i).addEvents({
		mouseenter: function(){
			this.tween('width',30);			
			myImgOn(this);	
		},
		mouseleave: function(){		
			this.tween('width',10);
			myImgOff(this);		
		},
		click: function(){
			myBlock(this);
		}
	});
	};


	$('w0').addEvents({
		mouseenter: function(){
		},
		mouseleave: function(){	
		},
		click: function(){
			myBlock(this);
		}
	});
	

	$('li'+setLang).tween('color','#E50000');	
	for(var i=1;i<13;i++){
	$('li'+i).addEvents({
		mouseenter: function(){
			this.morph({height:20, 'margin-top':0});			
		},
		mouseleave: function(){	
			this.morph({height:15, 'margin-top':5});	
		},
		click: function(){
         liMenu(this);
		}
	});
	};

	for(var i=1;i<11;i++){
	$('g5_'+i).addEvents({
		mouseenter: function(){
		},
		mouseleave: function(){	
		},
		click: function(){
         showFoto(this);
		}
	});
	};
	
	$('dclose').addEvents({
		mouseenter: function(){
		},
		mouseleave: function(){	
		},
		click: function(){
			$('d5').set('opacity', 0);
			$('d5txt').set('opacity', 0);
			$('d5faq').set('opacity', 0);			
			$('d5img').set('opacity', 0);
			$('d5video').set('opacity', 0);
			$('d5player').set('opacity', 0);
			$('d5s').set('opacity', 0);
			$('d5u').set('opacity', 0);
			$('dclose').set('opacity', 0);						
			$('mpl').sendEvent('stop','true');
		}
	});

	/*
	$('player1go').addEvents({
		mouseenter: function(){
		},
		mouseleave: function(){	
		},
		click: function(){
      	$('player1').set('opacity', 1);
         sendEvent.delay(200,this,'play');
   	   player1hide.delay(17300,this,1);      	
		}
	});
	*/
	
	myRider();
	
	$('sl').setStyle('background',' url('+MN_a[11][1]+')');
	$('sl').setStyle('background-position','400px -80px');	
	$('sl').setStyle('background-repeat','no-repeat');
	$('n2').set('opacity', 0);
	$('e1').set('opacity', 0);
	
	$('h2').set('opacity', 0);
	$('h1').set('opacity', 1);

	$('b2').set('opacity', 0);
	$('b3').set('opacity', 0);
	$('b1').set('opacity', 1);

	$('k2').set('opacity', 0);
	$('k1').set('opacity', 1);

	$('c2').set('opacity', 0);
	$('c1').set('opacity', 1);
	
	$('s2').set('opacity', 0);

	
	$('x2').set('opacity', 0);
	$('x1').set('opacity', 1);

	$('z2').set('opacity', 0);
	$('z1').set('opacity', 1);
		
	$('d5').set('opacity', 0);
	$('d5txt').set('opacity', 0);
	$('d5faq').set('opacity', 0);		
	$('d5img').set('opacity', 0);
	$('d5video').set('opacity', 0);		
	$('d5player').set('opacity', 0);		
	$('d5s').set('opacity', 0);		
	$('d5u').set('opacity', 0);
	$('dclose').set('opacity', 0);

        var nfile='/txt/'+setLang+'/ff9.txt';
        setLang = setLang? setLang : '1';
  	$('d40').load(nfile);	
});
		
