/**
 * This is how long we will wait after mouse out
 * to hide the menu.  Default: 500ms
 */
var timeout = 500;

/**
 * This is how long the transition from displayed
 * to hidden takes.  Default: 0.1s
 */
var speed = 0.1;

/**
 * This is a reference to the current timer.
 */
var timer = null;

/**
 * This is a reference to the current menu.
 */
var currentMenu = null;

/**
 * Display the requested menu.
 */
function showMenu(menu) {
	
	// Cancel the existing hide timer.
	if (timer != null) {
		window.clearTimeout(timer);
		timer = null;
	}
	
	// Hide the currently displayed menu if one exists.
	if (currentMenu != null && currentMenu.id != menu && currentMenu.visible()) {
		Effect.SlideUp(currentMenu.id, {duration: speed});
	}
	
	// Display the requested menu unless it is already visible.
	currentMenu = $(menu);
	if (!currentMenu.visible()) Effect.SlideDown(currentMenu.id, {duration: speed});
}

/**
 * Hide the currently displayed menu.
 */
function hideMenu() {
	
	// Create a timer to hide the currently displayed menu.
	timer = window.setTimeout(function() {
		
		// Hide the currently displayed menu if it is visible.
		if (currentMenu != null && currentMenu.visible()) {
			Effect.SlideUp(currentMenu.id, {duration: speed});
			currentMenu = null;
		}
	}, timeout);
}

