﻿//Drop down menu. 
jQuery.noConflict();

jQuery(document).ready(function() {
    
    //when clicking on anywhere else on the document, hide all visible subhover items
    jQuery(document).click(function() {
        jQuery('.subhover').slideUp('fast');
        jQuery('.subhover').removeClass('subhover');
    });
    
    
    jQuery("ul.subnav").parent().addClass('dropdownmenu');
    //Menu Hover. 
    jQuery("#TopNavigation li.dropdownmenu a.menufont").hover(function() {
        //Check if this menu is already in the midst of moving. 
        if (jQuery(this).hasClass('moving')) {
            return;
        };

        if (jQuery(this).parent().find("ul.subnav").hasClass('subhover')) {
            return;
        };

        jQuery(this).parent().find("ul.subnav").addClass("moving");
        jQuery(this).addClass("moving");

        //Slide up any existing menus.
        jQuery('.subhover').each(function() {
            jQuery(this).slideUp('fast');
            jQuery(this).removeClass('subhover');
        });

        jQuery(this).parent().find("ul.subnav").addClass("subhover");
        jQuery(this).parent().find("ul.subnav").slideDown('fast', function() {
            jQuery('.moving').removeClass('moving');
        });
    });

    //This is hovering over the drop down menu. When they move outside the submenu. We stop the drop down menu. 
    jQuery('ul.subnav').hover(function() {
    },
    function() {
        if (jQuery(this).hasClass("moving")) {
            return;
        }

        jQuery(this).slideUp('fast', function() {
            jQuery(this).removeClass("subhover");
        });
    });

    jQuery('ul.subnav').mouseout(function() {

    });
});  
