
var ie = 0;
var ie6 = 0;
var brie = navigator.userAgent.toLowerCase();
if (brie.indexOf("msie")>-1) ie = 1;
if (brie.indexOf("msie 6")>-1 || brie.indexOf("msie 5")>-1) ie6 = 1;


//Ajax Menu Functions
inaction = 0;

function ajaxmenu(url,itemid,hostitemid) {
if (inaction != 1) {
inaction = 1;
if (document.getElementById(itemid).innerHTML == '.') {
  document.getElementById(itemid+'_i').src = '/style/i/z_tr1_load.gif';
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById('temp_menu');
        el.innerHTML = x.responseText;
        meheight = el.offsetHeight;
        document.getElementById(itemid).innerHTML = x.responseText;
        toggle(itemid,hostitemid);
        
      }
    }
    x.open("GET", '/ajaxmenu.php?url='+url, true);
    x.send(null);
  }
} else {
	meheight = document.getElementById(itemid).offsetHeight;
	toggle(itemid,hostitemid);
}
}
}

mehost = null;
meid = null;
mefix = null;
meheight = 0;
mecss = null;
mearrow = null;
metimer = null;
mestep = null;
meshift = null;
start2 = null;
shift2 = null;
finalh = null;
mftimer = null;
mffix = null;
mfcss = null;

function toggle(itemid,hostitemid){
	mehost = hostitemid;
	mefix = document.getElementById(itemid+'_fix').style;
	mecss = document.getElementById(itemid).style;
	mearrow = document.getElementById(itemid+'_i');
	metimer = null;
	mestep = parseInt(meheight/12);
	mecss.display = 'block';
	
	if (mecss.visibility != 'visible') {
		meshift = 0;
		mearrow.src = '/style/i/z_tr1_on.png';
		clearTimeout(metimer);
		mecss.visibility = 'visible';
		slideon();
		if (mehost != null) {
			mfcss = document.getElementById(hostitemid).style;
			mffix = document.getElementById(hostitemid+'_fix').style;
			mestart2 = parseInt(document.getElementById(hostitemid+'_fix').style.height);
			meshift2 = mestart2;
			mefinalh = meshift2+meheight;
			fixon();
		}

		
	} else {
		meheight = document.getElementById(itemid).offsetHeight;
		metimer = null;
		meshift = meheight;
		mearrow.src = '/style/i/z_tr1_off.png';
		clearTimeout(metimer);
		slideoff();	
		if (mehost != null) {
			mfcss = document.getElementById(hostitemid).style;
			mffix = document.getElementById(hostitemid+'_fix').style;
			mestart2 = parseInt(document.getElementById(hostitemid+'_fix').style.height);
			meshift2 = mestart2;
			mefinalh = meshift2-meheight;
			fixoff();
		}	
	}
	
}

function slideon() {
	if (meshift == meheight) {clearTimeout(metimer); inaction = 0;}
	if (meshift < meheight) {
		if (meshift + mestep > meheight) {meshift = meheight;} else {meshift += mestep;}
		mefix.height = meshift+'px';
		mecss.clip = 'rect(0px, auto, '+meshift+'px, 0px)';
		metimer = setTimeout('slideon()', 10);
	}
}
function slideoff() {
	if (meshift == 0) {mecss.visibility = 'hidden'; clearTimeout(metimer); inaction = 0;}
	if (meshift > 0) {
		if (meshift-mestep < 0) {meshift = 0;} else {meshift -= mestep;}
		mefix.height = meshift+'px';
		mecss.clip = 'rect(0px, auto, '+meshift+'px, 0px)';
		metimer = setTimeout('slideoff()', 10);
	}
}

function fixoff() {
	if (meshift2 == mefinalh) {clearTimeout(mftimer);}
	if (meshift2 > mefinalh) {
		if (meshift2 - mestep < mefinalh) {meshift2 = mefinalh;} else {meshift2 -= mestep;}
		mffix.height = meshift2+'px';
		mfcss.clip = 'rect(0px, auto, '+meshift2+'px, 0px)';
		mftimer = setTimeout('fixoff()', 10);
	}
}

function fixon() {
	if (meshift2 == mefinalh) {clearTimeout(mftimer);}
	if (meshift2 < mefinalh) {
		if (meshift2 + mestep > mefinalh) {meshift2 = mefinalh;} else {meshift2 += mestep;}
		mffix.height = meshift2+'px';
		mfcss.clip = 'rect(0px, auto, '+meshift2+'px, 0px)';
		mftimer = setTimeout('fixon()', 10);
	}
}





var zcounter = 100;
var inhand = null;
function n(){}

function Tip(tipid){
	this.id = tipid;
	this.div = this.id+'_div';
	this.height = document.getElementById(this.div).offsetHeight;
	this.width = document.getElementById(this.div).offsetWidth;
	this.css = document.getElementById(this.div).style;
	this.timer = null;
	this.bodyshift = findPosX('bodydiv');
	this.bodywidth = 1000;
	this.x = 0;
	this.y = 0;
	this.downx = 0;
	this.downy = 0;
	this.distx=0;
	this.disty=0;
	this.opacity=1;
}
Tip.prototype.premove = function precontrol() {
	inhand = this.id;
	document.onmousemove=eventpremove;
}
Tip.prototype.premovestop = function precontrolstop() {
	document.onmousemove=null;
}
Tip.prototype.open = function tipopen() {
	this.css.zIndex = zcounter; zcounter ++;
	this.css.visibility = "visible";
	document.onmousemove=null;
}
Tip.prototype.flowopen = function flowtipopen() {
	inhand = this.id;
	this.css.zIndex = zcounter; zcounter ++;
	this.css.visibility = "visible";
	document.onmousemove = eventpremove;
}
Tip.prototype.control = function tipcontrol() {
	inhand = this.id;
	document.onmousemove=eventtipmove;
}
Tip.prototype.move = function tipmove() {
	inhand = this.id;
	this.css.zIndex = zcounter; zcounter ++;
	dx = this.css.left;
	dy = this.css.top;
	this.distx = this.downx - dx.substring(0,dx.length-2)*1;
	this.disty = this.downy - dy.substring(0,dy.length-2)*1;
	document.onmousemove=eventtipmove2;
}
Tip.prototype.demove = function tipdemove() {
	document.onmousemove=eventtipmove2;
}
Tip.prototype.stopcontrol = function tipstopcontrol() {
	//document.onmousemove=null;
}
Tip.prototype.close = function fixtipclose() {
	tipfade(this);
}

function tipfade(abj) {
	if (abj.opacity < 0.11) {
		abj.css.visibility = 'hidden';
		abj.css.opacity = 1;
		abj.opacity = 1;
		//document.onmousemove=null;
		return;
	}
	if (abj.opacity >= 0.11) {
		abj.opacity -= 0.1;
		abj.css.opacity = abj.opacity;
		abj.timer = setTimeout('tipfade(TipsPapa.'+abj.id+')', 10);
	}
}

function eventtipmove(e){
	abj = TipsPapa[inhand];
	abj.downx = ie?event.x:e.pageX;
	abj.downy = ie?event.y:e.pageY;
	if (ie==1) abj.downy=document.body.scrollTop+abj.downy;
}

function eventtipmove2(e){
	abj = TipsPapa[inhand];
	abj.x = ie?event.x:e.pageX;
	abj.y = ie?event.y:e.pageY;
	if (ie==1) abj.y=document.body.scrollTop+abj.y;
	abj.css.left=abj.x-abj.distx; abj.css.top=abj.y-abj.disty;
}
function eventpremove(e){
	abj = TipsPapa[inhand];
	abj.x = ie?event.x:e.pageX;
	abj.y = ie?event.y:e.pageY;
	if (ie==1) abj.y=document.body.scrollTop+abj.y;
	delta = parseInt((abj.x-abj.bodyshift)*abj.width/abj.bodywidth);
	abj.css.left=abj.x-delta-8; abj.css.top=abj.y-abj.height-18;
	rotator = (abj.x-abj.bodyshift-500)/50;
	abj.css.webkitTransform = 'rotate('+rotator+'deg)';
	abj.css.MozTransform = 'rotate('+rotator+'deg)';
	abj.css.OTransform = 'rotate('+rotator+'deg)';
	abj.css.MsTransform = 'rotate('+rotator+'deg)';
	abj.css.transform = 'rotate('+rotator+'deg)';
	
	
}

var swaphand = null;

function Swap(sid){
	this.id = sid;
	this.fix = document.getElementById(this.id+'_fix').style;
	this.height = document.getElementById(this.id+'_div').offsetHeight;
	this.css = document.getElementById(this.id+'_div').style;
	this.arrow = document.getElementById(this.id+'_i');
	this.timer = null;
	this.step = parseInt(this.height/12);
	this.state = 0;
	this.shift = 0;
}

Swap.prototype.toggle = function swaptoggle() {
	if (this.state == 0) {
		this.height = document.getElementById(this.id+'_div').offsetHeight;
		this.timer = null;
		this.shift = 0;
		this.arrow.src = '/style/i/z_tr2_on.png';
		swaphand = this;
		clearTimeout(this.timer);
		this.css.visibility = 'visible';
		swapon();
	} else {
		this.timer = null;
		this.shift = this.height;
		this.arrow.src = '/style/i/z_tr2_off.png';
		swaphand = this;
		this.shift = this.height;
		clearTimeout(this.timer);
		swapoff();	
	}
}

function swapon() {
	me = swaphand;
	if (me.shift == me.height) {me.state = 1; clearTimeout(me.timer);}
	if (me.shift < me.height) {
		if (me.shift + me.step > me.height) {me.shift = me.height;} else {me.shift += me.step;}
		me.fix.height = me.shift+'px';
		me.css.clip = 'rect(0px, auto, '+me.shift+'px, 0px)';
		me.timer = setTimeout('swapon()', 10);
	}
}
function swapoff() {
	me = swaphand;
	if (me.shift == 0) {me.css.visibility = 'hidden'; me.state = 0; clearTimeout(me.timer);}
	if (me.shift > 0) {
		if (me.shift-me.step < 0) {me.shift = 0;} else {me.shift -= me.step;}
		me.fix.height = me.shift+'px';
		me.css.clip = 'rect(0px, auto, '+me.shift+'px, 0px)';
		me.timer = setTimeout('swapoff()', 10);
	}
}


function tabswitch(tabid,tabnum,taball) {
	tabold = 0;
	for (i=1; i <= taball; i++) {
		if (document.getElementById(tabid+i+'_div').style.visibility == 'visible') tabold = i;
	}
	
	if (tabold == tabnum) return;

	tabcase = 2;
	if (tabnum == 1) tabcase = 1;
	if (tabnum == taball) tabcase = 3;
	tabcaseold = 2;
	if (tabold == 1) tabcaseold = 1;
	if (tabold == taball) tabcaseold = 3;
	
	switch (tabcaseold) {
	case 1:
	  document.getElementById(tabid+'_td'+tabold).style.background = "url('/style/i/z_tab_ap.png')";
	  break
	case 2:
	  document.getElementById(tabid+'_td'+tabold).style.background = "url('/style/i/z_tab_bp.png')";
	  break
	case 3:
	  document.getElementById(tabid+'_td'+tabold).style.background = "url('/style/i/z_tab_cp.png')";
	  document.getElementById(tabid+'_td'+tabold).style.backgroundPosition = "right";
	  break
	 }
	
	switch (tabcase) {
	case 1:
	  document.getElementById(tabid+'_td'+tabnum).style.background = "url('/style/i/z_tab_aa.png')";
	  break
	case 2:
	  document.getElementById(tabid+'_td'+tabnum).style.background = "url('/style/i/z_tab_ba.png')";
	  break
	case 3:
	  document.getElementById(tabid+'_td'+tabnum).style.background = "url('/style/i/z_tab_ca.png')";
	  document.getElementById(tabid+'_td'+tabnum).style.backgroundPosition = "right";
	  break
	 }
	taboldsize = document.getElementById(tabid+tabold+'_div').offsetHeight;
	tabnewsize = document.getElementById(tabid+tabnum+'_div').offsetHeight;	
	tabdif = tabnewsize - taboldsize;
	obj = document.getElementById(tabid+tabnum+'_div').style;
	obj2 = document.getElementById(tabid+'_fix').style;
	obj3 = document.getElementById(tabid+tabold+'_div').style;
	
	if (tabdif >= 0) {
		obj.clip = 'rect(0px, auto, '+(tabnewsize-tabdif)+'px, 0px)';
		obj.visibility = 'visible';
		obj3.visibility = 'hidden';
		step = Math.round(tabdif/10);
		size = taboldsize;
		shift = 0;
		tabInc();
	} else {
		obj.clip = 'rect(0px, auto, '+(tabnewsize-tabdif)+'px, 0px)';
		step = Math.round(-tabdif/10);
		size = taboldsize;
		shift = -tabdif;
		tabDec();			
	}
	
}
function tabInc() {
	if (shift < tabdif) {
		if ((shift+step) > tabdif) {shift = tabdif;} else {shift += step;}
		obj2.height = (shift+size)+'px';
		obj.clip = 'rect(0px, auto, '+(shift+size)+'px, 0px)';
		menutimer = setTimeout('tabInc()', 10);
	}
}
function tabDec() {
	if (shift < step+1) {
		obj.visibility = 'visible';
		obj3.visibility = 'hidden';
		}
	if (shift > 0) {
		if ((shift-step) < 0) {shift = 0;} else {shift -= step;}
		obj2.height = (size+tabdif+shift)+'px';
		obj3.clip = 'rect(0px, auto, '+(size+tabdif+shift)+'px, 0px)';
		menutimer = setTimeout('tabDec()', 10);
	}
}


function findPosY(id) {
	fobj = document.getElementById(id);
	var curtop = 0;
	while (fobj.offsetParent) { curtop += fobj.offsetTop; fobj = fobj.offsetParent; }
	return curtop;
}
function findPosX(id) {
	fobj = document.getElementById(id);
	var curtop = 0;
	while (fobj.offsetParent) { curtop += fobj.offsetLeft; fobj = fobj.offsetParent;}
	return curtop;
}


var zoomhand = null;

function Zoomer(zoomid, imageurl, iw, ih){
	this.id = zoomid;
	this.url = imageurl;
	this.imagewidth = iw;
	this.imageheight = ih;
	this.starter = document.getElementById(this.id+'_a');
	this.frame = document.getElementById(this.id+'_div');
	this.cont = document.getElementById(this.id+'_cont');
	this.steps = 14;
	this.timer = null;
	this.x = 0;
	this.y = 0;
	this.downx = 0;
	this.downy = 0;
	this.distx=0;
	this.disty=0;
	this.flag = false;
}

Zoomer.prototype.open = function zoomopen() {
	eval('clobj = ZoomPapa.'+this.id+'.flag');
	if (clobj == false) {
	eval('ZoomPapa.'+this.id+'.flag = true');
	this.img  = new Image(this.imagewidth, this.imageheight);
	this.img.src = this.url;
	this.starterx = findPosX(this.id+'_a');
	this.startery = findPosY(this.id+'_a');
	this.starterw = this.starter.offsetWidth;
	this.starterh = this.starter.offsetHeight;
	this.startx = this.starterx + this.starterw/2;
	this.starty = this.startery + this.starterh/2;
	py = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	this.finaly = py+(document.body.clientHeight)/2;
	if (this.finaly < this.imageheight/2 + 30) this.finaly = this.imageheight/2 + 30;
	this.finalx = document.body.clientWidth / 2;
	this.stepx = (this.finalx - this.startx)/this.steps;
	this.stepy = (this.finaly - this.starty)/this.steps;
	this.stepw = this.imagewidth/this.steps;
	this.steph = this.imageheight/this.steps;
	this.shiftw = 0;
	this.shifth = 0;
	this.opacity = 1;
	this.frame.style.top = this.starty - parseInt(this.frame.offsetHeight/2);
	this.frame.style.left = this.startx - parseInt(this.frame.offsetWidth/2);
	this.frame.style.visibility = 'visible';
	this.frame.style.zIndex = zcounter; zcounter ++;
	zoomhand = this;
	this.img.style.visibility = 'hidden';
	zoom();
	}
}
Zoomer.prototype.close = function zoomclose() {
	zoomhand = this;
	document.onmousemove=null;
	zoomfade();
	eval('ZoomPapa.'+this.id+'.flag = false');
}

function zoomfade() {
	me = zoomhand;
	if (me.opacity < 0.11) {
		me.img.style.visibility = 'hidden';
		me.frame.style.visibility = 'hidden';
		me.cont.removeChild(me.img);
		me.frame.style.opacity = 1;
	}
	if (me.opacity >= 0.11) {
		me.opacity -= 0.1;
		me.frame.style.opacity = me.opacity;
		me.timer = setTimeout('zoomfade()', 20);
	}
}


Zoomer.prototype.control = function zoomcontrol() {
	inhand = this.id;
	document.onmousemove=eventzoommove;
}
Zoomer.prototype.move = function zoommove() {
	inhand = this.id;
	this.frame.style.zIndex = zcounter; zcounter ++;
	dx = this.frame.style.left;
	dy = this.frame.style.top;
	this.distx = this.downx - dx.substring(0,dx.length-2)*1;
	this.disty = this.downy - dy.substring(0,dy.length-2)*1;
	document.onmousemove=eventzoommove2;
}
Zoomer.prototype.demove = function zoomdemove() {
	document.onmousemove=eventzoommove2;
}
Zoomer.prototype.stopcontrol = function zoomstopcontrol() {
	document.onmousemove=null;
}
function eventzoommove(e){
	abj = zoomhand;
	abj.downx = ie?event.x:e.pageX;
	abj.downy = ie?event.y:e.pageY;
	if (ie==1) abj.downy=document.body.scrollTop+abj.downy;
}
function eventzoommove2(e){
	abj = zoomhand;
	abj.x = ie?event.x:e.pageX;
	abj.y = ie?event.y:e.pageY;
	if (ie==1) abj.y=document.body.scrollTop+abj.y;
	abj.frame.style.left=abj.x-abj.distx; abj.frame.style.top=abj.y-abj.disty;
}
function zoom() {
	me = zoomhand;
	if ((me.shifth == me.imageheight) || (me.shiftw == me.imagewidth)) {
		me.cont.appendChild(me.img);
		me.img.style.visibility = 'visible';
	}
	if ((me.shifth+1 < me.imageheight) || (me.shiftw+1 < me.imagewidth)) {
		if (me.shiftw + me.stepw+1 > me.imagewidth) {
			me.shiftw = me.imagewidth;
			me.startx = me.finalx;
		} else {
			me.shiftw += me.stepw; me.startx += me.stepx;
		}
		if (me.shifth + me.steph+1 > me.imageheight) {
			me.shifth = me.imageheight;
			me.starty = me.finaly;
		} else {
			me.shifth += me.steph; me.starty += me.stepy;
		}
		me.cont.style.height = parseInt(me.shifth)+'px';
		me.cont.style.width = parseInt(me.shiftw)+'px';
		me.frame.style.top = parseInt(me.starty - me.frame.offsetHeight/2);
		me.frame.style.left = parseInt(me.startx - me.frame.offsetWidth/2);

		me.timer = setTimeout('zoom()', 20);
	}
}

function blog_check() {
	var alert_flag = 0;
	var alert_text = "Пожалуйста, заполните все необходимые поля.\nОстались незаполненными:\n";
	if (document.message_form.form_mess.value == '' || document.message_form.form_mess.value == ' ') { alert_flag = 1; alert_text = alert_text +'- Текст сообщения\n'; }
	if (document.message_form.form_name.value == '') { alert_flag = 1; alert_text = alert_text +'- Имя отправителя\n'; }
	if (document.message_form.form_control.value == '') { alert_flag = 1; alert_text = alert_text +'- Проверка против спам-роботов\n'; }
	if (alert_flag != 0) { alert(alert_text); return; }

	document.message_form.submit();
}


function Len() {
	len = document.message_form.form_mess.value.length;
	len = parseInt(501*len/2000);
	if (len < 400) {
		document.getElementById('message_length').style.backgroundColor = '#23910A';
		document.getElementById('message_length').style.width = len;
		} else {
		document.getElementById('message_length').style.backgroundColor = 'orange';
		document.getElementById('message_length').style.width = len;
		}

	if (len > 500) {
		document.getElementById('message_length').style.backgroundColor = 'red';
		document.getElementById('message_length').style.width = 501;
		}
}
function Chk() {
	chk = document.message_form.form_control.value;
	if (chk == '4') document.getElementById('form_c').style.backgroundColor = '#d3fac2';
	else document.getElementById('form_c').style.backgroundColor = '#fffcc8';
	
}
function Chk2() {
	chk = document.message_form.form_control.value;
	if (chk == '9') document.getElementById('form_c').style.backgroundColor = '#d3fac2';
	else document.getElementById('form_c').style.backgroundColor = '#fffcc8';
	
}
