﻿
$(document).ready
(function(){
    
    FormatNavMenuLinks();
    
    $("#MenuBar ul li").hover(
        function()
        {
            if( $(this).attr("class") !== "thisPage" )
            {
                $(this).addClass("hoverLink");
                $(this).children(".brdLeft").addClass("brdLeftHover");
                $(this).children(".brdRight").addClass("brdRightHover");
            }
            $(this).children("ul").show();
        },
        function()
        {
            if( $(this).attr("class") !== "thisPage" )
            {
                $(this).removeClass("hoverLink");
                $(this).children(".brdLeft").removeClass("brdLeftHover");
                $(this).children(".brdRight").removeClass("brdRightHover");
            }
            $(this).children("ul").hide();
        }
    );
    
    $(".calloutLink").hover(
        function()
        {
            if ($(this).siblings(".calloutAbove").is("*"))
            {
                $(this).parent().removeClass("level3");
                $(this).parent().addClass("level0");
            }
            $(this).siblings(".bannerCallout").fadeIn("slow");
        },
        function()
        {
            if ($(this).siblings("div.calloutAbove").length)
            {
                $(this).parent().removeClass("level0");
                $(this).parent().addClass("level3");
            }
            $(this).siblings(".bannerCallout").fadeOut("fast");
        }
    );
    
    $(".companyBox").hover(
        function()
        {
            $(this).addClass("companyBoxOver");
        },
        function()
        {
            $(this).removeClass("companyBoxOver");
        }
    );
    
    
    /// Ads formatting to menu buttons.  Highlights the menu button if it corresponds to the current page
    function FormatNavMenuLinks()
    {
        var thisPage = GetThisPage(window.location.href);
        
        var s = "";
        //-- Loop through each TOP LEVEL menu item, if the current page is one of the menu items
        //-- then add the "THIS PAGE" CSS formatting
        $("ul.nav > li").each(
            function()
            {
                //s += $(this).children("a").attr("href") + '\n';
                if ( $(this).children("a").attr("href") === thisPage )
                {
                    //-- Add the formatting
                    $(this).addClass("thisPage");
                    $(this).children("ul").addClass("thisPageDropdown");
                }
            }
        );
        //alert(s);
    }

    /// Gets the page name only out of a full url;
    function GetThisPage(s)
    {
        // Remove any querystring stuff
        if (s.lastIndexOf("?") > 0)
        {
            s = s.substring(0, s.lastIndexOf("?"))
        }
        if (s.length > (s.lastIndexOf(".aspx") + 5))
        {
            s = s.substring(0, s.lastIndexOf(".aspx") + 5)
        }
        // Get the page name
        s = s.substring(s.lastIndexOf("/") + 1, s.length);
        // Make sure the page is not just the root of a folder
        if (s.indexOf(".aspx") < 0)
        {
            s = "default.aspx";
        }
        //alert(s);
        return s;
    }



});
