var timeout_id = 0; // Set timeout_id to zero when page is loaded.
var menuCount = 4; // 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()
{
	var topMenuCount = 4;
	for (i=1;i<=4;i++)
	{
		document.all['punkt'+i].className = "deactiveMenu";
	}
}

// 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.all['punkt'+id].style.top = y+20;
	document.all['punkt'+id].style.left = x;
	
	// Shows submenu
	document.all['punkt'+id].className = "activeMenu"
}

// Hide a single submenu item
function HideMenu(id)
{
	document.all['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;
}