/*	Author: Michael Barron (mike@shannonandmike.net)
	Code and ideas from Dave Lindquist (http://www.gazingus.org)
*/
var currentMenu = null;
var currentTimeout = null;

onload="javascript: initializeMenu('productMenu','products');"

document.onclick = function() {
	if (currentMenu != null) {
		currentMenu.style.display = "none";
	}
	return true;
}

function initializeMenu(menuId, actuatorId) {
	if (document.getElementById) {
    	var menu = document.getElementById(menuId);
    	var actuator = document.getElementById(actuatorId);
		if (menu == null || actuator == null) return;

		actuator.onmouseover = function() {
			// Always clear the timeout when we go over the menu!
			if (currentTimeout != null) {
				clearTimeout(currentTimeout);
			}
			
			// If we have already activated this menu then return immediately
			if (currentMenu == actuator) {
				return;
			}
			
        	// If we have a previous menu clear it out
			if (currentMenu) { currentMenu.style.display = "none"; }
			
			// Show the requested menu
        	menu.style.display = "block";
			
			// Set the onmouseout function of the menu to hide itself.
			menu.onmouseover = function() {
				menu.style.display = "block";
				currentMenu = null;
				clearTimeout(currentTimeout);
			}
			menu.onmouseout = function() {
				currentMenu = menu;
				setTimeout(clearMenu, 2000);
			}
    	}
	}
}

function clearMenu() {
	if (currentMenu != null) {
		currentMenu.style.display = "none";
		currentMenu = null;
	}
}

function toggleMenu(menuId) {
	if (currentMenu != null) {
		currentMenu.style.display = "none";
	}
	else if (document.getElementById) {	
		var menu = document.getElementById(menuId);
		menu.style.display = "block";
		currentMenu = null;
	}
}

function menu_init() {
	initializeMenu('productMenu','products');	
}

if (document.getElementById && document.createElement) {
    addEvent(window, 'load', menu_init);
}
