/**
 * NavigationManager.js
 * Tom McFarlin / October 2007
 *
 * This class is responsible for handling events for the navigation system
 * for DavidLeinweber.com
 */
 
var NavigationManager = Class.create();
NavigationManager.prototype = {
	
	/*-----------------------------------------------------
	 * constructors
	 */
	
	/**
	 * Initializes this manager by settings up event handlers for
	 * each of the navigation menu items .
	 */
	initialize: function()
	{
		// setup the list of main navigation options	
		this.navigationMenu = this._getNavigationOptions();
		
		// setup event listeners for each option
		this._attachEventHandlers(this.navigationMenu);
		
		// a reference to this active menu
		this.activeMenu = null;
		
	}, // end initialize
	
	/*-----------------------------------------------------
	 * private functions
	 */
	
	/**
	 * Returns an array of each individual navigation menu
	 * elements.
	 */
	_getNavigationOptions: function() {
		return $A($('navigation-main').getElementsByTagName("li"));
	}, // end _getNavigationOptions
	
	/**
	 * Attaches event handlers to each of the options in the specified
	 * options collection.
	 * 
	 * Note: Each option must be identified by the name of its parent option
	 *       followed by an "-options" string.
	 */
	_attachEventHandlers: function(options) {
		
		var optionsStr = "";
		var This = this;

		// attaches a mouse over event to each option
		options.each(function(option) {
			
			// mouse over
			Event.observe(option, 'mouseover', function(e) {
				
				// build the option menu based on the current option
				var currentOptionMenuID = option.id + "-options";
				
				// hide the currently active menu (if it isn't null)
				if($(This.activeMenu) != null) {
					
					$(This.activeMenu).setStyle({
						display: "none"
					});
					
				} // end if
				
				// show the new menu
				$(currentOptionMenuID).setStyle({
					display: "block"
				});
				
				// update the active menu
				This.activeMenu = $(currentOptionMenuID);
				
			}); // end Event.observe
			
		}); // end options iterator
		
	} // end _attachEventHanders
	
} // end class
