var count = 0;
var maxColours = 0;

$(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("");
    }});   
    
    maxColours = $("#colourList > div").size(); // Find the amount of colour options for the product
    
    $("#colourRightArrow").click(function() {
        if ((count + 5) < maxColours) {
            // $("#colourList").animate({ left: '-=95' });
            /*$(".productColour:visible:first").animate({ width: '0px' }, function() {
				$(this).hide();
			});*/
			$(".productColour:visible:first").hide();
            count++;
        }
    });

    $("#colourLeftArrow").click(function() {
        if (count > 0) {
            // $("#colourList").animate({ left: '+=95' });
            $(".productColour:hidden:last").show();
            count--;
        }
    });
});

function showPreviewImage(s) {
	//$.get(
	var prevHtml;
	prevHtml = '<div style="text-align: center"><br />'+s+'';
	prevHtml += '<br />Example of Colour</div>';
	t1 = window.setTimeout(function() {
		$('#colourPreview').html(prevHtml);
		$('#colourPreview').toggle();
	}, 300);
	t2 = window.setTimeout(function() {
		$('#colourPreview').fadeOut();
	}, 3000);
}
