var menuProtect = false;
var timeOut = 3000;
var elmWidth = 150;
var IEoffset = 3;
var isIE = false;
var eX, eY;

function objGet(x)
{
	if (typeof x != 'string')
		return x;
	else if (Boolean(document.getElementById))
		return document.getElementById(x);
	else if (Boolean(document.all))
		return eval('document.all.'+x);
	else
		return null;
}


function wop(url) {
	window.open (url, "cwPopup", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=400,height=300");
}


function showhide(e)
{
	curState = objGet(e).style.display;
	if (curState=="none")
		objGet(e).style.display = "block";
	else 
		objGet(e).style.display = "none";
}

function startHide()
{
	setTimeout("doHide()",timeOut);
}

function doHide()
{
	if (!menuProtect)
		objGet("popup").style.display = "none";
}

function setProtect(type)
{
	menuProtect = type;
	if (type)
		objGet("popup").style.display = "block";
	else
		startHide();
}

function buildMenu(data)
{
	var rS = "<div class='menucontainer' id='indicate'>";
	for (n=0; n<data[0].length; n++)
	{
		rS += "<a href='"+data[1][n]+"'";
		if (location.pathname+location.search == data[1][n])
			rS += " class='sel'";
		rS += ">"+data[0][n]+"</a><br/>";
	}
	rS += "</div>";
	return rS;
}

function loadMenu(id)
{
	// Highlight active category
	resetHighlight();
	objGet("MainMenu_"+id).className = "dummyMenu sel";
	
	indPos = -1;
	
	// If the category has children, load them here
	if (subMenu[id].length>0)
	{
		// Load content
		objGet("popup").innerHTML = buildMenu(subMenu[id]);
		// Calculate position of children menus
		if (subMenu[id][0].length>1)
		{
			newPos = (id-1)*elmWidth;
		}
		else
			newPos = 0;
		
		if (!isIE)
			newPos += IEoffset;
			
		// Move child-menu
		objGet("popup").style.left = newPos+"px";
		objGet("popup").style.display = "block";
		setProtect(1);
	}
	else
		doHide();
}

function resetHighlight()
{
	// Reset class definitions on all category buttons
	for (n=1;n<subMenu.length;n++)
		objGet("MainMenu_"+n).className = "dummyMenu";
}

function initMenu()
{
	var browserString = navigator.userAgent;
	if ((browserString.indexOf("MSIE")>0) && (browserString.indexOf("Opera")==-1))
		isIE = true;
}
