﻿$(document).ready(function(){
    var currentHover = null
    var thirdHover = null
    
    $('.navTopLevel').hover(function(){

        $('.navTopLevel').css('background-color','transparent'); 
        $(this).css('background-color','#c3083d'); 
        var navLeft = $(this).position().left;
        var thisTLNav = $(this).attr('id');
        currentHover = thisTLNav;
        var thisNav2 = $('.nav2ndLevel').filter('.' + currentHover);
        hideThirdNav();   
        if(thisNav2.css('display') == 'none')
        {
            hideAllNavs();
        }
        thisNav2.width($(this).width()+30);
        thisNav2.css('left',navLeft);
        
        thisNav2.slideDown('fast');
    },function(e){
        $(this).css('background-color','transparent');
    });
    
    $(document).mouseover(function(e){
        var h = $(e.target);
        if(!h.hasClass(currentHover))
        {
           hideAllNavs();
           $('.nav3rdLevel').fadeOut('fast');
        }        
    });
        
    function hideAllNavs()
    {
         $('.nav2ndLevel').slideUp('fast');
         $('.registerHover').remove();   
    }
    
    function hideThirdNav()
    {
        $('.nav3rdLevel').fadeOut('fast');
        // Remove the next line per Matthew on 10/08/2010 as it is a redundancy but that was causing problems for our locking/rollover on level 2 locked menus.
        //$('.registerHover').remove();  
    }

    $('.navItem').hover(function(){
        navItem = $(this);
        
         $('.registerHover').fadeOut(200);
        if(!$(this).children('a').hasClass('lightgrey')){
            $(this).addClass('navItemHover');
            $(this).children('a').css('color','#ffffff');
            $(this).children('.navArrow').attr('src','images/navArrow_hover.png');
        }
        else
        {
        // this is a locked nav -- so registration hover
        thisClasses = $(this).attr('class').replace('navItem ','');
        registerHoverHeight = parseInt($(this).outerHeight())-12;
        registerHoverWidth = parseInt($(this).outerWidth()) - 34;
        // If the width is less than 200 then the height has to be 32 for the Register for free to unlock this content rollover.
        if (registerHoverWidth < 200 && registerHoverHeight < 32)
        {
            // Set the height to 32.
            registerHoverHeight = 32
        }
        registerHover = '<div class="registerHover activateChildLink ' + thisClasses + '" style="height:' + registerHoverHeight + 'px; width: ' + registerHoverWidth + 'px"><a href="register.aspx" class="white bold ' + thisClasses + '"><span class="' + thisClasses + '" style="color: gold;">Register for free</span> to unlock this content</a></div>'
        $(this).before(registerHover);

        }
                
        if(!$(this).hasClass(thirdHover))
        {
            // Problem is when this is called on the Additional Resources as it removes the "Register for free...." message.
            hideThirdNav();
        }        
        
        // pop the 3rd level
        if($(this).attr('id').length > 0)
        {
            thirdHover = $(this).attr('id');
        }
        var thisNav3 = $('.nav3rdLevel').filter('.' + $(this).attr('id'));
        thirdWidth = parseInt(eval($(this).width()) +  eval($('.nav2ndLevel').filter('.' + currentHover).css('left').replace('px',''))+34);
        thisNav3.css('left',thirdWidth);
       
        thisNav3.css('top',navItem.offset().top-138);
        thisNav3.fadeIn('fast');
                
        
    },function(){
        if(!$(this).children('a').hasClass('lightgrey')){
            $(this).removeClass('navItemHover');
            $(this).children('a').css('color','#B32017');
        }
        if($(this).children('.navArrow').hasClass('navArrow'))
        {
            $(this).children('.navArrow').attr('src','images/navArrow.png');        
        }
    });
    

});
