var timeout_id = 0; // Set timeout_id to zero when page is loaded.
//var menuCount = 7; // Number of menu items.

// Find x position
function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

//Find y position
function findPosY(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

// Hide all submenu items
function HideAllSubMenus()
{
	for (i=0;i<=(menuCount-1);i++)
	{
		document.getElementById('punkt'+i).className = "deactiveMenu";
		/*
		try
		{
			document.getElementById('punkt'+i).className = "deactiveMenu";
		}
		catch (ex)
		{
		}
		*/
	}
}

// Show a submenu item
function ShowMenu(id)
{	
	HideAllSubMenus();
	
	// Move submenu to its intended position
	var x = findPosX(eval("document.all.top" + id));
	var y = findPosY(eval("document.all.top" + id));
	document.getElementById('punkt'+id).style.top = y+13;
	document.getElementById('punkt'+id).style.left = x;
	
	// Shows submenu
	document.getElementById('punkt'+id).className = "activeMenu"
	
	// Hack der sættes border på dropdown-menuen
	if(document.getElementById('punkt'+id).innerHTML != "") {
      document.getElementById('punkt'+id).style.borderBottom = "1px solid #000000";
      document.getElementById('punkt'+id).style.borderLeft = "1px solid #000000";
      document.getElementById('punkt'+id).style.borderRight = "1px solid #000000";
	}
}

// Hide a single submenu item
function HideMenu(id)
{
	document.getElementById('punkt'+id).className = "deactiveMenu";
	timeout_id = 0;
}

// Set timeout so that the submenu will hide after 500 milliseconds
function InitTimeOut(id)
{
	if ( timeout_id == 0 )
	{
		timeout_id = setTimeout('HideMenu('+id+')',500);
	}
}

// Undo the timeout if the user moves the mouse over the submenu item.
function UndoTimeOut()
{
	clearTimeout(timeout_id);
	timeout_id = 0;
}
