var upbannermas= new Array('Франция','Канары'), is_ie=0, upban_country=0, upban_perform_count=new Array(1,2), upban_perform=1, upban_number_ph=1, upbanint=0, upbanintperf=0, animint=0, anim_a=100, anim_b=0, anim_c=0, anim_d=0, anim_font_flg=true, anim_font_a=100, anim_font_b=0, anim_font_c=0, anim_font_d=0, animintfont=0;
var quotesint=0, animquote=0, globallightint=0, animglobalquotes=0, currentquote=-1, animquoteopac=40, animquotelast=100, globalquoteopac=0, anim_quote_flg=false, lastlightquote=-1;

function
init( _lang )
{
    window.flashVideo;
    window.arrStor=new Array();
    window.lang=_lang;
    window.marStpCount=0;
    window.initFrnt=2;
    
    var name='video_width';
    window.isIE = navigator.appName.indexOf("Microsoft") != -1;
    window.flashVideo=(isIE) ? window[name] : document[name];
    //changer(1,0);
    changer(2,0);

    initMarqueeWith(1);
    initMarqueeWith(2);
    
    window.oXMLhttp=new eAJAX();
    getKey();
	
	is_ie=( navigator.userAgent.indexOf("MSIE ")>0 ) ? 1 : 0;
	/* init верхнего баннера */
	upbanint=window.setInterval("chbancountry(1)", 3200);  // 3200 - интервал смены стран <-- упр.
	upbanintperf=window.setInterval("chbancountry(2)", 8000); // 8000 - интервал смены фото постановки <-- упр.
	document.getElementById("baninf").onclick=function(ev){
		if(navigator.appName.substring(0,3)=="Mic") {ie=true;}
		if(ie){event.cancelBubble = true;} else {ev.cancelBubble = true;}
		window.open("http://www.irinakolesnikova.com/shedl/?lang=eng",('target','_blank'));
	}
	/* конец init верхн баннера */
	
	/* init цитатника */
	globallightint=window.setInterval("globalshowquotes()", 10000);  // 10000 - интервал впервоначального появления цитат
	/* конец init цитатника */

}
function globalshowquotes() {
	if(is_ie){
		var currobj=document.getElementById('quotecontainer').getElementsByTagName('div');
		for(i=0;i < currobj.length; i++){currobj[i].style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";}
	}
	animglobalquotes=window.setInterval("fade_globalquotes(document.getElementById('leftquotes'),10)", 150);
	window.clearInterval(globallightint);
}
function fade_globalquotes(fadeobj,step) {
	if(globalquoteopac < 100){
		globalquoteopac+=step;
		if(is_ie){
			//fadeobj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+globalquoteopac+")";
		} else {
			fadeobj.style.opacity=globalquoteopac/100;
		}
	} else {
		window.clearInterval(animglobalquotes);
		quotesint=window.setInterval("chquotes()", 1800);  // 1800 - интервал высвечивания цитат
	}
}
function chquotes() {
	var currobj=document.getElementById('quotecontainer').getElementsByTagName('div');
	if(anim_quote_flg){
		window.clearInterval(animquote); animquoteopac=0;
	} anim_quote_flg=true;	if(++currentquote >= document.getElementById('quotecontainer').getElementsByTagName('div').length){currentquote=0; window.clearInterval(quotesint); return;}
	currobj[currentquote].style.visibility='visible';
	animquote=window.setInterval("fade_quote_font(document.getElementById('quotecontainer').getElementsByTagName('div')[currentquote],10)", 150);
}
function fade_quote_font(obj_font,step) {
	if(animquoteopac < 100){
		animquoteopac+=step;
		if(is_ie){
			obj_font.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+animquoteopac+")";
		} else {
			obj_font.style.opacity=animquoteopac/100;
		}
	} else {
		anim_quote_flg=false;
		animquoteopac=0;
		window.clearInterval(animquote);
		return;
	}
}
function chbancountry(val) {
	switch(val){
	case 1: // для смены страны
		upban_country++;
		if(upban_country >= upbannermas.length) {upban_country=0;
			
		}
		window.clearInterval(animintfont); anim_font_flg=true;
		anim_font_c=anim_font_a; anim_font_d=anim_font_b;
		animintfont=window.setInterval("fade_font(document.getElementById('bancountry'),'"+upbannermas[upban_country]+"',50,"+is_ie+")", 150);
	break;
	case 2: // для смены спектакля
		var strobjimg_last="bb2_"+upban_perform+"_"+upban_number_ph;
		if(++upban_number_ph > upban_perform_count[upban_perform-1]) {upban_number_ph=1;
			if(++upban_perform > upban_perform_count.length) upban_perform=1;
		}
		var strobjimg="bb2_"+upban_perform+"_"+upban_number_ph;
		anim_c=anim_a; anim_d=anim_b;
		document.getElementById(strobjimg).style.visibility="visible";
		animint=window.setInterval("changebanimg(document.getElementById('"+strobjimg_last+"'),document.getElementById('"+strobjimg+"'),5,"+is_ie+")", 150);
	break;
	}
}
function fade_font(obj_font,newtext,step,ie){
	if(anim_font_flg){ // исчезновение
		if(anim_font_c >= 0){
			anim_font_c-=step;
		    if(ie){
		        obj_font.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+anim_font_c+")";
		    } else {
		        obj_font.style.opacity=anim_font_c/100;
		    }
		} else {
			anim_font_flg=false;
			obj_font.innerHTML='<p>'+newtext+'</p>';
			obj_font.getElementsByTagName('p')[0].style.fontSize = '8px';
		}
	} else { // проявление
		if(anim_font_d <= 100){
			anim_font_d+=step;
			if(ie){
		        obj_font.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+anim_font_d+")";
		    } else {
		        obj_font.style.opacity=anim_font_d/100;
		    }
			obj_font.getElementsByTagName('p')[0].style.fontSize = (Math.ceil((anim_font_d/100)*5))+'px';
		} else {
			window.clearInterval(animintfont);
			anim_font_flg=true;
			obj_font.getElementsByTagName('p')[0].style.fontSize = '14px';
		}
	}
}
function changebanimg(obj_a,obj_b,step,ie){
	if(anim_c){
		anim_c-=step;
	    anim_d+=step;
	    if(ie){
	        obj_a.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+anim_c+")";
	        obj_b.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+anim_d+")";
	    } else {
	        obj_a.style.opacity=anim_c/100;
	        obj_b.style.opacity=anim_d/100;
	    }
	} else {
		window.clearInterval(animint);
		obj_a.style.visibility="hidden";
	}
}

function
initMarqueeWith(_idPart)
{

    var o,obj;
    for(var i=0;o=document.getElementById("marquee_box"+_idPart+"_"+i);i++)
    {
    	obj = new MarqueeAnimator(o.id,o.offsetWidth,5,75,false);
    }	
}
// __get
function
getKey()
{
	var main=this;
	oXMLhttp.handler=setKey;
	sendVal='?type=getkey';
	oXMLhttp.crtSend('GET','../ajax/index.php',sendVal,true);
}
// __set
function
setKey()
{
	if(oXMLhttp.xmlHttp.readyState==4){
		if(oXMLhttp.xmlHttp.status==200){
			var res=oXMLhttp.xmlHttp.responseXML;
			var root=res.documentElement;
			if(root.firstChild){
				sNum=root.firstChild.data;
				window.Key=sNum;
				addContext(window.lang);
				//alert(window.Key);
			}else{
				window.Key=false;
			}
		}
	}
}
function
clearKey(sNum)
{
	var sOutput=sNum.split('_');
	return sOutput[0];
}
// add
function
addWait()
{
	var dict={
		rus: 'Ждите...',
  		eng: 'Wait...'
	}
	var ieHack=( window.isIE ) ? 'padding-left:139px;' : '';
	var str="<table width=\"100%\" height=\"90%\" ><tr><td style=\"text-align:center;"+ieHack+"\" class='no_fcs' >"+dict[window.lang]+"</td></tr></table>"
	var o = document.getElementById('form_content');
	o.innerHTML=str;
}
function
addContext(_lang)
{
	var dict={
		'rus':new Array('ВАШИ ИНИЦИАЛЫ','ВАШ E-MAIL','ТЕКСТ СООБЩЕНИЯ','ОТПРАВИТЬ'),
  		'eng':new Array('YOUR NAME','YOUR E-MAIL','MESSAGE TEXT','SEND')
	};
	
	var _onFocus = ( window.isIE ) ? "onfocus=\"changeStyleFor(this,'borderColor','#fff')\"" : '' ;
	var _onBlur = ( window.isIE ) ? "onblur=\"changeStyleFor(this,'borderColor','656567')\"" : '';
	var ieHack=_onFocus+' '+_onBlur;
	
	if( window.Key ){
		var str='<form action="./?val=send&lang=rus" method="post" onsubmit="return checkBeforeSend()"  ><table cellpadding="0" cellspacing="0" ><tr><td class="have_text" >'+dict[_lang][0]+':</td><td><input id="nm_input" '+ieHack+'  class="no_fcs" type="text" name="v89" /></td></tr><tr><td class="have_text" >'+dict[_lang][1]+':</td><td><input id="eml_input"   class="no_fcs" '+ieHack+' type="text" name="v99" /></td></tr>';
		str+='<tr><td class="have_text" >'+dict[_lang][2]+':</td><td><textarea id="text_text"  '+ieHack+'  class="no_fcs" type="text" name="v00"></textarea></td></tr>';
		str+='<tr><td style="padding-top:4px;" colspan="2" align="right" ><input id="sendie" class="no_fcs" style="width:102px;font-size:9px;color:#626264;" type="submit" value="'+dict[_lang][3]+'"  /></td></tr></table><input type="hidden" name="v01" value="'+clearKey(window.Key)+'" /></form>';
		//alert(str);
		var o = document.getElementById('form_content');
		o.innerHTML=str;
	}
}
// obj
function
MarqueeAnimator(_gnrl,_stp,_st,_sp,_lp)
{
    this.gnrl=_gnrl;
    this.stp=_stp;
    this.st=_st;
    this.sp=_sp;
    this.interval=0;
    this.intr=0;
 
    if(!_lp) this.startAnimOnce();
}
MarqueeAnimator.prototype.startAnimOnce=function()
{
    var main=this;
    var func=function(){ return animMarquee(true,main)};
    this.intr=setInterval(func,this.sp);
}
// anim
animMarquee=function(_direct,_this)
{
    if(_direct)
    {
		_this.stp -= _this.st; //alert(this.stp);
		if(_this.stp>0)
		{
		    document.getElementById(_this.gnrl+'_main').style.left=_this.stp+'px';
		}
		else
		{
		    clearInterval(_this.intr);
		    callMarquee();
		}
    }
}
// call
function
callMarquee()
{
    if(++window.marStpCount==initFrnt)
    {
    	var o = document.getElementById("marque_bill");
		new MarqueeAnimator(o.id,o.offsetWidth,5,75,false);
    }
}
function
callPlay(_this,_br,_video)
{
    var a_old = window.arrStor.pop();
    window.arrStor.push( new Array(_this,new Array(_this.onmouseover,_this.onmouseout,_this.onclick), _br )  );
    var a = new Array('onmouseover','onmouseout','onclick');
    for(var i=0; a[i]; i++) _this[ a[i] ] = function(){ return false; }
    _this.style.cursor="default";
 
    try{
        var old= a_old[0];
	for(var i=0; a[i]; i++) old[ a[i] ] = a_old[1][i];
	old.style.cursor="pointer";
	old.style.borderColor=a_old[2];
    }catch(ex){}
    window.flashVideo.playThis(_video);
}
// change
function
changeStyleFor(_this,_style,_to)
{
    _this.style[_style]=_to;
}
function
changer(_tmplt,_i)
{
	try
	{
		var o = document.getElementById('layer_'+_tmplt+'_'+(_i+1));
		var p = document.getElementById('layer_'+_tmplt+'_'+(_i));
		o.style.display="block";
		p.style.display="none";
		o = document.getElementById('marquee_box'+_tmplt+'_'+(_i+1));
		p = document.getElementById('marquee_box'+_tmplt+'_'+(_i));
		o.style.visibility="visible";
		p.style.visibility="hidden";
		_i++;
	}
	catch(ex)
	{
		try
		{
			var o = document.getElementById('layer_'+_tmplt+'_0');
			var p = document.getElementById('layer_'+_tmplt+'_1');
			o.style.display="block";
			p.style.display="none";
			o = document.getElementById('marquee_box'+_tmplt+'_0');
			p = document.getElementById('marquee_box'+_tmplt+'_1');
			o.style.visibility="visible";
			p.style.visibility="hidden";
			_i=0;
		}
		catch(ex)
		{
			o = document.getElementById('marquee_box'+_tmplt+'_0');
			o.style.visibility="visible";
			return false;
		}
	}
	var pause= ( window.PAUSES[ _tmplt ][ _i ] ) ? window.PAUSES[ _tmplt ][ _i ] : 5000;
	setTimeout("changer("+_tmplt+","+_i+")", pause );
}
//check
function 
checkBeforeSend()
{
	if(!window.Key) return false;
    var pattern = new RegExp('.+@[\.a-z]+\.[a-z]{2,3}$','i');
    var patternTag= new RegExp('<.+>(.*)</.+>');
    var arrIDs = new Array("nm_input","eml_input","text_text");
    var arrValue=new Array();
    for(var i=0,e=0;i!=arrIDs.length;i++)
    {
	if(!document.getElementById(arrIDs[i]).value && arrIDs[i]!="eml_input") e++;
	else if(arrIDs[i]=='eml_input' && !pattern.test(document.getElementById(arrIDs[i]).value)  ) e++;
	else{
		arrValue.push(document.getElementById(arrIDs[i]).value)
	}
    }
    if( patternTag.test(document.getElementById(arrIDs[2]).value) )var res = false;
    var res = (e) ? false : true;
    if(res)
    {
	    var sendVal='?type=send&name='+arrValue+'&node=letter&mail='+arrValue+'&textbody='+arrValue+'&view=0&key='+clearKey(window.Key)+'&lang='+window.lang;
	    document.getElementById('sendie').cursor='wait';
	    oXMLhttp.handler=MailHandler;
	    oXMLhttp.crtSend('GET','../ajax/index.php',sendVal,true);
	    addWait();
    }
    return false;
}
// handler
MailHandler=function(){
	if(oXMLhttp.xmlHttp.readyState==1){
		
	}else if(oXMLhttp.xmlHttp.readyState==4){
		if(oXMLhttp.xmlHttp.status==200){
			var dict={
				rus: {'good':'Сообщение отправлено успешно','bad':'Ваше сообщение не было отправлено, т.к. распознано, как спам или содержащее запрещенные слова; устраните ошибки и попробуйте еще раз'},
    eng: {'good':'Message was sent successfully','bad':'Message not sent; spam or forbidden words detected. Make corrections and try again.'}
			}
			var res=oXMLhttp.xmlHttp.responseXML;
			var root=res.documentElement;
			if(root.firstChild.tagName!='ERROR' || root.firstChild.tagName!='error'){
				if(root.firstChild.data==1){
					// анимация оповещения
					alert(dict[window.lang]['good']);
					addContext(window.lang);
				}else alert(dict[window.lang]['bad']);
			}
			else alert(root.firstChild.data);
		}
		//this.isInUse=this.isInUse ^ 1;
		document.getElementById('sendie').cursor='pointer';
	}	
}
function 
switchStyleFor(_this,_style,_variant,_def)
{
	 if(_this.style[_style]==_variant[0])
	 {
	 	changeStyleFor(_this,_style,_variant[1]);
	 }
	 else if(_this.style[_style]==_variant[1])
	 {
	 	changeStyleFor(_this,_style,_variant[0]);
	 }
	 else
	 {
	 	changeStyleFor(_this,_style,_def);
	 }
}
function
newLocation()
{
	location.href="./?lang="+window.lang;
}