var myMenuItem	= 0;
var oldMenuID = 0;
var menuClicks = 0;

function openMenu(id)
{
	myMenuItem = document.getElementById(id);	 	// locate the menu object in the document.
	if ((oldMenuID == id) && (menuClicks == 2))		// If we are on the same menu as a current menu (if there is one), and...
	{ 												// ... if this is our second click on the same menu, just let closeMenu hide the menu.
		oldMenuID = 0;								// Reset the menu id so next time we open a menu we start again
	}
	else
	{
		myMenuItem.style.visibility = 'visible';	// if this is not an existing visible menu make the new menu visible.
		oldMenuID = id;								// make the old id the same as the new menu so we can test on the next mouse click.
		menuClicks = 1;								// Reset our menu mouse clicks for a new menu.
	}
}

function closeMenu()
{	
	if(myMenuItem) myMenuItem.style.visibility = 'hidden';		// Any click in the page window will close the menu if it's visible.
	menuClicks = (menuClicks + 1);								// Count our clicks.
}

document.onclick = closeMenu;

