var prevMenu = null;
var currMenu = null;
function menuMouseOver(obj)
{
	prevMenu = currMenu;
	currMenu = obj;
	if (prevMenu)
	{
		HideChild(prevMenu);
	}
	ShowChild(currMenu);
}
function menuMouseOut(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if (obj)
	{
	if (event.toElement!=obj && !obj.contains(event.toElement))
	{
		var x1 = getOffsetLeft(menuObj);
		var x2 = x1 + menuObj.offsetWidth;
		if (!(event.offsetX<=x2 && event.offsetX>=x1 && event.offsetY>getOffsetTop(menuObj)))
		{
			HideChild(menuObj);
		}
	}
	}
}
function HideChild(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if (obj)
	{
		obj.style.display = 'none';
		obj.style.zIndex = '0';
	}
}
function getOffsetLeft(obj)
{
  var tmp = 0;
  if (obj != document.body) {
	tmp = getOffsetLeft(obj.offsetParent) + obj.offsetLeft;
  } else {
    tmp = obj.offsetLeft;
  }
  return tmp;
}
function getOffsetTop(obj)
{
  var tmp = 0;
  if (obj != document.body) {
	tmp = getOffsetTop(obj.offsetParent) + obj.offsetTop;
  } else {
    tmp = obj.offsetTop;
  }
  return tmp;
}
function ShowChild(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if (obj)
	{
		obj.style.zIndex = '100';
		obj.style.top = getOffsetTop(menuObj)+menuObj.offsetHeight-1;
		obj.style.left = getOffsetLeft(menuObj)-3;
		obj.style.display = '';
	}
}
function submenuMouseOut(obj)
{
	if (event.toElement!=currMenu && !obj.contains(event.toElement))
	{
		prevMenu = null;
		currMenu = null;
		obj.style.display = 'none';
		obj.style.zIndex = '0';
	}
}
