$(document).ready(function(){var mMenu=new MMenu(); grayImage(); var vizit=new firstVisit(); });

function MMenu() {
	this.timeOut=0;
	this.timeOut2=0;
	this.lastLevel1=0;
	this.lastLevel2=0;
	this.l2pref='a';
	this.l3pref='b';
	this.trigger=0;
	var el=this;
	this.timeSpeed=500;
	this.lastInactiv=0;
	$('.level1 a, .level1 span').mouseover(function(){ el.level1Over(this.id); });
	$('.level1 a, .level1 span').mouseout(function(){ el.level1Out(this.id); });
	$('.level2').mouseover(function(){ el.level2Over(this.id); });
	$('.level2').mouseout(function(){ el.level2Out(this.id); });
}

MMenu.prototype.level1Over=function(sid) {
	if (this.timeOut) {
		clearTimeout(this.timeOut);
		this.timeOut=0;
		if(this.lastLevel1!=sid) this.level1Clear();
	}
	if (document.getElementById(this.l2pref+sid)) {
		this.lastLevel1=sid;
		var uw=$('#'+this.l2pref+sid).outerWidth();
		var aw=$('#'+sid).outerWidth();
		if(aw>uw) $('#'+this.l2pref+sid).css({width:(aw-30)+'px'});
		document.getElementById(this.l2pref+sid).style.display='block';
		if(!$('#'+sid).hasClass('on')&&$('#'+sid).attr('href')) this.lastInactiv=1;
		if(this.lastInactiv) $('#'+this.lastLevel1).addClass('on');
	}
}

MMenu.prototype.level1Out=function(sid) {
	if (!this.timeOut) {
		var el=this;
		this.timeOut=setTimeout(function() {el.level1Clear();}, this.timeSpeed);
	}
}

MMenu.prototype.level2Over=function(sid) {
	if (this.timeOut) { clearTimeout(this.timeOut); this.timeOut=''; }
	if(this.lastInactiv) $('#'+this.lastLevel1).addClass('on');
	document.getElementById(sid).style.display='block';
}

MMenu.prototype.level2Out=function(sid) {
	if (!this.timeOut) {
		var el=this;
		this.timeOut=setTimeout(function() {el.level1Clear();}, this.timeSpeed);
	}
}

MMenu.prototype.level2linkOver=function (sid) {
	if (this.timeOut2) {
		clearTimeout(this.timeOut2);
		this.timeOut2=0;
		if(this.lastLevel2!=sid) this.level2Clear();
	}
	if (document.getElementById(this.l3pref+sid)) {
		this.lastLevel2=sid;
		document.getElementById(this.l3pref+sid).style.display='block';
		$('#menu3marker').show();
		var offset = $('#'+sid).parent().parent().position();
		var loff=offset.left+230;
		$('#'+this.l3pref+sid).css({ left:loff+'px' });
		$('#menu3marker').css({ left:(loff-10)+'px', top:($('#'+sid).position().top+8)+'px' });
	}
}

MMenu.prototype.level2linkOut=function(sid) {
	if (!this.timeOut2) {
		var el=this;
		this.timeOut2=setTimeout(function() {el.level2Clear();}, this.timeSpeed);
	}
}

MMenu.prototype.level3Over=function(sid) {
	if (this.timeOut2) { clearTimeout(this.timeOut2); this.timeOut2=''; }
	document.getElementById(sid).style.display='block';
}

MMenu.prototype.level3Out=function(sid) {
	if (!this.timeOut2) {
		var el=this;
		this.timeOut2=setTimeout(function() {el.level2Clear();}, this.timeSpeed);
	}
}

MMenu.prototype.level1Clear=function() {
	if (document.getElementById(this.l2pref+this.lastLevel1)) {
		document.getElementById(this.l2pref+this.lastLevel1).style.display='none';
		if(this.lastInactiv) $('#'+this.lastLevel1).removeClass('on');
	}
}

MMenu.prototype.level2Clear=function() {
	if (document.getElementById(this.l3pref+this.lastLevel2)) {
		document.getElementById(this.l3pref+this.lastLevel2).style.display='none';
		$('#menu3marker').hide();
	}
}

function grayImage() {
    $('.gray').each(function(){
      (new Image()).src=this.src.replace(/144_/,'126_');
    });
    $('.cat div').mouseover(function(){detiOver(this)}).mouseout(function(){detiOut(this)});
}

function detiOver(el) {
	el=$(el);
	el.find('.info a').addClass('on');
	el.find('.conf a').addClass('on');
	var img=el.find('.gray');
	if(img.attr('src')) img.attr('src',img.attr('src').replace(/144_/,'126_'));
}

function detiOut(el){
	el=$(el);
	el.find('.info a').removeClass('on');
	el.find('.conf a').removeClass('on');
	var img=el.find('.gray');
	if(img.attr('src')) img.attr('src',img.attr('src').replace(/126_/,'144_'));
}

function firstVisit() {
	this.shadow=$('#warningShadow');
	this.shadow.css({ width:$(document).width()+'px', height:$(document).height()+'px', opacity:0.98 });
	this.shadow.show();
	$('#shadowBg').css({ left:(($(document).width()/2)-270)+'px', top:(($(window).height()/2)-285)+'px'  });
	var el=this;
	$('#enterButton img').click(function(){el.enter();});
}

firstVisit.prototype.enter=function() {
	this.setMyCookie('isVisit','1');
	this.shadow.hide();
	$('#shadowBg').hide();
}

firstVisit.prototype.setMyCookie=function(names,sid) {
	document.cookie=names+'='+sid+"; path=/";
}

firstVisit.prototype.getMyCookie=function(name) {
	var allCookie=document.cookie.split('; ');
	var count=allCookie.length;
	var ret='';
	for (i=0; i<count; i++) {
		now_cookie=allCookie[i].split('=');
		if (now_cookie[0]==name) ret=now_cookie[1];
	}
	return ret;
}

function formIsLoad() {
    setTimeout(function(){$('#Qin').removeAttr('readonly');$('#in').removeAttr('readonly');$('#in').val(0);},1000);
}
