$(document).ready(function () {
    $("h1").text(function () {
        var text = $(this).text();
        $(this).html("<span>" + text + "</span><b></b>");
    });

    $("a.preview, a.lightbox, a.fancybox").fancybox();

    // Image gallery preloading functions
    $("a.preview img, .gallery ul li a img").each(function () {
        var img = new Image();
        img.src = $(this).attr("src");

        if (img.complete) {
            $(this).fadeIn();
        } else {
            img.onload = function () {
                $(this).fadeIn();
            };
        }
    });

    $(".gallery ul li a").click(function (e) {
        e.preventDefault();

        var preview = $("a.preview img");
        preview.parent().attr("href", $(this).attr("href"));

        var img = new Image();
        img.src = $(this).attr("href") + ".axd?width=" + preview.parent().width() + "&height=" + preview.parent().height() + "&crop=auto";

        if (img.complete) {
            preview.attr("src", img.src);
            preview.fadeIn();
        } else {
            preview.hide();
            img.onload = function () {
                preview.attr("src", img.src);
                preview.fadeIn();
            };
        }

        //alert(img.src);

        //        var imgUrl = $(this).attr("href") + ".axd?width=" + preview.parent().width() + "&height=" + preview.parent().height() + "&crop=auto";

        //        preview.parent().attr("href", $(this).attr("href"));
        //        preview.hide();

        //        $.ajax({
        //            ifModified: true,
        //            url: imgUrl,
        //            success: function () {
        //                preview.attr("src", imgUrl);
        //                preview.show();
        //            }
        //        });
    });
});

