/**
 * Adds and removes classes to a list of links to allow keyboard accessibility
 *
 * @param string dropDownId
 * @param string hoverClass
 */
jQuery.fn.dropdown = function() {
    var nav = this;
    this.find("li").hover(addHover, removeHover);
    var anchors = this.find("li a");
    anchors.focus(function () {
        tabOn($(this).parent());
    });
    anchors.blur(function () {
        tabOff($(this).parent());
    });
        
    function tabOn(li) {
        if (!li.is("li")) {
            return;
        }
        li.each(addHover);
        tabOn($(li.parents().eq(1)));
    }
    
    function tabOff(li) {
        if (!li.is("li")) {
            return;
        }
        li.each(removeHover);
        tabOff($(li.parents().eq(1)));
    }

    function addHover() {
        $(this).addClass("hover");
        if ($(this).closest("ul").attr("id") == nav.attr("id")) {
            $(this).children("ul").addClass("hover-first-level");
        }
    }

    function removeHover() {
        $(this).removeClass("hover");
        $(this).children("ul").removeClass("hover-first-level");
    }
};
