/**
 * JavaScript for SAINT 7.0 drop down menus
 *
 * @author Brian Stull
 * @version 3/19/09
 */

// They have 2 seconds to mouse over a drop down before it dissappears
var drop_down_timeout_value = 1000;
// The current active drop down menu
var current_drop_down_menu = "";
// The timer ID for the current drop down menu
var current_drop_down_timeout_id = 0;
// The timer ID for rescuing a menu after rolling off of an <a> element
var current_drop_down_rescue_timeout_id = 0;
// Menu saved from closing after rolling over a link?
var rescued = false;
// Menu was just saved from rolling off of a link?
var just_rescued = false;
// Are we leaving a drop down menu?
var leaving_drop_menu = false;
// Argument to be passed to wait function.
var wait_arg = "";

/**
 * Called when a user mouses over an icon containing a drop down menu.
 * Displays the specified drop down menu.
 *
 * @param menuID the menu to show.
 */
function showDropDown(menuID)
{
	if (menuID != null && menuID != "") 
	{
		// If there is an active menu
		if (current_drop_down_timeout_id > 0)
		{
			// Clear the timer and hide the current menu.
			// This avoids more than 1 menu being displayed at a time
			clearTimeout(current_drop_down_timeout_id);
			document.getElementById(current_drop_down_menu).style.display = 'none';
			current_drop_down_timeout_id = 0;
		}
		else if (leaving_drop_menu) // Make sure it gets set to none before
									// being set to block
		{
			wait_arg = menuID;
			if (current_drop_down_menu != null && current_drop_down_menu != "")
				document.getElementById(current_drop_down_menu).style.display = 'none';
			setTimeout('wait()',50);
			return true; // rest is taken care of in wait() function.
		}

		// Now display the new menu
		document.getElementById(menuID).style.display = 'block';
		current_drop_down_menu = menuID;
	}
}

/**
 * Display a new menu after getting rid of an old one.
 * 
 * helper method to showDropDown()
 */
function wait()
{
	document.getElementById(wait_arg).style.display = 'block';
	current_drop_down_menu = wait_arg;
	wait_arg = "";
}

/**
 * Called onMouseOut event.
 * Sets a timer to get rid of the drop down menu if the users mouse
 * is not located over the menu before 'drop_down_timeout_value' is up.
 *
 * @param menuID the icon left to cause a menu to fire.
 */
function hideDropDown(menuID)
{
	if (menuID != null && menuID != "")
		current_drop_down_timeout_id = setTimeout('expireDropDown()', 
													drop_down_timeout_value);
}

/**
 * Fires 2 seconds after hideDropDown is called unless the timer is cleared
 * by a user mousing over the drop down menu.
 */
function expireDropDown()
{
	if (current_drop_down_menu != null && current_drop_down_menu != "")
		document.getElementById(current_drop_down_menu).style.display = 'none';
	current_drop_down_timeout_id = 0;
	current_drop_down_menu = "";
}

/**
 * Called when a user mouses over a drop down menu, cancels
 * expireDropDown() so it will not fire.
 */
function overDropDown()
{
	if (current_drop_down_timeout_id > 0)
	{
		clearTimeout(current_drop_down_timeout_id);
		current_drop_down_timeout_id = 0;
	}
}

/**
 * Called when a user mouses out of a drop down menu that is active.
 */
function outDropDown()
{
	leaving_drop_menu = true;
	if (!just_rescued)
		current_drop_down_rescue_timeout_id = setTimeout('reallyClearDropMenu()', 5);
	else
		just_rescued = false;
}

/**
 * Gets rid of a drop down menu if it hasn't been moused over again after
 * having rolled over on after a link.
 *
 * helper method to outDropDown()
 */
function reallyClearDropMenu()
{
	if (!rescued)
	{
		if (current_drop_down_menu != null && current_drop_down_menu != "")
			document.getElementById(current_drop_down_menu).style.display = 'none';
		leaving_drop_menu = false;
	}
	else
	{
		just_rescued = true;
		rescued = false;
	}
}

/**
 * Called on mouse over link.
 * This is necessary because when you roll over a link within a div it thinks
 * you are leaving the div tag. (also calls leaving div tag again when you
 * roll back onto the div from the link... its dumb.)
 *
 */
function rescueDropDown()
{
	rescued = true;
}


