var menus = null;
var popoutTimer = null;
var popoutVisible = -1;

function initMenus()
{
	menus = new Array(menuCount);
	for (var i=0;i<menuCount;i++)
	{
		menus[i] = new Object();
		menus[i].visible = false;
		
		menus[i].topitem = document.getElementById('m'+i+'t');
		menus[i].before = document.getElementById('m'+i+'b');
		menus[i].after = document.getElementById('m'+i+'a');
		menus[i].dropdown = document.getElementById('m'+i+'d');
		menus[i].right = document.getElementById('m'+i+'r');
		menus[i].bottom = document.getElementById('m'+i+'u');

		var rc = document.getElementById('m'+i+'rc');
		rc.width="1px";
		rc.height=(menus[i].dropdown.offsetHeight-2)+"px";
		
		menus[i].right.style.top = String(fTop(menus[i].topitem)+29) + "px";
		menus[i].bottom.style.left = String(fLeft(menus[i].topitem)-1) + "px";

		var bc = document.getElementById('m'+i+'uc');
		bc.height="2px";
		bc.width=String(menus[i].dropdown.offsetWidth-1)+"px";
		
		menus[i].dropdown.style.left = String(fLeft(menus[i].topitem)-3) + "px";
		menus[i].dropdown.style.top = String(fTop(menus[i].topitem)+27) + "px";
		menus[i].bottom.style.top = String(fTop(menus[i].dropdown)+menus[i].dropdown.offsetHeight) + "px";
		menus[i].right.style.left = String(fLeft(menus[i].dropdown)+menus[i].dropdown.offsetWidth) + "px";
	}
}
function popoutShow(n)
{
	setMenuStatus(n,"2");
	popoutVisible = n;
	fadeIn(n);
}
function popoutHide(n)
{
	setMenuStatus(n,"0");
	popoutVisible = -1;
	fadeOut(n);
}
function downD(s)
{
	s.className = "md3";
}
function clickD(u)
{
	if (popoutVisible>=0)
	{
		setMenuStatus(popoutVisible,"0");
		fadeStep(popoutVisible,0);
		popoutVisible = -1;
	}
	if (u == "hp")
	{
		sC("hp","1",14);
		window.location.reload();
	}
	if (u == "sp")
	{
		uC("hp");
		window.location.reload();
	}
	if (window.location.assign)
		window.location.assign(u);
	else if (window.location.replace)
		window.location.replace(u);
	else
		alert("cannot open url '"+u+"'");

}
function hoverInD(s)
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	s.className = "md2";
}
function hoverOutD(s)
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	s.className = "md1";
	if (popoutVisible>=0) popoutTimer = setTimeout('popoutHide('+popoutVisible+')',fd2);
}
function hoverInS()
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
}
function hoverOutS()
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	if (popoutVisible>=0) popoutTimer = setTimeout('popoutHide('+popoutVisible+')',fd2);
}
function hoverIn(n)
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	if (!menus) initMenus();
	
	if (popoutVisible>=0)
	{
		if (popoutVisible!=n)
		{
			popoutHide(popoutVisible);
			popoutShow(n);
		}
	}
	else
	{
		setMenuStatus(n,"1");
		popoutTimer = setTimeout('popoutShow('+n+')',fd1);
	}
}
function hoverOut(n)
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	if (popoutVisible>=0)
		popoutTimer = setTimeout('popoutHide('+popoutVisible+')',fd2);
	else
		setMenuStatus(n,"0");
}
function fLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) curleft += obj.offsetLeft;
	}
	return curleft;
}
function fTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) curtop += obj.offsetTop;
	}
	return curtop;
}
function fadeStep(n,v)
{
	setOpacity(menus[n].dropdown,v);
	setOpacity(menus[n].right,v/6);
	setOpacity(menus[n].bottom,v/6);
	if (v>0)
	{
		menus[n].dropdown.style.visibility="visible";
		menus[n].right.style.visibility="visible";
		menus[n].bottom.style.visibility="visible";
	}
	else
	{
		menus[n].dropdown.style.visibility="hidden";
		menus[n].right.style.visibility="hidden";
		menus[n].bottom.style.visibility="hidden";
	}
}
function setOpacity(e,v)
{
	e.style.opacity = v/10;
	e.style.filter = "alpha(opacity=" + v*10 + ")";
}
function fadeIn(n)
{
	if (n<0 || n>= menus.length) return;
	for (var i=1;i<11;i++) setTimeout('fadeStep('+n+','+i+')',fi1*i);
}
function fadeOut(n)
{
	if (n<0 || n>= menus.length) return;

	for (var i=1;i<=10;i++) setTimeout('fadeStep('+n+','+(10-i)+')',fi2*i);
}
function menuClick(n)
{
	if (popoutTimer) { clearTimeout(popoutTimer); popoutTimer=null; }
	if (popoutVisible<0) popoutShow(n);
}
function setMenuStatus(n,v)
{
	if (n>=0 && n<menuCount && menus[n])
	{
		menus[n].topitem.className="m1"+v;
		menus[n].before.className="m0"+v;
		menus[n].after.className="m2"+v;
	}
}
function wT(n,t)
{
	document.write('<td class="m00" id="m'+n+'b"></td>');
	document.write('<td class="m10" id="m'+n+'t" onmouseover="hoverIn('+n+')" onmouseout="hoverOut('+n+')" onclick="menuClick('+n+')"><span unselectable="on">'+t+'</span></td>');
	document.write('<td class="m20" id="m'+n+'a"></td>');
}
function wD1(n)
{
	document.write('<div class="mdd" id="m'+n+'d">');
	document.write('<table class="mdt" cellspacing="0" cellpadding="1">');
}
function wD2(t,u)
{
	document.write('<tr class="mdr"><td class="md1" onmouseover="hoverInD(this)" onmouseout="hoverOutD(this)" onmousedown="downD(this)" onclick="clickD('+"'"+u+"'"+');"><span unselectable="on">'+t+'</span></td></tr>');
}
function wD3()
{
	document.write('<tr class="mdrs"><td class="mdcs" onmouseover="hoverInS()" onmouseout="hoverOutS()"></td></tr>');
}
function wD4(n)
{
	document.write('</table></div>');
	document.write('<table class="mdsr" cellspacing="0" border="0" id="m'+n+'r"><tr><td id="m'+n+'rc"></td></tr></table>');
	document.write('<table class="mdsb" cellspacing="0" border="0" id="m'+n+'u"><tr><td id="m'+n+'uc"></td></tr></table>');
}
function wD5(s,a)
{
	wD6(s+'.php',s,a);
}
function wD6(t,s,a)
{
	var w = 98;
	var h = 79;
	var x = window.document.body.offsetWidth - 20;
	if (x < (w*12))
	{
		w = Math.floor(x / 12);
		h = Math.floor(w * (79/98));
	}
	document.write('<a href="'+t+'"><img border="0" src="images/nav/'+s+'.png" alt="'+a+'" width="'+w+'px" height="'+h+'px"></img></a>');
}
function sC(n,v,x)
{
	var d = new Date();
	d.setDate(d.getDate()+x);
	document.cookie = n+ "=" +escape(v)+((x==null) ? "" : ";expires="+d.toGMTString());
}
function uC(n)
{
	var d = new Date();
	d.setTime(d.getTime() - 1);
	document.cookie = n+ "=;expires=" + d.toGMTString();
}
function gC(n)
{
	if (document.cookie.length>0)
	{
		b = document.cookie.indexOf(n + "=");
		if (b!=-1)
		{
			b = b + n.length + 1;
			e = document.cookie.indexOf(";",b);
			if (e==-1) e = document.cookie.length;
			return unescape(document.cookie.substring(b,e));
		}
	}
	return "";
}

