﻿/// <reference path="~\Scripts\jquery-1.3.2-vsdoc.js"/>

var lastClicked;

$(document).ready(function() {

    $("#suppList li a").click(function() {
        var href = this.href;
        lastClicked = href;

        $("#suppContent").fadeOut("slow", function() {
            $("#suppContent").html("").addClass("loading");
            $("#suppContent").fadeIn(10);

            $.ajax({
                type: "POST",
                url: "Materials.aspx/GetMaterialsData",
                data: "{'id':'" + href + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    if (lastClicked == href) {
                        $("#suppContent").fadeOut("normal", function() {
                            $("#suppContent").removeClass("loading");
                            $("#suppContent").html(msg.d)
                            $("#suppContent").fadeIn("slow");
                            WireUpLightbox();
                        });
                    }
                }
            });

        });
        return false;
    });

});

function WireUpLightbox() {
    var i = 1;

    $("#suppContent img").each(function() {

        var imgUrl = $(this).url();
        var largeUrl = imgUrl.toString().replace('.jpg', '-large.jpg');

        $(this).wrap("<a class='" + i + "' href='" + largeUrl + "'></a>");
        $("#suppContent a." + i).lightBox();
        i = i + 1;
    });

}