$(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 DETAILS ------------ /
	/*$(".thumbnail_item a").mouseover(function(){
		$("#click_to_enlarge_link img").attr("src", "/images/ecomm/products/sized/" + $(this).attr("rel"));
		$("#click_to_enlarge_link").attr("href", "/images/ecomm/products/large/" + $(this).attr("rel"));
		$("#ptb_click_to_enlarge_link").attr("href", "/images/ecomm/products/large/" + $(this).attr("rel"));
		$(".thumbnail_item").removeClass("thumbnail_item_main");
		$(this).parent().addClass("thumbnail_item_main");
	});*/
	$(".helpful_yes").click(function(){
		location.href = "/product_rate_helpful.php" + $(this).attr("rel") + "&rating=1";
	});
	$(".helpful_no").click(function(){
		location.href = "/product_rate_helpful.php" + $(this).attr("rel") + "&rating=0";
	});
	
	// VIEW CART --------------/
	$(".remove_item").click(function(){
		location.href = "view_cart.php?remove=" + $(this).attr("rel");
	});

	// 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();
		$("#checkout_processing").show();
		$("#form_checkout").submit();
		return false;
	});
	$("#apply_promo_code").click(function(){
		$("#form_promo_code").submit();
		return false;
	});	
	
	// HOW HEARD --------------/
	$("#how_heard").change(function(){
		if($(this).val() == "Other")
		{
			$("#how_heard_other").show();
			$("#how_heard_other").focus();
		} else {
			$("#how_heard_other").hide();
		}
		return false;
	});	
	
	//GENERAL -------- /
	$(".go_back").click(function(){
		history.go(-1);
		return false;
	});
	$(".print_this").click(function(){
		window.print();
		return false;
	});
	$(".confirm_delete").click(function(){
		return confirm("Are you sure you want to delete this?");
	});
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'overlayOpacity':	0.7,
		'speedIn'		:	300, 
		'speedOut'		:	300, 
		'titlePosition'	:	'over'
	});
	$(".select_rel").each(function(){
		$(this).val($(this).attr("rel"));
	});
	$(".focus_me").focus();
});

