$(document).ready(function($) {
    
    // jQuery easing, don't want to add the whole easing plugin
    $.extend( $.easing, {
        easeOutExpo: function (x, t, b, c, d) {
            return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
        },
    });
    
    // Preload page and fade in objects
    $("#progress").fadeOut(200,function(){ jQuery(this).remove(); });
    
    $(".fade").each(function(i) {
        var e = $(this);
            e.fadeTo(0, 0);
            setTimeout(function(){
                e.fadeTo(200, 1);
        }, i*100);
    });
    
    // toggle grid
      $(window).bind("load resize", function() {
            var h = $(document).height();
            $("#grid").css({ "height" : (h) });
      });
    
    $("#grid").hide();
    
    // masonry
    $("ul.projects").masonry({ 
        columnWidth: 160,
        animate: false,
        animationOptions: {
            duration: 200
        }
    });
    
    // info panel toggle
    $("#about").hide();
    
    $("a.info").click(function () {
        $("#about").slideToggle(400, "easeOutExpo");
    });
    
    // collapse info panel if user navigates away from page
    $("a:not(.info, [target=_blank])").live("click", function(){
        if ($("#about").is(":visible")) {
            var href = $(this).attr("href");
            
            var animDuration = 200;
            
            $("#about").slideUp(200);
            
            setTimeout(function () {
                window.location = href;
            }, animDuration);
            
            return false;
        }
    });
    
    // keyboard shortcuts
    $(document.documentElement).keyup(function (event) {
        if (event.keyCode == 71) {
            $("#grid").fadeToggle(100); // G toggles grid
        } else if (event.keyCode == 73) {
            $("a.info").click(); // I toggles info
        } else if (event.keyCode == 39) {
            $("a#next-image").click(); // right arrow, next image
        } else if (event.keyCode == 37) {
            $("a#previous-image").click(); // left arrow, prev image
        }
    });

}); 

