/*--- ------------------------------------------------------------------------- ----
	
	File:		drop_down_menu.js
	Author:		Ben Nadel
	Desc:		This handles the drop down menu system.
				
	Sample Code:
		
				N/A
				
	Update History:
	
				04/19/2006 - Ben Nadel
				Built the first run of the page.
	
----- --------------------------------------------------------------------//// ---*/

// This is the class for drop down menus.
function DropDownMenuSystem(){
	// Holds the collection of menus.
	this.Menus = new Object();
	
	// Holds the interval pointer used when hiding menus.
	this.HideInterval = null;
}


// This shows the menu when the root link has been moused over. This
// method needs to be called first to initialize this menu and root
// button combination.
DropDownMenuSystem.prototype.ShowByRoot = function ( objLink, strMenuID ){
	var objSelf = this;
		
	// Clear the interval if needbe.
	clearTimeout( this.HideInterval );
	
	// Check to see if the menu is already in the system.
	if (this.Menus[ strMenuID ] == null){
		
		// Add the menu to the system.
		this.Menus[ strMenuID ] = new Object();
		this.Menus[ strMenuID ].Root = objLink;
		this.Menus[ strMenuID ].Image = objLink.childNodes[0];
		this.Menus[ strMenuID ].ImageName = objLink.childNodes[0].name;
		this.Menus[ strMenuID ].ID = strMenuID;
		this.Menus[ strMenuID ].Menu = document.getElementById( strMenuID );
		
		// Set up the menu mouse actions.
		this.Menus[ strMenuID ].Menu.onmouseover = function(){ objSelf.Show(this); };
		this.Menus[ strMenuID ].Menu.onmouseout = function(){ objSelf.Hide(); };
		
	}
	
	// Hide all menus except this one.
	this.Hide( strMenuID );
	
	// Show the menu.
	this.Menus[ strMenuID ].Menu.style.display = "block";
}


// This shows the menu when the menu itself is moused over.
DropDownMenuSystem.prototype.Show = function ( objMenu ){
	var strMenuID = objMenu.getAttribute("id");
		
	// Clear the interval if needbe.
	clearTimeout( this.HideInterval );
	
	// Hide the flash movie.
	// document.getElementById( "page_title_flash" ).style.visibility = "hidden";
	
	// Show the menu.
	this.Menus[ strMenuID ].Menu.style.display = "block";
	
	// Call the mouse over on the root element.
	//this.Menus[ strMenuID ].Root.onmouseover();
}


// This is called when the menu is "asked" to be closed. We will then set
// a timer to close it when we need to.
DropDownMenuSystem.prototype.RequestHide = function(){
	var objSelf = this;
	
	// Set the interval for the hide check.
	this.HideInterval = setTimeout(
		function(){ objSelf.Hide(); },
		500
		);
}


// This actually commits the hiding by closing all the menus. It will close all 
// menus unless it is passed an "exception" id, which will not be closed.
DropDownMenuSystem.prototype.Hide = function( strMenuID ){
	// Clear the interval.
	clearTimeout( this.HideInterval );
			
	// Close all menus.
	for (var strKey in this.Menus){
	
		// Check to see if we have a passed menu ID.
		if (!strMenuID || (strKey != strMenuID)){
			this.Menus[ strKey ].Menu.style.display = "none";	
		}
		
	}
	
	// Show the flash movie.
	// document.getElementById( "page_title_flash" ).style.visibility = "visible";
}


// Create a drop down menu system instance.
var objMenuSystem = new DropDownMenuSystem();
