/*-----------------------------------------+
 | Hover - Add :hover functionality for IE |
 +-----------------------------------------*/
var Hover = {
    // Create two-dimensional array of identifiers for hover effect
    // [id/class] [child nodes] [unique]
    collections : new Array(
        new Array("nav", "li", true)
        ),

    // Find all elemnts specified in array (IE only)
    init : function(collections) {
        if (document.all && document.getElementById && document.getElementsByTagName) {
            for (var i = 0; i < collections.length; i++) {
                var list = collections[i];
                var name = list[0];
                var delimiter = list[1];
                var unique = list[2];
                var children = new Array();

                if (unique) {
                    // Unique element, find by ID
                    var parent = document.getElementById(name);

                    if (parent) {
                        children = parent.getElementsByTagName(delimiter);
                        Hover.addBehaviors(children);
                    }
                } else {
                    // Not unique, find by class
                    var parents = document.getElementsByTagName("*");

                    for (var j = 0; j < parents.length; j++) {
                        if (parents[j].className.indexOf(name) > -1) {
                            children = parents[j].getElementsByTagName(delimiter);
                            Hover.addBehaviors(children);
                        }
                    }
                }
            }
        }
    },

    // Add class of "over" to elements when mouse hovers over them, remove when mouse stops hovering
    addBehaviors : function(collection) {
        for (var j = 0; j < collection.length; j++) {
            var node = collection[j];

            if (node.className.indexOf("current") == -1) {
                node.onmouseover = function() {
                    this.className += " over";
                    this.style.zIndex = 9999;  // Fixes IE z-index bug
                }
                node.onmouseout = function() {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
};

//jQuery.noConflict();

// From Hover Delay
var Hover = function(navBar)
{
    var me = this;
    me.items = navBar.find("ul")[0].childNodes;

    jQuery.each(me.items, function(i, item) {
        me.initItem(item);
    });
}

Hover.prototype.initItem = function(item)
{
    var me = this;
    item.onmouseover = function()
    {
        me.closeAllExcept(item);

        clearTimeout(me.closeTimeout);
        me.openTimeout = setTimeout(function()
        {
            item.className = "over";
            item.style.zIndex = 9999;
        }, Hover.OPEN_TIMEOUT);
    };

    item.onmouseout = function()
    {
        clearTimeout(me.openTimeout);

        me.closeTimeout = setTimeout(function()
        {
            item.className = "";
        }, Hover.CLOSE_TIMEOUT);
    };
}

Hover.prototype.closeAllExcept = function(exceptItem)
{
    jQuery.each(this.items, function(i, item)
    {
        if (item != exceptItem)
            item.className = "";
    });
}

Hover.OPEN_TIMEOUT  = 0;
Hover.CLOSE_TIMEOUT = 0;

