﻿var bMenuIsDisplayed  = false;
var bMouseIsOverMenu = false;

// This is called anytime the mouse button is pressed. 
// It removes the menu if it is displayed and the click is not within the menu.
function mouseButtonDown(e) 
{
	if( bMenuIsDisplayed && !bMouseIsOverMenu ) 
	{
		bMenuIsDisplayed = false;
		bMouseIsOverMenu = false;
		document.getElementById('menudiv').style.display = "none";
	}
	
	return;
}

// This is called any time the mouse is clicked.
// It displays the popup menu if it isn't displayed.
function displayMenu(e)
{
	e = e || event; // Firefox will get the event through the "e" arg where IE will use the window.event property.

	// Position menu next to the mouse.
	var menuElement = document.getElementById('menudiv');
	menuElement.style.left = (e.clientX+document.body.scrollLeft) + "px";
	menuElement.style.top = (e.clientY+document.body.scrollTop) + "px";

	// Show the menu.
	menuElement.style.display = "";
	bMenuIsDisplayed = true;
	
	return;
}

// Call my mouseButtonDown function anytime the mouse is clicked.
document.onmousedown  = mouseButtonDown;

