$(document).ready(function(){ 

	
	//Functions to Add To Basket

	$("#basketItemsWrap li:first").hide();
	$(".productPriceWrapRight a img").click(function() {
													 
											 
		var partNoValSplitter 	= (this.id).split("_");
		var partNoVal 			= partNoValSplitter[1];
	
		//$("#notificationsLoader").html('<img src="/clearance/graphics/loader.gif" />');
	
	
		$.ajax({
		type: "POST",
		url: "/clearance/includes/ecomm_functions.php",
		data: { partNo: partNoVal, quantity: "1", action: "addToBasket"},
		success: function(theResponse) {
	
			if( $("#partNo_" + partNoVal).length > 0){
				$("#partNo_" + partNoVal).animate({ opacity: 0 }, 500, function() {
					$("#partNo_" + partNoVal).before(theResponse).remove();
				});
				$("#partNo_" + partNoVal).animate({ opacity: 0 }, 500);
				$("#partNo_" + partNoVal).animate({ opacity: 1 }, 500);
				$("#notificationsLoader").empty();
			} else {
				$("#basketItemsWrap li:first").before(theResponse);
				//$("#basketItemsWrap li:first").hide();
				//$("#basketItemsWrap li:first").show("slow");
				//$("#notificationsLoader").empty();
			}
	
		}
		
		}); 
		
		
				
		var subTotalHTML = $.ajax({
		type: "POST",
		url: "/clearance/includes/ecomm_functions.php?action=subTotal",
		data: { action: "subTotal"},
		success: function(theResponse) {

				$('#weecart_total').animate({ opacity: 0 }, 500, function() {
					$('#weecart_total').before(theResponse).remove();
				});
				$('#weecart_total').animate({ opacity: 0 }, 500);
				$('#weecart_total').animate({ opacity: 1 }, 500);	
				} 
				
			//
				
			   
			   
		}); 
			   
		

	
	});
	
	
		$("#oBuyButton a img").click(function() {
													 
											 
		var partNoValSplitter 	= (this.id).split("_");
		var partNoVal 			= partNoValSplitter[1];
		var quantity = parseInt($('#oBuyButton #' + partNoVal).val());
		
		//alert (quantity);

	
		//$("#notificationsLoader").html('<img src="/clearance/graphics/loader.gif" />');
	
	
		$.ajax({
		type: "POST",
		url: "/clearance/includes/ecomm_functions.php",
		data: { partNo: partNoVal, quantity: quantity, action: "addToBasket"},
		success: function(theResponse) {
	
			if( $("#partNo_" + partNoVal).length > 0){
				$("#partNo_" + partNoVal).animate({ opacity: 0 }, 500, function() {
					$("#partNo_" + partNoVal).before(theResponse).remove();
				});
				$("#partNo_" + partNoVal).animate({ opacity: 0 }, 500);
				$("#partNo_" + partNoVal).animate({ opacity: 1 }, 500);
				$("#notificationsLoader").empty();
			} else {
				$("#basketItemsWrap li:first").before(theResponse);
				//$("#basketItemsWrap li:first").hide();
				//$("#basketItemsWrap li:first").show("slow");
				//$("#notificationsLoader").empty();
			}
	
		}
		
		}); 
		
		
				
		var subTotalHTML = $.ajax({
		type: "POST",
		url: "/clearance/includes/ecomm_functions.php?action=subTotal",
		data: { action: "subTotal"},
		success: function(theResponse) {

				$('#weecart_total').animate({ opacity: 0 }, 500, function() {
					$('#weecart_total').before(theResponse).remove();
				});
				$('#weecart_total').animate({ opacity: 0 }, 500);
				$('#weecart_total').animate({ opacity: 1 }, 500);	
				} 
				
			//
				
			   
			   
		}); 
			   
		

	
	});	
	
	//Functions to Delete From Basket
	
	$("#basketItemsWrap li img").live("click", function(event) { 
														
		var partNoValSplitter 	= (this.id).split("_");
		var partNoVal 			= partNoValSplitter[1];	
	
		//$("#notificationsLoader").html('<img src="/clearance/graphics/loader.gif" />');
	
		$.ajax({  
		type: "POST",  
		url: "/clearance/includes/ecomm_functions.php",  
		data: { partNo: partNoVal, action: "deleteFromBasket"},  
		success: function(theResponse) {
			
			$("#cart #" + partNoVal).hide(function() {$(this).remove();});
			$("#partNo_" + partNoVal).hide(function() {$(this).remove();});
			//$("#notificationsLoader").empty();
		
		}  
		});  
		
		
		var subTotalHTML = $.ajax({
		type: "POST",
		url: "/clearance/includes/ecomm_functions.php?action=subTotal",
		data: { action: "subTotal"},
		success: function(theResponse) {

				$('#weecart_total').animate({ opacity: 0 }, 500, function() {
					$('#weecart_total').before(theResponse).remove();
				});
				$('#weecart_total').animate({ opacity: 0 }, 500);
				$('#weecart_total').animate({ opacity: 1 }, 500);	
				} 
				
			//
				
			   
			   
		}); 
		
	});
	
	


});

