$(document).ready(function(){
	// PRODUCT OPTIONS ---------- /
	$("#form_choose_options .product_option").change(function(){
		var i = 0;
		var postData = {};

		$("#form_choose_options .product_option option:selected").each(function(){
			postData["option_" + i] = $(this).val();
			i++;
		});
		postData["product_id"]	= $("#form_choose_options #id").val();
		postData["qty"]			= $("#form_choose_options #qty").val();
		$.ajax({
			type:		"POST",
			url:		"/ajax/get_option_info.php",
			data:		(postData),
			async:		false,
			success:	function(xml){
							$(xml).find("element").each(function(){
								var dataId = $(this).find("id").text();
								var dataPriceChange = $(this).find("price_change").text();
								var dataOptionsTotal = $(this).find("options_total").text();
								var dataItemsTotal = $(this).find("items_total").text();
								var dataGrandTotal = $(this).find("grand_total").text();
								$("#form_choose_options #option_cost_" + dataId).html(dataPriceChange);
								$("#form_choose_options #options_total").html(dataOptionsTotal);
								$("#form_choose_options #items_total").html(dataItemsTotal);
								$("#form_choose_options #grand_total").html(dataGrandTotal);
							});
						}
		});
		return false;
	});
	
	// PRODUCT OPTIONS FOR DETAILS ---------- /
	$(".update_options .product_option").change(function(){
		var i = 0;
		var postData = {};
		var theID = $(this).parent().parent().find(".product_id").val();

		$("#form_choose_options_" + theID + " .product_option").find("option:selected").each(function(){
			postData["option_" + i] = $(this).val();
			i++;
		});
		postData["product_id"]	= $("#form_choose_options_" + theID + " .product_id").val();
		postData["qty"]			= $("#form_choose_options_" + theID + " .qty").val();
		$.ajax({
			type:		"POST",
			url:		"/ajax/get_option_info.php",
			data:		(postData),
			async:		false,
			success:	function(xml){
							$(xml).find("element").each(function(){
								var dataId = $(this).find("id").text();
								var dataPriceChange = $(this).find("price_change").text();
								var dataOptionsTotal = $(this).find("options_total").text();
								var dataItemsTotal = $(this).find("items_total").text();
								var dataGrandTotal = $(this).find("grand_total").text();
								$("#form_choose_options_" + theID + " .prod_cost").html(dataGrandTotal);
							});
						}
		});
		return false;
	});
	
	// VIEW CART ---------- /
	$("#form_cart .view_cart_update").click(function(){
		$("#form_cart #action").val("update");
		$("#form_cart").submit();
	});
	$("#form_cart #checkout_button").click(function(){
		$("#form_cart #action").val("checkout");
		$("#form_cart").submit();
	});
	$(".removeItem").click(function(){
		return confirm("Are you sure you want to remove this product from your cart?");
	});
	
	// CHECKOUT ---------- /
	$(".update_shipping_method").change(function(){
		location.href = "/checkout.php?shipping_method_id=" + this.value;
	});
	$("#checkout_place_order_button").click(function(){
		$("#checkout_place_order").hide("fast");
		$("#checkout_processing").show("fast");
		$("#form_checkout").submit();
		return false;
	});
	$("#apply_promo_code").click(function(){
		$("#form_promo_code").submit();
		return false;
	});	
	
	//PRODUCT DETAILS --------/
	$("#search_sort").change(function(){
		location.href = $(this).attr("rel") + $(this).val() + "/";
	});
	
	//GENERAL -------- /
	$(".go_back").click(function(){
		history.go(-1);
		return false;
	});
	$("a.imgZoom").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow':	true,
		'overlayOpacity': .8,
		'hideOnContentClick': true
	});
	$(".print_this").click(function(){
		window.print();
		return false;
	});
	$(".confirm_delete").click(function(){
		return confirm("Are you sure you want to delete this?");
	});
	$("#artist_section").val($("#artist_section").attr("rel"));
	$("#artist_section").change(function(){
		location.href = "artists.php?section=" + $(this).val();
	});
});
