var lCloseAfter	= 500;
var lCloseID	= 0;
var objMenu;

// Show the required menu option
function OpenMenuOption(vsID)
{	
	// Cancel the close that was going on
	CancelCloseAfterTime();

	// Hide the old menu option
	CloseMenuItem();

	// Show the new menu option
	objMenu = document.getElementById(vsID);
	objMenu.style.visibility = 'visible';

}

// Hides the current menu option
function CloseMenuItem()
{
	if(objMenu) objMenu.style.visibility = 'hidden';
}

// Close the menu option after the required time
function CloseAfterTime()
{
	// Set a timeout
	lCloseID = window.setTimeout(CloseMenuItem, lCloseAfter);
}

// Cancels a close that is about to happen
function CancelCloseAfterTime()
{
	if(lCloseID)
	{
		window.clearTimeout(lCloseID);
		lCloseID = null;
	}
}

// Close when clicks out
document.onclick = CloseMenuItem; 
