$(document).ready(function(){
    var locked = 0;
    
    $(".left-link").mouseenter(function(){
        var elid = $(this).attr("id");
        var id = elid.substr(elid.length-1,1);
        leftShowMenu(id);
    });

    $("#home-item").mouseleave(function(event){
        if(locked) {locked = 0; leftNext();}
    });

    function leftGoTo(id)
    {
        $(".home-bg").stop();
        $(".home-bg").animate({opacity:0},500, "linear", function(){$(this).css({'display':'none'})});
        $("#left-"+id+"-img").stop().css({'display':'block'}).animate({opacity:1},500);
        $(".home-item .arrow").stop();
        $(".home-item .arrow").animate({top: (id-1)*125}, 500)
    }

    function leftShowMenu(id)
    {
        leftGoTo(id);
        $(".exp-menu").stop();
        $(".exp-menu").css({width:0});
        $("#expanded-menu-"+id).stop();
        var expw;
        if($("#expanded-menu-"+id).hasClass("article-postcard"))
        {
            expw = 198;
        }
        else
        {
            expw = 225;
        }
        $("#expanded-menu-"+id).animate({width:expw}, 500);

        locked = 1;
    }

    var leftCur = 0;
    function leftNext()
    {
        if(!locked)
        {
            $(".exp-menu").stop();
            $(".exp-menu").animate({width:0},500);
            leftCur++;
            if(leftCur>3) leftCur = 1;
            leftGoTo(leftCur);
            setTimeout(function(){leftNext();}, 7000);
        }
    }
    leftNext();
});
