﻿/**
 *  A simple drop down object does nothing more than provide a simple
 *  list of links that form under a header that is provided
 */
function SimpleDropMenu( config )
{
    var self = this;
    var dom = new DomHelper();

    config.menu_element = YAHOO.util.Dom.get( config.main_tab );
    

    config.drop_menu_class = config.drop_class || "sfhover";

    var class_re = new RegExp( config.drop_menu_class + "\\b", "g" );

    /**
     *  This function must be called after the page is loaded and all
     *  the required fields are on the page and can be manipulated.
     */
    this.initialize = function()
    {
        if (!config.menu_element)
        {
            return;
        }
        
        config.menu_items = config.menu_element.getElementsByTagName("li"); 

        for ( var i = 0; i < config.menu_items.length; i++)
        {
            var element = config.menu_items[i];
            dom.setClass( element, "" );

            YAHOO.util.Event.addListener( element, 'mouseover',
                self.mouseover);

            YAHOO.util.Event.addListener( element, 'mouseout',
                self.mouseout);
        }
    }
    /**
     *  For all of the 'li' items found under the main menu element
     *  this function is added as a 'onmouseover' function and so
     *  assigns the style to those 'li' items to include the 
     *  configured drop_menu_class.
     */
    this.mouseover = function()
    {
        dom.setClass( this, config.drop_menu_class );
    };
    /**
     *  This function handles removing the drop_menu_class from
     *  the element's class list where an element could have a number
     *  of classes seperated by spaces.  Based on the css the new
     *  style should return the state of the underlying 'li' elements
     *  be non-visible, ussually by moving them far offscreen.
     */
    this.mouseout = function()
    {
        var className = this.className.replace( class_re, "" );
        dom.setClass( this, "" );
    };
};
/**
 *  The code below adds an event listener to the window to fire when 
 *  the window fnially completely loads.  At which point each of the
 *  independent navigation menus found on the page should will be
 *  processed based entirely on the 'main_tab' property provided here
 *  upon creation of the SimpleDropMenu.
 *
 *  NOTE: If the 'main_tab' property does not point to a valid elemnt
 *  each of the successive menu's will fail to load properly because
 *  the main tab will be undefined causing unhandled errors to
 *  propagate up the call stack of the SimpleDropMenu.
 */
YAHOO.util.Event.addListener(window, 'load',
    function()
    {
        new SimpleDropMenu( { main_tab : "pageNav1" } ).initialize();
        new SimpleDropMenu( { main_tab : "pageNav2" } ).initialize();
        new SimpleDropMenu( { main_tab : "pageNav3" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav4" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav5" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav6" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav7" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav8" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav9" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav10" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav11" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav12" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav13" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav14" } ).initialize();
		new SimpleDropMenu( { main_tab : "pageNav15" } ).initialize();
		});
