$(document).ready(function($) {
    
    // Preload page and fade in objects
    $(window).bind("load", function() {
        $("#progress").fadeOut(1,function(){ 
            $(this).remove(); 
        });
    });
    
    // 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;
        },
    });
    
    // masonry
    $("ul.projects").masonry({ 
        columnWidth: 160,
        animate: false,
        animationOptions: {
            duration: 200
        }
    });
    
    // info panel toggle
    
    $("a.info").click(function () {
        $("#about").slideToggle(400, "easeOutExpo").css("display","block");
    });
    
    // 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(400, "easeOutExpo");
            
            setTimeout(function () {
                window.location = href;
            }, animDuration);
            
            return false;
        }
    });
    
    // size baseline grid for css columns
    $(window).bind('load resize', function() {
        var column = $('.words');
        column.css({ 'height' : 'auto' });
        var height = Math.floor(column.height() / 18)*18;
        column.css({ 'height' : height });
    });
    
    // 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
        }
    });

}); 

