$(document).ready(function(){
	//$('.header').corner("top 5px");
	//$(".colorbox").colorbox({width:550, height:600, iframe:true});
	$('.colorbox').die().live('click', function() {
		$.fn.colorbox({href:$(this).attr('href'), width:550, height:600, iframe:true});
		return false;
	});

	var src = $('#purchaseCode :selected').attr("class");
	$("#purchaseImagePreview").html(src ? "<a href=\"viewImage.php?imageId="+$('#purchaseCode').val()+"\" target=\"_blank\" class=\"colorbox\"><img src='showImage.php?image=thumbs/" + src + "' border='0'></a>" : "");
	
	$("#purchaseCheckMessage").html("Please be sure to check purchasing information in this painting's <a href=\"viewImage.php?imageId="+$('#purchaseCode').val()+"\" target=\"_blank\" class=\"colorbox\">gallery page</a> to avoid disappointment.");
	
	$("#purchaseCode").change(function() {
		var src = $('#purchaseCode :selected').attr("class");

        $("#purchaseImagePreview").html(src ? "<a href=\"viewImage.php?imageId="+$('#purchaseCode').val()+"\" target=\"_blank\" class=\"colorbox\"><img src='showImage.php?image=thumbs/" + src + "' border='0'></a>" : "");
		
		$("#purchaseCheckMessage").html("Please be sure to check purchasing information in this painting's <a href=\"viewImage.php?imageId="+$('#purchaseCode').val()+"\" target=\"_blank\" class=\"colorbox\">gallery page</a> to avoid disappointment.");
    });
	
	var x = $("#purchaseCode").val();
	$.ajax({
			type: "GET",
			url: "check_availability.php",
			data: "imageId=" + x,
			dataType: "html",
			success: function(html){
				//$("#debug").html(html);
				$("#purchaseType").html(html);
			},
			error: function(msg){
				alert( "An Error: " + msg );
			}
	});
	
	$("#purchaseCode").change(function()
	{
		var x = $(this).val();
		$.ajax({
				type: "GET",
				url: "check_availability.php",
				data: "imageId=" + x,
				dataType: "html",
				success: function(html){
					//$("#debug").html(html);
					$("#purchaseType").html(html);
				},
				error: function(msg){
					alert( "An Error: " + msg );
				}
		});
	});
	
	$("#purchase").validate();
	$("#form1").validate();
});
