//Function to add hover rules to the main site navigation
$(document).ready(
    function addNavigationListeners() {
        /* Add hover event to main menu items to dropdown submenus */
        $(".listMainNavigationItem").hoverIntent(
        //hover over actions
                function () {
                    /* Calculate out the left positions */
                    var navOffset = $(this).offset();
                    var navLeft = navOffset.left;
                    var navWidth = $(this).width();
                    var navId = $(this).attr("id");
                    if (navId == "navAbout") {
                        navLeft = navLeft - 0;
                    }
                    else if (navId == "navMarketSolutions") {
                        navLeft = navLeft - 111;
                    }
                    else if (navId == "navProductSolutions") {
                        navLeft = navLeft - 278;
                    }
                    else if (navId == "navResources") {
                        navLeft = navLeft - 449;
                    }
                    else if (navId == "navPartnerships") {
                        navLeft = navLeft - 583;
                    }
                    else if (navId == "navTraining") {
                        navLeft = navLeft - 729;
                    }
                    else if (navId == "navContact") {
                        navLeft = navLeft - 851;
                    }
                    var navFinalLeft = navLeft.toString() + "px";
                    /* Done calculating out the left position */
                    $(this).find(".navImage").hide();                                   //Hide the non-hover image
                    $(this).find(".navImageHover").show();                              //Show the hover image
                    if ((navId != "navAbout") && (navId != "navContact")) {
                        $("#navAboutImage").hide();                                     //Hide the about image with corners if we are hovering over a center button
                        $("#navContactImage").hide();                                   //Hide the contact image with conrners if we are hovering over a center button   
                        $(".navImageNoCorner").show();                                  //Show the cornerless images if we are hovering over a center button
                    }
                    else if (navId == "navAbout") {
                        $("#navContactImage").hide();                                   //Hide the contact image with corners if we are hovering over the about button
                        $("#navContactImageNoCorner").show();                           //Show the cornerless contact image if we are hovering over the about button
                    }
                    else if (navId == "navContact") {
                        $("#navAboutImage").hide();                                     //Hide the about image with corners if we are hovering over the contact button
                        $("#navAboutImageNoCorner").show();                             //Show the cornerless about image if we are hovering over the contact button
                    }
                    $(this).find(".listSubNavigation").css({ "left": navFinalLeft });    //Place the Subnavigation at the correct position
                    $(this).find(".listSubNavigation").show();                          //Show the sub navigation menu after a delay
                    $("#divSplashContent").hide();                                      //Hide the splash content so it does not interfere with the dropdown
                    $("#divGlobalOfficesMap").hide();                                   //Hide the global offices flash map so it does not interfere with the dropdown
                },
        //hover out actions
                function () {
                    var navId = $(this).attr("id");
                    $(this).find(".listSubNavigation").hide();                          //Hide the sub navigation menu
                    if ((navId != "navAbout") && (navId != "navContact")) {
                        $(".navImageNoCorner").hide();                                  //Hide the cornerless images if we are moving off a center button
                        $("#navAboutImage").show();                                     //Show the about image with corners if we are moving off a center button
                        $("#navContactImage").show();                                   //Show the contact image with conrners if we are moving off a center button   
                    }
                    else if (navId == "navAbout") {
                        $("#navContactImageNoCorner").hide();                           //Hide the cornerless contact image if we are moving off the about button
                        $("#navContactImage").show();                                   //Show the contact image with corners if we are moving off the about button
                    }
                    else if (navId == "navContact") {
                        $("#navAboutImageNoCorner").hide();                             //Hide the cornerless about image if we are moving off the contact button
                        $("#navAboutImage").show();                                     //Show the about image with corners if we are moving off the contact button
                    }
                    $(this).find(".navImageHover").hide();                              //Hide the hover image
                    $(this).find(".navImage").show();                                   //Show the non-hover image
                    $("#divSplashContent").show();                                      //Show the splash content now that we are done with the subnavigation
                    $("#divGlobalOfficesMap").show();                                   //Show the global offices flash map now that we are done with the subnavigation
                }
        );
        /* Add hover events to subnavigation content items to change images if they exist */
        $(".listSubNavigationContent li").hover(
        //hover over actions
            function () {
                var contentID = $(this).attr("id");                                     //Get the id of the sub navigation content item
                if (contentID != null)                                                  //Check if the id is not null
                {
                    var imgID = contentID.replace("li", "img");                          //Get the image id from the content id
                    if (imgID != "")                                                    //Find out if the image exists
                    {
                        $(".imgSubNavigationDefault").hide();                                //Hide all of the default navigation images
                        $("#" + imgID).show();                                               //Show the related subnavigation image
                    }
                }
            },
        //hover out actions
            function () {
                var contentID = $(this).attr("id");                                     //Get the id of the sub navigation content item
                if (contentID != null)                                                  //Check if the id is not null
                {
                    var imgID = contentID.replace("li", "img");                          //Get the image id from the content id
                    if (imgID != "")                                                    //Find out if the image exists
                    {
                        $("#" + imgID).hide();                                              //Hide the related subnavigation image
                        $(".imgSubNavigationDefault").show();                               //Show all of the default navigation images   
                    }
                }
            }
        );
    }
);
