$(function() {
    var PROJECT_INFO_ANIM_SPEED =  "fast";
    $(".project-info-bg").css("opacity", 0.80);
    $(".project-nav-menu").css("opacity", 0.93);
    $(".project-info,.project-info-bg").css("visibility", "visible").hide();  
   
    $(".project-list li").hover(
        function() {
            var $me = $(this);            
            var info_set = $me.find(".project-info,.project-info-bg");            
            info_set.fadeInWithStop(PROJECT_INFO_ANIM_SPEED);               
        },
        function() {
            var $me = $(this);
            var info_set = $me.find(".project-info,.project-info-bg");            
            info_set.fadeOutWithStop(PROJECT_INFO_ANIM_SPEED);            
        }
    ); 
    
    $(".project-thumb").click(
        function(e) {
            window.location = $(this).children("a")[0].href;            
        }
    );
    
    $(".tab-panel:gt(0) ul").hide();
    $(".tab-panel h4").click(
        function(e) {
            $(".tab-panel ul").hide();
            $($(this).siblings("ul")[0]).show();
            $(".tab-panel h4").removeClass("selected");
            $(this).addClass("selected");
        }
    );
    
    
    var last_menu, menu_timer;
    
    $("ul.sub-menu").css('display', 'inline').hide();
    $("a.has-sub-menu").click(function() { return false;});
    $("a.has-sub-menu").hover(
       function() {
           var $me = $(this);
           var $menu = $me.next("ul");         
           
           if(last_menu && last_menu[0] != $menu[0]) {               
               menu_out();
           }
           
           $menu.fadeInWithStop("fast");           
           $me.addClass("hover");           
           stop_menu_timer();
       },
       function() {            
           last_menu = $(this).next("ul");
           start_menu_timer();
       }
    ); 
    
    function start_menu_timer() {
        menu_timer = setTimeout(menu_out, 300);
    }
    
    function stop_menu_timer() {
        clearTimeout(menu_timer);
    }
    
    function menu_out() {
        if(last_menu != null) {
            last_menu.prev("a").removeClass("hover");            
            last_menu.fadeOutWithStop("fast");            
        }
    }
    
    $("ul.sub-menu").hover(
        stop_menu_timer,
        start_menu_timer
    );
});