﻿//Hover menu plug-in for jquery
jQuery.noConflict();

(function($) {
    var hideDelayTimer;
    var elem;

    $.fn.hoverMenu = function() {
        this.each(function() {
            elem = this;
            $("ul.subnav", elem).each(function(i) { $(this).parent().data('customID', i) });
            $("ul.subnav", elem).parent().hover(function() {
				$(this).find("a").addClass("subhover"); //On hover over, add class "subhover"
                var x = $(this);
                if (hideDelayTimer) { clearTimeout(hideDelayTimer); hideDelayTimer = null; }
                $("ul.subnav").each(function(i) { if ($(this).parent().data('customID') != x.data('customID')) { $(this).stop(true, true).hide(); } });
                if ($(elem).data('showing') == null || $(this).data('customID') != $(elem).data('showing').data('customID')) {
                    $(this).find("ul.subnav").slideDown('fast').show();
                }
            }, function() {
                 $(this).find("a").removeClass("subhover"); //On hover out, remove class "subhover"
                $(elem).data('showing', $(this));
                hideDelayTimer = setTimeout(function() {
                    $(elem).data('showing').find("ul.subnav").slideUp('fast');
                    $(elem).data('showing', null)
                }, 100);
            });
        });
    }
})(jQuery);     
