var activeMenuId = null;
var timerOn = false;
var timerID = null;
function startTimer() {
	timerID = setTimeout('hide()',300);
	timerOn = true;
}

function stopTimer() {
	if (timerOn) {
		clearTimeout(timerID);
		timerOn = false;
	}
}

function showMenu(menuId) {
	stopTimer();
	if (activeMenuId && (activeMenuId != menuId)) {
		hide();
	} 
	activeMenuId = menuId;
    menuElem = document.getElementById(menuId);
	if (menuElem) {
        xPos = findPosX(document.getElementById('a' + menuId)) - 0;
        menuElem.style.left = xPos + 'px';
        menuElem.style.visibility = 'visible';
	}
}			

function closeMenu(menuId) {
	if (menuId == activeMenuId) {
		startTimer();
	}
}

function hide() {
    menuElem = document.getElementById(activeMenuId);
	if (menuElem) {
		menuElem.style.visibility = 'hidden';	
		timerOn = false;
    	activeMenuId = null;
	}
}

function findPosX(obj) {
    // Taken from http://www.quirksmode.org
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}