

var MENU_HIDE_DELAY = 500;

var _menutimer = null;
var _openmenu = null;
var macAdditionalPopupOffset = 5;


function showMenu (objButton)
{
	var menu = document.getElementById(objButton.getAttribute('menuid'));	
	
	if (_openmenu != null)
	{
		_openmenu.style.visibility = 'hidden';
	}
	
	if (menu == null)
	{
		return;
	}
	else
	{
		clearMenuHideTimer();
	
		positionObjectBelowItem (menu, objButton);
	
		menu.style.visibility = 'visible';
		_openmenu = menu;
	}

}

function setMenuHideTimer ()
{
	_menutimer = setTimeout('hideCurrentMenu()', MENU_HIDE_DELAY);
}

function clearMenuHideTimer ()
{
	if (_menutimer != null)
	{
		clearTimeout (_menutimer);
		_menutimer = null;
	}
}


function positionObjectBelowItem (objToPosition, objReference)
{
	
	var x = objReference.offsetLeft;
	var y = objReference.offsetTop + objReference.offsetHeight;
	
	if (isMac) {
		// for mac browsers, we need to add the padding to the elements
		y += macAdditionalPopupOffset;
	}

	var tmp = objReference.offsetParent;
	while (tmp != null)
	{
		x += tmp.offsetLeft;
		y += tmp.offsetTop;		
		tmp = tmp.offsetParent;
	}
	
	objToPosition.style.left = x;
	objToPosition.style.top = y;
	
}

function hideCurrentMenu ()
{
	if (_openmenu != null)
	{
		_openmenu.style.visibility = 'hidden';
		_openmenu = null;
	}	
}