/*
	The super-simple dropdown menu 2010!
	Author: Rick Quantz
	
	Requires core.js
	
	To make this go:
		1. Set the selector for the menu UL.
		2. Call dropdown.init() on document ready.
		
	See the end of this document for an example of the necessary markup
*/



var dropdown = (function() {

    // Private configuration variables
    var menuSelector = '#nav li'  // The selector you want to use for the menu items
      , hoverClass = 'over'     // The class that will be added when a menu item is hovered over
      , currentItemClass = 'current'; // The class that will be added to the current menu item

    // Public. Use self as a scope-safe alias for this
    var self = {

        menuItems: [],

        init: function() {

            attachHoverEvents();
            //lightUpMenu(); // This is commented out because inc_top.aspx already adds the 'current' class

        }
    }

    // Private functions
    function attachHoverEvents() {
        self.menuItems = core.getElements(menuSelector);

        core.each(self.menuItems, function(item) {

            item.onmouseover = navMenuItemMouseOver;
            item.onmouseout = navMenuItemMouseOut;

        });
    }

    function navMenuItemMouseOver() {
        core.css.addClass(this, hoverClass);
    }

    function navMenuItemMouseOut() {
        core.css.removeClass(this, hoverClass);
    }

    function lightUpMenu() {
        var currentPage = getFileName(location.pathname)
          , anchors = core.getElements(menuSelector + ' a');
        core.each(anchors, function(a) {
            var thisFile = getFileName(a.href);
            if (currentPage === thisFile) {
                core.css.addClass(a, currentItemClass);
                core.css.addClass(getMenuParent(a), currentItemClass);
            }
        });
    }

    function getFileName(path) {
        return path.substr(path.lastIndexOf('/') + 1) || 'index.aspx';
    }

    function getMenuParent(a) {
        return a.parentNode.parentNode.parentNode
    }

    // Return the public object
    return self;

})();



// The onready function. If you are using core.ready elsewhere, be sure to move dropdown.init() there.
core.ready(function() {

	dropdown.init();

});
