var offDelay = 350;

// -------------------------------------------------

var ie = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns5 = (document.getElementById && !document.all) ? true : false;
var myWidth = 0;

function hova() 
{
	if(document.body && ( document.body.clientWidth) ) 
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	else if(document.documentElement && ( document.documentElement.clientWidth) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	else if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
	} 
}

// -------------------------------------------------

function showLayer(name) {
	var wx=0;
	hova();
	switch (name)
	{
		case 'layer_mag_menu': wx=10; break;
		case 'layer_jat_menu': wx=150; break;
		case 'layer_szolg_menu': wx=311; break;
		case 'layer_ar_menu': wx=496; break;
	}
	if (ie) 
	{
		if(myWidth>800)	document.all[name].style.left = (myWidth-800)/2 + wx;
		else document.all[name].style.left = wx;
		document.all[name].style.visibility = "visible";
	}
	if (ns4)
	{
		document.layers[name].style.top = 150 + 'px';
		if(myWidth>800)	document.layers[name].style.left = (myWidth-800)/2 + wx + 'px';
		else document.layers[name].style.left = wx + 'px';
		document.layers[name].visibility = "show";
	}
	if (ns5)
	{
		document.getElementById(name).style.top = 150 + 'px';
		if(myWidth>800)	document.getElementById(name).style.left = (myWidth-800)/2 + wx + 'px';
		else document.getElementById(name).style.left = wx + 'px';
		document.getElementById(name).style.visibility = "visible";
	}
}

function hideLayer(name) 
{
	if (ie) document.all[name].style.visibility = "hidden";
	if (ns4) document.layers[name].visibility = "hide";
	if (ns5) document.getElementById(name).style.visibility = "hidden";
}

// -------------------------------------------------

function oMenu(name, lCount, docked) 
{
	this.name = name;	this.oname = name;
	this.menuname = "layer_" + name + "_menu";
	this.obj = this.menuname + "_object"; 
	eval(this.obj + " = this");
	this.lCount = lCount;
	this.docked = docked;
	this.bTimer = false;

	this.arrNew = new Array();
	this.arrOld = new Array();

	this.imgOver = m_imgOver;
	this.imgOut = m_imgOut;

	this.open = m_open;
	this.close = m_close;
	this.realClose = m_realClose;

	for (i = 0; i < lCount; i++)
	{
		this.arrOld[i] = new Image(); 
		this.arrOld[i].src = "img/" + this.name + "_" + i + ".gif";
		this.arrNew[i] = new Image(); 
		this.arrNew[i].src = "img/" + this.name + "_" + i + "_on.gif";
	}
	this.menuimgon = new Image();
	this.menuimgon.src = "img/menu_"  + this.name + "_on.gif";
	this.menuimg = new Image();
	this.menuimg.src = "img/menu_"  + this.name + ".gif";
}

function m_imgOver(num) 
{
	closeAll(this.name);
	if (this.bTimer)
	{
		clearTimeout(this.bTimer); this.bTimer = false;
	}
	if (document.images && (num > -1)) document.images["img_" + this.name + "_" + num].src = this.arrNew[num].src;
}

function m_imgOut(num) {
	if (document.images && (num > -1)) document.images["img_" + this.name + "_" + num].src = this.arrOld[num].src;
	this.close();
}

function m_open() {
	closeAll(this.name);
	if (this.docked) return;
	if (this.bTimer) 
	{
		clearTimeout(this.bTimer); this.bTimer = false;
	}
	showLayer(this.menuname);
	if (document.images) document.images["title_" + this.name].src = this.menuimgon.src;
}

function m_close() 
{
	if (this.docked) return;
	if (this.bTimer)
	{
		clearTimeout(this.bTimer); this.bTimer = false;
	}
	this.bTimer = setTimeout(this.obj + ".realClose()", offDelay);
}

function m_realClose() 
{
	if (this.bTimer) clearTimeout(this.bTimer);
	this.bTimer = false;
	if (!this.docked) 
	{
		document.images["title_" + this.name].src = this.menuimg.src;
		hideLayer(this.menuname);
	}
}

// -------------------------------------------------

function closeAll(exc) {
	if (exc != "mag") menu_mag.realClose();
	if (exc != "jat") menu_jat.realClose();
	if (exc != "szolg") menu_szolg.realClose();
	if (exc != "ar") menu_ar.realClose();
}

// -------------------------------------------------

var mm_offTimer = false;

function mego_goto(num) 
{
	if (!document.mego) return false;
	if (num == 10) 
	{
		mm_offTimer = setTimeout("mego_goto10()", 500);
	}
	else {
		if (mm_offTimer) 
		{
			clearTimeout(mm_offTimer);
			mm_offTimer = false;
		}
		var mego_ojjektum = (document.all) ? mego : document.mego;
		if (mego_ojjektum) 
		{
			var m_oks = mego_ojjektum.GetVariable("loaded_ok");
			if (m_oks == "ok") mego_ojjektum.gotoframe(num);
		}
	}
}

function mego_goto10() 
{
	mm_offTimer = false;
	if ((mouseX > 380) && (mouseX < 760) && (mouseY > 170) && (mouseY < 335)) {
		mm_offTimer = setTimeout("mego_goto10()", 500);
		return false;
	}
	var mego_ojjektum = (document.all) ? mego : document.mego;
	if (mego_ojjektum) {
		var m_oks = mego_ojjektum.GetVariable("loaded_ok");
		if (m_oks == "ok") mego_ojjektum.gotoframe(10);
	}
}

function proc_mousemove(e) 
{
	if (ie) 
	{
		mouseX = event.clientX;
		mouseY = event.clientY + document.body.scrollTop;
	}
	else {
		mouseX = 0;
		mouseY = 0;
	}
}

document.onmousemove = proc_mousemove;

// -------------------------------------------------

var menu_mag = new oMenu("mag", 2, false);
var menu_jat = new oMenu("jat", 10, false);
var menu_szolg = new oMenu("szolg", 5, false);
var menu_ar = new oMenu("ar", 3, false);
