﻿//ENUM/Struct
var positionType = {None:0, Left:1, Center:2, Right:3};
var hoverOverride = {None:0, ForceHover:1, ForceRegular:2, ForceSelect:3};

//For debug purposes...
var htmlGenerated = '';

var keepSelected = false;

var menuItemsArr = new Array();

var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

//BEGIN MENU ITEM OBJECT
//DESCRIPTION: A menu item that appears in the menu. It performs a simple hover effect and redirect.
var MenuItem = function(name, href, text, mname) {
    //Class variables / properties
    this.name = name;
    this.href = href;
    this.text = text;
    this.selected = false;
    this.index = 0;
    this.position = positionType.None;
    this.regClassName = '';
    this.hoverClassName = '';
    this.selectClassName = '';
    this.mname = mname;
    //this.width = 1;

    this.objectType = 'MenuItem';

    MenuItem.prototype.render = function(delay,width) {
        //Renders the HTML for an item that appears in the menu
        var item = '';
        item += '<td class="';
        //Chooses a class based on whether the item is selected or not
        if (this.selected)
            item += this.selectClassName;
        else
            item += this.regClassName;
        item += '" onmouseover="Menu.delayToggle(this, ';
        item += this.selected;
        item += ', ';
        item += this.position;
        item += ', hoverOverride.ForceHover, '
        item += delay;
        item += ', ';
        item += '\'' + this.mname + '\'';
        item += ');" onmouseout="Menu.delayToggle(this, ';
        item += this.selected;
        item += ', ';
        item += this.position;
        item += ', hoverOverride.None, '
        item += delay;
        item += ', ';
        item += '\'' + this.mname + '\'';
        item += ');Menu.checkDropMenu(\''
        item += this.mname;
        item += '\');" onclick="Menu.redirect(\'';
        item += this.href;
        item += '\');" id="';
        item += this.name;
        //item += '"><a href="'; 
        item += '" width="' + width.toString() + '%"><a href="';
        item += this.href;
        item += '" style="padding:9px 10px 9px 10px;">';
        item += this.text;
        item += '</a></td>';

        //Write the HTML to the browser
        document.writeln(item);
        htmlGenerated += item;
    }
}

//END MENU ITEM OBJECT

//BEGIN MENU DROP OBJECT

//MenuDrop inherits from MenuItem
MenuDrop.prototype = new MenuItem;
MenuDrop.prototype.constructor = MenuDrop;
//DESCRIPTION: A menu item that not only offers a hover effect and redirect, but also provides a drop down menu with further selections.
//              Can contain multiple MenuDropItem objects.
function MenuDrop(name, href, text, mname)
{
    //Create an array that will contain the drop down's links
    var dropItems = new Array();
    
    //Must call the base classes constructor, pass it "this" and then the required variables
    MenuItem.prototype.constructor.call(this, name, href, text, mname);
    
    this.objectType = 'MenuDrop';
    //Allows for an override to the left positioning.  When "-1" it automatically positions menu item.
    this.left = -1;
    
    this.add = function(item) {
        //Set the index of the MenuDropItem to the current length (first item would have an index of 0)
        item.index = dropItems.length;
        //Push the item onto the array
        dropItems.push(item);
    }
    
    this.setSubItemSelection = function(menuItem) {
        for( var i = 0; i < dropItems.length; i++ ) {
            if( dropItems[i].name == menuItem.name ) {
                dropItems[i].selected = true;
                this.selected = true;
                return true;
                break;
            }
        }
        
        return false;
    }
    
    this.setSubItemSelectionName = function(subItemName) {
        for( var i = 0; i < dropItems.length; i++ ) {
            if( dropItems[i].name == subItemName ) {
                dropItems[i].selected = true;
                this.selected = true;
                return true;
                break;
            }
        }
        
        return false;
    }
    
    this.render = function(delay) {
        //Renders the HTML for an item that appears in the menu
        var item = '';
        item += '<td class="';
        //Chooses a class based on whether the item is selected or not
        if( this.selected )
            item += this.selectClassName;
        else
            item += this.regClassName;
        item += '" onmouseover="Menu.delayToggle(this, ';
        item += this.selected;
        item += ', '
        item += this.position;
        item += ', hoverOverride.ForceHover, '
        item += delay;
        item += ', '
        item += '\'' + this.mname + '\'';
        //An extra function call is added to display the drop down menu
        item += '); Menu.delayMenuShow(document.getElementById(\'md';
        item += this.name;
        item += '\'), ';
        item += delay;
        item += ', '
        item += '\'' + this.mname + '\'';
        item += ');" onmouseout="Menu.delayToggle(this, ';
        item += this.selected;
        item += ', '
        item += this.position;
        item += ', hoverOverride.None, '
        item += delay;
        item += ', '
        item += '\'' + this.mname + '\'';
        item += '); Menu.delayMenuHide(document.getElementById(\'md';
        item += this.name;
        item += '\'), ';
        item += delay;
        item += ', '
        item += '\'' + this.mname + '\'';
        item += ');" onclick="Menu.redirect(\'';
        item += this.href;
        item += '\');" id="';
        item += this.name;
        item += '"><a href="'; 
        item += this.href;
        item += '" style="padding:9px 10px 9px 10px;">';
        item += this.text;
        item += '</a></td>';
        
        //Write HTML to browser
        document.writeln(item);
        htmlGenerated += item;
    }
    
    //When called it renders all MenuDropItems (drop down links)
    this.renderDropItems = function(linkClassName, selectedLinkClassName) {
        //Loop through each added link
        for( i = 0; i < dropItems.length; i++ ) {
            //Set the class for links, passed by the Menu object
            dropItems[i].className = linkClassName;
            dropItems[i].selectedClassName = selectedLinkClassName;
            //Render the HTML
            dropItems[i].render();
        }
    }
    
    this.hasSubItemSelected = function() {
        var itemSelected = false;
        for( var i = 0; i < dropItems.length; i++ ) {
            if( dropItems[i].selected ) {
                itemSelected = true;
                break;
            }
        }
        
        itemSelected = this.selected;
                
        return itemSelected;
    }
}

//END MENU DROP OBJECT

//BEGIN MENU DROP ITEM
//DESCRIPTION: Displays a regular link within a menu drop down. Can be added to a MenuDrop object.
function MenuDropItem(name, href, text)
{
    //class variables / properties
    this.index = 0;
    this.href = href;
    this.name = name;
    this.text = text;
    this.target = '_self';
    this.className = '';
    this.selectedClassName = '';
    this.selected = false;
    
    this.render = function() {
        //Renders HTML for link
        dropItem = '<a href="';
        dropItem += this.href;
        dropItem += '" target="';
        dropItem += this.target;
        dropItem += '" class="';
        if( this.selected )
            dropItem += this.selectedClassName;
        else
            dropItem += this.className;
        dropItem += '">';
        dropItem += this.text;
        dropItem += '</a>&nbsp;&nbsp;';
        
        //Write HTML to browser
        document.writeln(dropItem);
        htmlGenerated += dropItem;
    }
}

//END MENU DROP ITEM

//BEGIN MENU OBJECT
//DESCRIPTION: This is the main menu bar. MenuItems are added to it. All calls to render and set up menu should be made to this object.
var Menu = function() {
    //Private variables
    //An array that will contain all of the MenuItems
    var items = new Array();
    //A variable to hold the currently selected MenuItem in the menu
    var selectedItem = new MenuItem('', '', '');
    var hasDropMenu = false;
    //A value to keep track of timers
    var t = null;
    var hoverActive = false;
    var dropMenuItemSelected = false;

    var hasDropHang = false;

    //Properties for setting classes for menu
    this.menuName = '';
    this.menuClassName = '';
    this.centerClassName = '';

    //Properties to hold the class names used for the left and right ends of the menu (not the left and right menu items)
    this.leftSideClassName = '';
    this.rightSideClassName = '';
    this.leftSideHoverClassName = '';
    this.rightSideHoverClassName = '';
    this.leftSideSelectClassName = '';
    this.rightSideSelectClassName = '';

    //Properties to hold the class names for center menu items
    this.regItemClassName = '';
    this.hoverItemClassName = '';
    this.selectItemClassName = '';

    //Properties to hold class names for the left most menu item
    this.regItemLeftClassName = '';
    this.hoverItemLeftClassName = '';
    this.selectItemLeftClassName = '';

    //Properties to hold class names for the right most menu item
    this.regItemRightClassName = '';
    this.hoverItemRightClassName = '';
    this.selectItemRightClassName = '';

    //Properties to hold class names for the drop down menu and its links
    this.dropNavMainClassName = '';
    this.dropSubMenuClassName = '';
    this.dropSubMenuLinkClassName = '';
    this.dropSubMenuLinkSelectedClassName = '';
    this.dropHangClassName = '';

    //Holds the delay value for menu effects.  In milliseconds.
    this.hoverDelay = 0;

    //When set to true a pop-up opens displaying the generated HTML
    this.debug = false;

    this.add = function(item) {
        //Add menu items to menu.
        //Menu items are added left to right. Menu items cannot be inserted.
        //Set the index to the current array length (the first item would have an index of 0)
        item.index = items.length;
        //Configure the positioning of the menu item
        switch (item.index) {
            case 0:
                //The first menu item added will be configured as the left most menu item
                item.regClassName = this.regItemLeftClassName;
                item.hoverClassName = this.hoverItemLeftClassName;
                item.selectClassName = this.selectItemLeftClassName;
                //Indicate the menu item's position is left
                item.position = positionType.Left;
                break;
            case 1:
                //The second menu item added will be configured as the right most menu item
                item.regClassName = this.regItemRightClassName;
                item.hoverClassName = this.hoverItemRightClassName;
                item.selectClassName = this.selectItemRightClassName;
                //Indicate the menu items positiong is right
                item.position = positionType.Right;
                break;
            default:
                //All menu items added after the second will be configured as the right most menu item.
                //First, the previously added menu item, which was marked as the right most, must now be configured as a center menu item
                items[items.length - 1].regClassName = this.regItemClassName;
                items[items.length - 1].hoverClassName = this.hoverItemClassName;
                items[items.length - 1].selectClassName = this.selectItemClassName;
                //Indicate the last added menu item's positioning is center
                items[items.length - 1].position = positionType.Center;
                //Configure the newly added menu item as the right most menu item
                item.regClassName = this.regItemRightClassName;
                item.hoverClassName = this.hoverItemRightClassName;
                item.selectClassName = this.selectItemRightClassName;
                //Indicate the newly added menu item's position is right
                item.position = positionType.Right;
        }

        //The menu object sets a flag if the menu item being added is actually a MenuDrop object.
        if (item.objectType == 'MenuDrop')
            this.hasDropMenu = true;

        //Add the item to the array of menu items.
        items.push(item);
    }

    this.hasSelectedSubItem = function() {
        var selectedItem = false;

        for (var i = 0; i < items.length; i++) {
            if (items[i].objectType == 'MenuDrop') {
                if (items[i].hasSubItemSelected()) {
                    selectedItem = true;
                    break;
                }
            }
        }

        return selectedItem;
    }

    this.setSelection = function(menuItem) {
        //Set the selected menu item by passing in the object
        for (var i = 0; i < items.length; i++) {
            //Loops through each item and compares the name
            if (items[i].name == menuItem.name) {
                items[i].selected = true;
                selectedItem = items[i];
            }
            else
                items[i].selected = false;
        }
    }

    this.setSelectionIndex = function(index) {
        //Set the selected menu item by indicating the index
        for (var i = 0; i < items.length; i++) {
            //Loop through and deselect each item
            items[i].selected = false;
        }

        //Set selected item based on the index
        items[index].selected = true;
        selectedItem = items[index];
    }

    this.setSubItemSelection = function(menuSubItem) {
        for (var i = 0; i < items.length; i++) {
            if (items[i].objectType == 'MenuDrop') {
                if (items[i].setSubItemSelection(menuSubItem))
                    selectedItem = items[i];
            }
        }
    }

    this.setSubItemSelectionName = function(subItemName) {
        for (var i = 0; i < items.length; i++) {
            if (items[i].objectType == 'MenuDrop') {
                if (items[i].setSubItemSelectionName(subItemName))
                    selectedItem = items[i];
            }
        }
    }

    this.render = function() {
        //Render the menu and all of its children
        var selectedDropDown = '';
        var itemWidth = 0;

        hasDropHang = (this.dropHangClassName != '');

        if (!this.hasDropMenu) {
            itemWidth = Math.round(100 / items.length);
        }

        htmlGenerated = '';
        //Begin building HTML for menu
        menuStart = '<div class="';
        menuStart += this.menuClassName;
        menuStart += '" id="' + this.menuName + 'DivNavMenuMain"><div id="' + this.menuName + 'DivLeftSide" class="';
        if (selectedItem.position == positionType.Left)
            menuStart += this.leftSideSelectClassName;
        else
            menuStart += this.leftSideClassName;
        menuStart += '">&#32;</div><div class="';
        menuStart += this.centerClassName;
        menuStart += '"><div><table><tr>';

        //Write HTML
        document.writeln(menuStart);
        htmlGenerated += menuStart;

        //Loop through each menu item and render it
        for (i = 0; i < items.length; i++) {
            items[i].render(this.hoverDelay,itemWidth);
            //As it loops through each item it checks to see if a MenuDrop has been selected
            if (!dropMenuItemSelected)
                dropMenuItemSelected = (items[i].selected && items[i].objectType == 'MenuDrop');
        }

        //Continue building menu
        menuEnd = '</tr></table></div></div><div id="' + this.menuName + 'DivRightSide" class="';
        if (selectedItem.position == positionType.Right)
            menuEnd += this.rightSideSelectClassName;
        else
            menuEnd += this.rightSideClassName;
        menuEnd += '">&#32;</div></div>';

        //Write HTML
        document.writeln(menuEnd);
        htmlGenerated += menuEnd;

        //If a there is a DropMenu item the drop menu must be rendered. Otherwise this section is skipped.
        if (this.hasDropMenu) {
            if (!dropMenuItemSelected)
                dropMenuItemSelected = this.hasSelectedSubItem();

            if (hasDropHang) {
                dropHang = '<div id="' + this.menuName + 'DropHang" name="' + this.menuName + 'DropHang" class="';
                dropHang += this.dropHangClassName;
                dropHang += '" style="';
                if (dropMenuItemSelected)
                    dropHang += 'display:none; ';
                dropHang += 'position:relative;"></div>';
                document.writeln(dropHang);
                dropHang += dropHang;
            }

            //Begin building drop menu
            dropDownMenu = '<div class="';
            dropDownMenu += this.dropNavMainClassName;
            dropDownMenu += '" id="' + this.menuName + 'DivDropDown" name="' + this.menuName + 'DivDropDown" style="';
            //If there currently isn't a drop menu selected, hide it. Otherwise, show it
            if (!dropMenuItemSelected && !isIE6)
                dropDownMenu += 'display:none; ';
            dropDownMenu += 'position:relative;" onmouseover="Menu.holdDropMenu(\'' + this.menuName + '\');" onmouseout="Menu.releaseDropMenu(\'' + this.menuName + '\');">';

            //Write beginning of drop down
            document.writeln(dropDownMenu);
            htmlGenerated += dropDownMenu;

            //For each MenuDrop render it's children links into the drop menu
            for (x = 0; x < items.length; x++) {
                if (items[x].objectType == 'MenuDrop') {

                    itemPos = 0;

                    //If .left hasn't been set, automatically position items under menu item
                    if (items[x].left < 0) {
                        //Get the current hovered menu item
                        curTD = document.getElementById(items[x].name);
                        //Set positiong
                        itemPos = curTD.offsetLeft
                    }
                    else {
                        //User has manually set position
                        itemPos = items[x].left;
                    }
                    menuItemsArr.push(items[x].name);

                    dropDownMenu = '<div id="md';
                    dropDownMenu += items[x].name;
                    dropDownMenu += '" class="';
                    dropDownMenu += this.dropSubMenuClassName;
                    dropDownMenu += '" name="md';
                    dropDownMenu += items[x].name;
                    dropDownMenu += '" onmouseover="Menu.holdDropMenu(\'' + this.menuName + '\');" onmouseout="Menu.holdDropMenu(\'' + this.menuName + '\');" style="';
                    //If the parent menu item hasn't been selected, hide the links
                    if (!items[x].selected)
                        dropDownMenu += 'display:none; ';
                    else {
                        //Indicate the selected menu item
                        selectedDropDown = 'md' + items[x].name;
                    }
                    //dropDownMenu += 'position:relative; left:';
                    dropDownMenu += 'position:absolute; left:';
                    dropDownMenu += itemPos;
                    dropDownMenu += 'px">';

                    //Write HTML
                    document.writeln(dropDownMenu);
                    htmlGenerated += dropDownMenu;

                    //Render all of the links for the menu item
                    items[x].renderDropItems(this.dropSubMenuLinkClassName, this.dropSubMenuLinkSelectedClassName);

                    //Close tags and write HTML
                    endTags = '</div>';
                    document.writeln(endTags);
                    htmlGenerated += endTags;
                }
            }

            //Create a span to store the currently selected drop item
            endTags = '</div><span id="' + this.menuName + 'SpanCurrentDropItem"></span>';
            document.writeln(endTags);
            htmlGenerated += endTags;
            document.getElementById('' + this.menuName + 'SpanCurrentDropItem').value = '';

        }

        //Span tags will be used to store various values for the menu to be called upon during runtime
        endTags = '<span id="' + this.menuName + 'SpanLeftSide" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanRightSide" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanMenuItem" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanMenuLeftItem" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanMenuRightItem" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanCurrentMenuItem" style="width:0px;display:none;"></span><span id="' + this.menuName + 'SpanMenuSettings" style="width:0px;display:none;"></span>';
        document.writeln(endTags);
        htmlGenerated += endTags;

        //Assign span tags to variables for easy call
        var nmSpanLeftSide = document.getElementById('' + this.menuName + 'SpanLeftSide');
        var nmSpanRightSide = document.getElementById('' + this.menuName + 'SpanRightSide');
        var nmSpanMenuItem = document.getElementById('' + this.menuName + 'SpanMenuItem');
        var nmSpanMenuLeftItem = document.getElementById('' + this.menuName + 'SpanMenuLeftItem');
        var nmSpanMenuRightItem = document.getElementById('' + this.menuName + 'SpanMenuRightItem');
        var nmSpanCurrentMenuItem = document.getElementById('' + this.menuName + 'SpanCurrentMenuItem');
        var nmSpanMenuSettings = document.getElementById('' + this.menuName + 'SpanMenuSettings');

        //Set class names for each of the menu item types
        nmSpanLeftSide.reg = this.leftSideClassName;
        nmSpanLeftSide.hover = this.leftSideHoverClassName;
        nmSpanLeftSide.select = this.leftSideSelectClassName;
        nmSpanRightSide.reg = this.rightSideClassName;
        nmSpanRightSide.hover = this.rightSideHoverClassName;
        nmSpanRightSide.select = this.rightSideSelectClassName;
        nmSpanMenuItem.reg = this.regItemClassName;
        nmSpanMenuItem.hover = this.hoverItemClassName;
        nmSpanMenuItem.select = this.selectItemClassName;
        nmSpanMenuLeftItem.reg = this.regItemLeftClassName;
        nmSpanMenuLeftItem.hover = this.hoverItemLeftClassName;
        nmSpanMenuLeftItem.select = this.selectItemLeftClassName;
        nmSpanMenuRightItem.reg = this.regItemRightClassName;
        nmSpanMenuRightItem.hover = this.hoverItemRightClassName;
        nmSpanMenuRightItem.select = this.selectItemRightClassName;

        nmSpanCurrentMenuItem.name = '';
        nmSpanCurrentMenuItem.selected = false;
        nmSpanCurrentMenuItem.position = positionType.None;

        //Set menu settings for calls during runtime
        nmSpanMenuSettings.delay = this.hoverDelay;
        nmSpanMenuSettings.selectedDropDownName = selectedDropDown;
        nmSpanMenuSettings.dropMenuItemSelected = dropMenuItemSelected;
        nmSpanMenuSettings.hasDropHang = hasDropHang;

        if (isIE6 && !dropMenuItemSelected) {
            dropDownDiv = document.getElementById(this.menuName + 'DivDropDown');
            if (document.getElementById(this.menuName + 'DivDropDown'))
                setTimeout(function() { dropDownDiv.style.display = 'none'; }, 2000);
        }

        //Only call when in debug mode
        if (this.debug) {
            //Open pop-up that displays generated HTML.
            newWindow = window.open('', 'debugWin', 'height=550,width=700,toolbar=no,scrollbars=no,menubar=no');
            newWindow.document.writeln('<HTML><Head><Title>DEBUG MODE ON: Generated Menu HTML</Title></Head><Body><B>Textbox contains HTML generated by Menu object:</B><BR><TEXTAREA readonly cols="80%" rows="10">');
            newWindow.document.writeln(htmlGenerated);
            newWindow.document.writeln('</TEXTAREA><BR>Debug mode is "on"<BR>To turn off set "Menu.debug=false"</Body></HTML>');
        }
    }

    //Perform a delayed toggle
    Menu.delayToggle = function(td, selected, pos, override, delay, mname) {
        if (!selected)
            setTimeout(function() { Menu.performToggle(td, selected, pos, override, mname) }, delay);
        else {
            document.getElementById('' + mname + 'SpanCurrentMenuItem').name = td.id;
            document.getElementById('' + mname + 'SpanCurrentMenuItem').selected = selected;
            document.getElementById('' + mname + 'SpanCurrentMenuItem').position = pos;
        }
    }

    //Perform an immediate toggle when called
    Menu.performToggle = function(td, selected, pos, override, mname) {
        //Only perform if not selected
        if (!keepSelected && !selected) {
            switch (pos) {
                case positionType.Left:
                    //When item is left most item, both the left item and the left end of the menu must be toggled
                    Menu.toggleItem(td, document.getElementById('' + mname + 'SpanMenuLeftItem'), override);
                    Menu.toggleItem(document.getElementById('' + mname + 'DivLeftSide'), document.getElementById('' + mname + 'SpanLeftSide'), override);
                    break;
                case positionType.Right:
                    //When item is right most item, both the right item and the right end of the menu must be toggled
                    Menu.toggleItem(td, document.getElementById('' + mname + 'SpanMenuRightItem'), override);
                    Menu.toggleItem(document.getElementById('' + mname + 'DivRightSide'), document.getElementById('' + mname + 'SpanRightSide'), override)
                    break;
                default:
                    //Handles toggling of items in between the left most and right most items
                    Menu.toggleItem(td, document.getElementById('' + mname + 'SpanMenuItem'), override);
                    break;
            }
            //Indicate currently hovered over item
            if (hoverActive) {
                document.getElementById('' + mname + 'SpanCurrentMenuItem').name = td.id;
                document.getElementById('' + mname + 'SpanCurrentMenuItem').selected = selected;
                document.getElementById('' + mname + 'SpanCurrentMenuItem').position = pos;

                var nmSpanMenuSettings = document.getElementById('' + mname + 'SpanMenuSettings');
                if (nmSpanMenuSettings.dropMenuItemSelected) {
                    /*if(nmSpanMenuSettings.hasDropHang)
                    document.getElementById('' + mname + 'DropHang').style.display = 'block';
                
                    document.getElementById('' + mname + 'DivDropDown').style.display = 'none';*/
                    //div.style.display = 'none';
                    Menu.hideAllSubItems(mname);
                    //document.getElementById(nmSpanMenuSettings.selectedDropDownName).style.display = 'block';
                }
            }
            else {
                document.getElementById('' + mname + 'SpanCurrentMenuItem').name = '';
                document.getElementById('' + mname + 'SpanCurrentMenuItem').selected = false;
                document.getElementById('' + mname + 'SpanCurrentMenuItem').position = positionType.None;
            }

        }
    }

    //Performs a simple redirect
    Menu.redirect = function(href) {
        window.location.href = href;
    }

    //Function performs the actual menu item toggle
    Menu.toggleItem = function(item, classes, override) {
        var newClass = '';

        if (document.getElementById('divTest')) {
            var div = document.getElementById('divTest');
            div.innerHTML = div.innerHTML + override;
        }

        switch (override) {
            case hoverOverride.ForceHover:
                //Force the hover class to be used
                hoverActive = true;
                newClass = classes.hover;
                break;
            case hoverOverride.ForceRegular:
                //Force the regular class to be used
                hoverActive = false;
                newClass = classes.reg;
                break;
            case hoverOverride.ForceSelect:
                //Force the select class to be used
                hoverActive = false;
                newClass = classes.select;
                break;
            default:
                //Alternate between regular class and hover class depending on currently set class name
                hoverActive = !(item.className == classes.hover);
                if (!hoverActive)
                    newClass = classes.reg;
                else
                    newClass = classes.hover;
                break;
        }

        //Set the new class       
        item.className = newClass;
    }

    //Shows the menu after a delay
    Menu.delayMenuShow = function(div, delay, mname) {
        t = setTimeout(function() { Menu.showDropMenu(div, mname) }, delay);
    }

    //Immediately shows a drop menu
    Menu.showDropMenu = function(div, mname) {
        var nmSpanMenuSettings = document.getElementById('' + mname + 'SpanMenuSettings');
        var nmSpanCurrentMenuItem = document.getElementById('' + mname + 'SpanCurrentMenuItem');

        currentMenuItemName = nmSpanCurrentMenuItem.name;

        if (document.getElementById('md' + currentMenuItemName)) {
            div = document.getElementById('md' + currentMenuItemName);

            if (div.id != nmSpanMenuSettings.selectedDropDownName && nmSpanMenuSettings.dropMenuItemSelected) {
                document.getElementById(nmSpanMenuSettings.selectedDropDownName).style.display = 'none';
            }
        }

        if (nmSpanMenuSettings.hasDropHang)
            document.getElementById('' + mname + 'DropHang').style.display = 'none';

        document.getElementById('' + mname + 'SpanCurrentDropItem').value = div.id;
        document.getElementById('' + mname + 'DivDropDown').style.display = 'block';
        div.style.display = 'block';
    }

    Menu.delayMenuHide = function(div, delay, mname) {
        t = setTimeout(function() { Menu.hideDropMenu(div, mname) }, delay);
    }

    Menu.hideDropMenu = function(div, mname) {
        var nmSpanMenuSettings = document.getElementById('' + mname + 'SpanMenuSettings');

        document.getElementById('' + mname + 'SpanCurrentDropItem').value = '';
        if (nmSpanMenuSettings.dropMenuItemSelected) {
            if (div.id != nmSpanMenuSettings.selectedDropDownName) {
                div.style.display = 'none';
                Menu.hideAllSubItems(mname);
                if (nmSpanMenuSettings.hasDropHang)
                    document.getElementById('' + mname + 'DropHang').style.display = 'none';
                document.getElementById(mname + 'DivDropDown').style.display = 'block';
                document.getElementById(nmSpanMenuSettings.selectedDropDownName).style.display = 'block';
            }
        }
        else {
            if (nmSpanMenuSettings.hasDropHang)
                document.getElementById('' + mname + 'DropHang').style.display = 'block';

            document.getElementById('' + mname + 'DivDropDown').style.display = 'none';
            div.style.display = 'none';
            Menu.hideAllSubItems(mname);
        }
    }

    Menu.holdDropMenu = function(mname) {
        if (t) {
            clearTimeout(t);
        }
        if (document.getElementById('' + mname + 'SpanCurrentDropItem').value != '') {
            var currentDropItem = document.getElementById('' + mname + 'SpanCurrentDropItem').value;
            menuItemName = currentDropItem.substring(2, currentDropItem.length);

            keepSelected = true;

            activeDiv = document.getElementById(currentDropItem);

            //Menu.delayMenuShow(activeDiv, document.getElementById('' + mname + 'SpanMenuSettings').delay, mname);
        }
    }

    Menu.releaseDropMenu = function(mname) {
        if (t) {
            clearTimeout(t);
        }
        keepSelected = false;

        nmCurrentMenuItem = document.getElementById('' + mname + 'SpanCurrentMenuItem');
        if (nmCurrentMenuItem.name != '') {
            td = document.getElementById(nmCurrentMenuItem.name);
            Menu.delayToggle(td, nmCurrentMenuItem.selected, nmCurrentMenuItem.position, hoverOverride.ForceRegular, document.getElementById('' + mname + 'SpanMenuSettings').delay, mname);
        }

        var activeDiv;
        if (document.getElementById('' + mname + 'SpanCurrentDropItem').value != '')
            activeDiv = document.getElementById(document.getElementById('' + mname + 'SpanCurrentDropItem').value);
        //document.getElementById('nmSpanCurrentDropItem').value = '';
        if (activeDiv)
            Menu.delayMenuHide(activeDiv, document.getElementById('' + mname + 'SpanMenuSettings').delay, mname);
    }

    Menu.hideAllSubItems = function(mname) {
        var nmSpanMenuSettings = document.getElementById('' + mname + 'SpanMenuSettings');
        for (var i = 0; i < menuItemsArr.length; i++) {
            if (menuItemsArr[i] != nmSpanMenuSettings.selectedDropDownName) {
                div = document.getElementById('md' + menuItemsArr[i]);
                div.style.display = 'none';
            }
            //Menu.hideDropMenu(document.getElementById('md' + menuItemsArr[i]), mname);
        }
    }

    Menu.checkDropMenu = function(mname) {
        var nmSpanMenuSettings = document.getElementById('' + mname + 'SpanMenuSettings');
        nmCurrentMenuItem = document.getElementById('' + mname + 'SpanCurrentMenuItem');

        if (nmSpanMenuSettings.dropMenuItemSelected && !document.getElementById('md' + nmCurrentMenuItem.name)) {
            setTimeout(function() { document.getElementById(nmSpanMenuSettings.selectedDropDownName).style.display = 'block' }, nmSpanMenuSettings.delay);
        }
    }
}

//END MENU OBJECT
