$(document).ready(function() {

	$("#customer_details_wrap table input").unbind();

	$("#products td").each(function() {
		var tdh = $(this).height();
		$(this).children(".product_data").height((tdh-45));
	});
	
	/* $("#minicart tr:not([class=minicart_totals]):odd td").css("background", "#eee"); */
	
	$("#product_tabs ul a").click(function() {
		$("#product_tabs ul a").removeClass("active");
		$(this).addClass("active");
		$(".showhide").hide();
		$("#"+ $(this).attr("rel")).show();
		return false;
	});	
	
	$("img").mousedown(function(event) {
		switch(event.which) {
			case 3: alert("All images copyright Bonsai Direct. If you would like to use our images, please contact us."); break;
		}
	});
	
	$("img").bind("contextmenu", function(e) {
		e.preventDefault();
		return false;
	});
	
	$(".additional_pending").click(function() {
		$that = $(this);
		$.ajax({
			type: "GET",
			url: "/custom/addons/add_additional.php",
			data: "id="+ $that.attr("rel"),
			success: function(e) {
				$that.val("ADDED").addClass("additional_added");
				$that.click(function() { return false; });
				$("#minicart").replaceWith(e);
			}
		});
		return false;
	});
	
	
	
	/* New checkout functionality.*/
	
	if($("form[name=cart] table.cart").length > 0) {
		
		$("table.cart td.cart_quantity input:not(:hidden)").after('<input type="submit" class="update" name="update_basket" value="Update" />');
		
		$("table.cart td.cart_remove input.checkbox").change(function() { $("input[name=update_basket]").trigger("click"); });
		
		$("#delivery_charge").live("load", function() { $(this).find("tr.cart_total:not(.final)").hide(); });
		
	}
	
	$("#promo_code").before("Promotional Code:");
	
	
	
	/* Cycle. */
	
	$("#top_banner, #mid_banner").cycle();
	
	
	
	/* Paging. */
	
	var thead = $("#products:not(.home) thead th").html();
	if(thead) {
		var tfoot = '<tfoot><tr><th colspan="3">'+thead+'</th></tr></tfoot>';
		$("#products:not(.home)").append(tfoot);
	}

});
