$(function () {
    // Remove pesky link titles from popping up, but without causing validation to fail
    $("a").removeAttr("title");

    // Hover Menu Implementation
    var tmrHideHover,
    hideHover = function () {
        $('div#sub_menu_container').slideDown("fast"); // Show the sub menu (if it exists)
        $('div#hover_menu_container').slideUp("fast"); // Hide the hover menu container
    }, showHover = function (curr) {
        clearTimeout(tmrHideHover); // Clear the timer (if it is set), to prevent the hover container from being hidden

        if (curr.hasClass('active')) {
            $('div#hover_menu_container').hide();
            $('div#sub_menu_container').slideDown("fast"); // Show the sub menu (if it exists)
            $('div.hover_menu').hide(); // Hide all other hover menus
        }
        else {
            $('div#sub_menu_container').hide(); // Hide the sub menu (if it exists)
            $('div.hover_menu').hide(); // Hide all other hover menus
            $('div#hover_menu_container').slideDown("fast"); // Show the hover menu container

        }
        
    }

    $('div#hover_menu_container').hover(function () {
        clearTimeout(tmrHideHover); // Prevent the hover menu from being hidden
    }, function () {
        tmrHideHover = setTimeout(hideHover, 1000);
    });

    // Add the hover menus to the main menu
    $('div#main_menu a').each(function () {
        // Display the hover menu, only if it exists
        if ($('div#' + $(this).attr('class')).length > 0) {
            $(this).hover(function () {

                //Lets hide the submenu if its the other 3 items.
              

                    showHover($(this)); // Call the show hover function
                    $('div#' + $(this).attr('class')).show(); // Show the specific hover menu
              
            }, function () {
                // Allow the user to transition from the main menu to the hover menu (without it flickering)
                // TODO: fix scoping issue and call the hideHover function

                tmrHideHover = setTimeout("$('div#sub_menu_container').show(); $('div#hover_menu_container').hide();", 1000);

            });
        }
    });

    //instantly hide the non hover menu if highlighting a tab without submenus
    $('div#main_menu a.our_team').hover(function(){
        $('#hover_menu_container').hide();
        $('div#sub_menu_container').hide();
            }, function(){}
        );
    $('div#main_menu a.contact_us').hover(function () {
        $('#hover_menu_container').hide();
        $('div#sub_menu_container').hide();
    }, function () { }
        );


    $('div#main_menu a.careers').hover(function () {
        $('#hover_menu_container').hide();
        $('div#sub_menu_container').hide();
    }, function () { }
        );
    
    

    // Add hover to buttons
    $(':button, :submit').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });

    /*
    So lets remove the top links Services, About Us Panel and Other Links for this revision
    */



    $('a.services').attr("href", "#");
    $('a.about_us').attr("href", "#");
    $('a.panel').attr("href", "#");
    $('a.link_otherlinks').attr("href", "#");
    $('li.menu_item a.link_otherlinks').css("display", "none");



    $('#footer_left ul.contact_us').remove();


    $('a.surveyresults,a.landing_page').hide();



    //Override hover on about_us because when we click on newsroom the about_us submenu doesn't appear when re-hovered. This fixes that.
    $('a.about_us').hover(function () {

        //Lets hide the submenu if its the other 3 items.


        showHover($(this)); // Call the show hover function
        $('div#about_us').show(); // Show the specific hover menu

    }, function () {
        // Allow the user to transition from the main menu to the hover menu (without it flickering)
        // TODO: fix scoping issue and call the hideHover function

        tmrHideHover = setTimeout("$('div#sub_menu_container').show(); $('div#hover_menu_container').hide();", 1000);

    });

});


