﻿$(document).ready(function () {

    // preload css images
    $.preloadCssImages();

    Cufon.replace('.hover span, .project_detail .content_right ul li');
    Cufon.replace('#menu li a, h2', { hover: 'true' });

    $(".featured_projects .project:nth-child(odd)").addClass("clear")
    $(".projects .project:nth-child(3n+1)").addClass("clear");

    // lazy load images
    var images = $("img.thumbnail");
    $(".image_wrapper").addClass("loading");

    $(images)
        .hide()
        .each(function () {
            if (!this.complete) {
                $(this).load(function () {
                    displayImage(this);
                });
            }
            else {
                displayImage(this);
            }
        });

    $(".image_wrapper").click(function () {
        var url = $(".hover a", this).attr("href");
        window.location = url;
    });
});

$(document).unload(function () { });

function setUpOverlay(e) {
    $(e).removeClass("loading");
    $(e).hoverIntent(
        function () {
            var width = $('img.thumbnail', this).width();
            var height = $('img.thumbnail', this).height();
            $('.hover', this).width(width).height(height);
            $(".hover", this).fadeIn("100");
        },
        function () {
            $(".hover", this).fadeOut("200");
        });
    }

function displayImage(img) {
    $(img).fadeIn(300, function () {
        setUpOverlay($(this).parents(".image_wrapper"));
    });
}
