$(function() {
    $('#productGalleryImages li:first').addClass("selected");

    // setup modal dialog
    $('#dialog').dialog({autoOpen: false, width: 600, bgiframe: true, buttons: {
        "Ok": function() {
            $(this).dialog("close");
        }        
    }});

    $('a.closeDialogOnClick').livequery("click", function(event) {
    	$('#dialog').dialog("close");
    });
    
    $("#largeImageContainer a").lightBox({imageBtnClose: WEB_ROOT + "/presentation/images/frontend/lightbox/lightbox-btn-close.gif",
                                          imageLoading: WEB_ROOT + "/presentation/images/frontend/lightbox/lightbox-ico-loading.gif",
                                          imageBtnPrev: WEB_ROOT + "/presentation/images/frontend/lightbox/lightbox-btn-prev.gif",
                                          imageBtnNext: WEB_ROOT + "/presentation/images/frontend/lightbox/lightbox-btn-next.gif"});

  	$('#productGalleryImages li a').click(function(event) {
		event.preventDefault();

        var href = $(this).attr("href");

        $("#largeImageContainer img").ImageSwitch({Type:"FadeIn", NewImage:$(this).attr("href"), Direction:"DownTop", EffectOriginal: false});
        $("#largeImageContainer a").attr("href", href);
        $(this).parent().parent().find("li.selected").removeClass("selected");
        $(this).parent().addClass("selected");
  	});

    $('#cartForm').ajaxForm({url: location.href, data: {requestType:"ajax"}, success: function(response, status) {
        $('#dialog').html(response);
        $('#dialog').dialog("open");
	$("#cartForm table tr td input[@type='checkbox']").attr("checked", false);
	$("#cartForm table tr td.qty input").val("");
    }});    
});
