﻿$(window).load(function(){
    $('#navcontainer h2').click(function(){
        $('#leftnav .cats').addClass('collapsed');
        $(this).next('ul').removeClass('collapsed');
        //console.log($(this));
    });
    addShadowToSubNav();
    makeSubNavsStayOnScreen();
});

var menuTimeout;
var i = 0;
var defNavImg;
$(function(){
//main dropdown on hover functions
    $('#dropDown-links .catlinks>li, .subnav').hover(function(){
        //console.log('over');
        clearTimeout(menuTimeout);
        $('.subnav').hide();
                
        if ($("li", $(this)).length > 0) {
            $(this).children('.subnav').show();
            defNavImg = $(this).children('.subnav').find('img.navpic').attr('src');
        }
    },
    function(){
        //i++;
        var $this = $(this);
        //console.log('out ' + i);
        var func = function(){ hideSubNav( $this ); }
        menuTimeout = window.setTimeout( func , 500);
    });
    
    //when each link is hovered over - change the menu image
    $('.subnav li').hover(
        function(){
            var image = $(this).attr('data-img');
            var thumbholder = $(this).parent('div.navContain').siblings('.navpic');
            thumbholder.attr('src',image);
            thumbholder.attr('alt', $(this).find('a').text());
        },function(){
           
        }
    );
        
     
});

 

function hideSubNav($this){
    //console.log($this);
    $this.children('.subnav').hide();
}

function addShadowToSubNav(){
    $("#dropDown-links .subnav").append('<div class="shadow"><img src="/images/subnavShadow.png"/></div>');

}

function makeSubNavsStayOnScreen()
{
    $('#dropDown-links .catlinks > li:gt(4) .subnav').addClass('right');

}
