﻿function showSubmenu(navItem)
{
    // hide all submenus    
    $(".submenu").hide();        
    
    // show active submenu     
    $(navItem).children("ul.submenu").show();    
}

$(document).ready(function()
{  
    var timer;       
    var minTimerThreshold = 200;
    var navItem;
    
    $("#top-bar > li").hover(
    function()
    {
        navItem = this;       
        
        // Only show the submenu if the main item is hovered 
        // over for a minimum number of ms   
        timer = setTimeout(function()                
        {                  
            // deactivate all menu items
            $(".mainopt").removeClass("active"); 
            $(".leftcap").removeClass("leftcap_active");
            $(".rightcap").removeClass("rightcap_active");                        
                                                     
            // set the hovered menu item as active 
            $(navItem).children("a.mainopt").addClass("active");   
            $(navItem).children(".leftcap").addClass("leftcap_active"); 
            $(navItem).children(".rightcap").addClass("rightcap_active"); 
            
            // show the active item's submenu
            showSubmenu(navItem);                           
        }, minTimerThreshold);
    },    
    function()
    {                  
        // clear the mouseover timer
        clearTimeout(timer);                                
    });          
                                           
    $("#top-bar").hover(null, function()
    {
        // deactivate all menu items    
        $(".mainopt").removeClass("active"); 
        $(".leftcap").removeClass("leftcap_active");         
        $(".rightcap").removeClass("rightcap_active");        
        
        // show the submenu of the current subsite page
        showSubmenu($("#top-bar").find('li.active'));  
    });     
});



