var topX, topY, bottomX, bottomY, subMenu;

function InitMenu()
{
	var submenus = document.getElementsByTagName("*");
	for (i = 0; i < submenus.length; i++)
		if (submenus[i].id.substring(0, 8) == 'submenu_')
			PlaceMenu(submenus[i].id.substring(3));
}

function PlaceMenu(id)
{
	// Position the menu correctly...
	var parentMenu = document.getElementById(id);
	var subMenu = document.getElementById('sub' + id);
	if (parentMenu && subMenu)
	{
		subMenu.style.left = FindPosX(parentMenu) + 'px';
		subMenu.style.top = FindPosY(parentMenu) + FindHeight(parentMenu) + 'px';
	}
}

function SubMenu(elm)
{
	PlaceMenu(elm.id);
	subMenu = document.getElementById('sub' + elm.id);
	if (subMenu)
	{
		subMenu.style.visibility = "visible";
		topX = FindPosX(elm);
		topY = FindPosY(elm);
		bottomX = FindPosX(subMenu) + FindWidth(subMenu);
		bottomY = FindPosY(subMenu) + FindHeight(subMenu);

		document.onmousemove = function(e) {
			var x, y;
			if (ie)
			{
				x = event.clientX + document.body.scrollLeft;
				y = event.clientY + document.body.scrollTop;
			}
			else
			{
				x = e.pageX;
				y = e.pageY;
			}

			if (x < topX || x > bottomX || y < topY || y > bottomY)
			{
				subMenu.style.visibility = "hidden";
				document.onmousemove = null;
			}
		}
	}
}

function Hover(elm)
{
	elm.className += " " + elm.className + "_hover";
}

function MouseOut(elm)
{
	var classes = elm.className.split(" ");
	classes.pop();
	elm.className = classes.join(" ");
}
