
function setImage(caption, lgImage, xlImage) {
    if (xlImage.length < 1) {
        $("#magnifyDiv").hide();
        $("#productImg").removeClass("clickableProductImg");
        $("#photovid-content #productImg").unbind("click");
    } 
    else {
        $("#magnifyDiv").show();
             if(!$("#productImg").hasClass("clickableProductImg")) {
                 $("#productImg").addClass("clickableProductImg");
                 $("#photovid-content #productImg").click(function () { $('#magnifyLink').trigger("click") });
            }
    }
    // show magnifying glass
    $("#photoContent").show();
    // set images to hidden form element
    $("#product-image-lg").val(lgImage);
    $("#product-image-xl").val(xlImage);
    // reset toggle if image is zoomed out when switching product photos
    if ($("#magnifyLink #magnifyImg").attr("src").indexOf("zoomOut.png") != -1) {
	    $('#magnifyLink').trigger("click");
	}
    // remove video
    $("#video-content").html("");
    // set product caption
    $("#photovid-content h2").html(caption);
    // set product image
    $("#photovid-content #productImg").attr({ "src": lgImage, "alt": caption });
}
var zoomIn = function() {
    $("#magnifyLink #magnifyImg").attr({ "src": zoomOutGraphic, alt: "zoom out" });
    $("#photovid-content #productImg").attr("src", $("#product-image-xl").val());
}
var zoomOut = function() {
    $("#magnifyLink #magnifyImg").attr({ "src": zoomInGraphic, alt: "zoom in" });
    $("#photovid-content #productImg").attr("src", $("#product-image-lg").val());
}
$(document).ready(function () {
    // set magnify button toggle
    $('#magnifyLink').toggle(zoomIn, zoomOut);
    // add click handler to thumbnails
    $('#thumbnails li a').click(function () {
        // remove all borders from thumbnails
        $('#thumbnails li a').attr("style", "border:1px solid #EAEAEA");
        // add border to this thumbnail
        $(this).attr("style", "border:1px solid blue");
    });
    // add border to this thumbnail when clicked
    $('#thumbnails li a').click(function () {
        $(this).attr("style", "border:1px solid #000");
    });
    // hide magnifying glass 
    if ($("#productImg").attr("src").indexOf("1X1.gif") != -1) {
        $("#photoContent").hide();
    }
    eval($("div#photos ul#thumbnails li:first-child a").attr("href"));
});
