﻿preloadImages();
$(document).ready(function () {
    // Blur images on mouse over
    $(".portfolio a").hover(function () {
        $(this).children("img").animate({ opacity: 0.75 }, "fast");
    }, function () {
        $(this).children("img").animate({ opacity: 1.0 }, "slow");
    });

    // Initialize prettyPhoto plugin
    $(".portfolio a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'light_square',
        autoplay_slideshow: false,
        overlay_gallery: false,
        show_title: false
    });

    // Clone portfolio items to get a second collection for Quicksand plugin
    var $portfolioClone = $(".portfolio").clone();

    // Attempt to call Quicksand on every click event handler
    $(".filter a").click(function (e) {

        $(".filter li").removeClass("current");

        // Get the class attribute value of the clicked link
        var $filterClass = $(this).parent().attr("class");

        if ($filterClass == "all") {
            var $filteredPortfolio = $portfolioClone.find("li");
        } else {
            var $filteredPortfolio = $portfolioClone.find("li[data-type~=" + $filterClass + "]");
        }

        // Call quicksand
        $(".portfolio").quicksand($filteredPortfolio, {
            duration: 700,
            easing: 'easeInOutQuad'
        }, function () {

            // Blur newly cloned portfolio items on mouse over and apply prettyPhoto
            $(".portfolio a").hover(function () {
                $(this).children("img").animate({ opacity: 0.75 }, "fast");
            }, function () {
                $(this).children("img").animate({ opacity: 1.0 }, "slow");
            });

            $(".portfolio a[rel^='prettyPhoto']").prettyPhoto({
                theme: 'light_square',
                autoplay_slideshow: false,
                overlay_gallery: false,
                show_title: false
            });
        });


        $(this).parent().addClass("current");

        // Prevent the browser jump to the link anchor
        e.preventDefault();
    })

    //...click "All" by default so page will load completely
    $(".current a").click();
});

function preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}
