var submenuHoverTimeout;

Menu = function(sActiveMenu)
{
	ActivateSubMenu(sActiveMenu, true);
}

ActivateSubMenu = function(sActiveMenu, bBlur)
{
	StopBlur();

	if ($("SubMenu" + sActiveMenu) != null && $("SubMenu" + sActiveMenu).className == "Hidden")
	{
		oSubMenus = $("SubMenu").getElementsBySelector("div");
	
		// Hide submenus that are not active
		for (iCnt = 0; iCnt < oSubMenus.length; iCnt++)
		{
			oSubMenus[iCnt].style.left = "0px";
			oSubMenus[iCnt].className = "Hidden";
		}
		
		// Get width of elements required to determine the position of the submenu
		iMenuWidth = $("Menu" + sActiveMenu).getWidth();
		iSubMenuWidth = $("SubMenu" + sActiveMenu).getWidth();
		iDesignWidth = $("bodyWrapper").getWidth();
		
		// Find the space between the browser and the websitedesign
		iWindowLeftSpace = ((document.body.offsetWidth - iDesignWidth) / 2);
		
		if (iSubMenuWidth == 0)
		{
			$("SubMenu" + sActiveMenu).style.width = iMenuWidth + "px";
			iSubMenuWidth = iMenuWidth;
		}
		
		// Get activated menus x position
		iLeft = $("Menu" + sActiveMenu).positionedOffset($("Menu"))[0];
						
		// Add the half of the activated menus width
		iLeft += (iMenuWidth / 2);
			
		// Minus the width of the submenu
		iLeft -= (iSubMenuWidth / 2);
		
		if (iWindowLeftSpace > 0)
			iLeft -= iWindowLeftSpace;
		
		// Make sure the submenu stays inside the design in the left side
		if (iLeft < 0)
			iLeft = 0;
		
		// Make sure the submenu stays inside the design in the right side
		if ((iLeft + iSubMenuWidth) > iDesignWidth)
			iLeft = (iDesignWidth - iSubMenuWidth);
		
		$("SubMenu" + sActiveMenu).style.left = iLeft + "px";
		$("SubMenu" + sActiveMenu).className = "Visible";
		
		ShowSubMenu(sActiveMenu, (bBlur) ? 1 : 100);
	}
}
		
ShowSubMenu = function(sActiveMenu, iOpacity)
{
	$("SubMenu" + sActiveMenu).setOpacity(iOpacity / 100);

	if (iOpacity < 100)
	{
		iOpacity *= 1.7;
		
		if (iOpacity > 100)
			iOpacity = 100;
			
		setTimeout("ShowSubMenu('" + sActiveMenu + "', " + iOpacity + ")", 30);
	}
}

StartBlur = function()
{
	submenuHoverTimeout = setTimeout("ActivateCurrentMenu()", 750);
}

StopBlur = function()
{
	window.clearTimeout(submenuHoverTimeout);
}

ActivateCurrentMenu = function()
{
	Menu(sMenu);
}