$(document).ready(function(){ 

	$("#basketItemsWrap li:first").hide();
	
	$(".productPriceWrapRight a img").click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];
	
		$("#notificationsLoader").html('<img src="images/loader.gif">');
		
		$.ajax({  
		type: "POST",  
		url: "inc/functions.php",  
		data: { productID: productIDVal, action: "addToBasket"},  
		success: function(theResponse) {
			var theResponseVal = theResponse.split("/systx/");
			var theResponsebande = theResponseVal[0];
			var totalVal = theResponseVal[1];
			var totalPanier = theResponseVal[2];
			
			if(theResponsebande=="erreur"){
				$("#resto_panier").hide(1000);
				$("#erreurresto").show("slow");
				$("#notificationsLoader").empty();
			}else{
				if( $("#productID_" + productIDVal).length > 0){
					$("#productID_" + productIDVal).animate({ opacity: 0 }, 500, function() {
						$("#productID_" + productIDVal).before(theResponsebande).remove();
					});
					$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
					$("#productID_" + productIDVal).animate({ opacity: 1 }, 500);		
				} else {
					$("#basketItemsWrap li:first").before(theResponsebande);
					$("#basketItemsWrap li:first").hide();
					$("#basketItemsWrap li:first").show("slow");  		
				}
				
				$("#totalvaleur").html(totalVal);
				$("#sumpanier").html(totalPanier);
				$("#notificationsLoader").empty();
				
			}
			
		}  
		});
	});
	
	
	
	$("#basketItemsWrap li img").live("click", function(event) { 
														
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];	
	
		$("#notificationsLoader").html('<img src="images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "inc/functions.php",  
		data: { productID: productIDVal, action: "deleteFromBasket"},  
		success: function(theResponse) {
			
			var theResponseVal = theResponse.split("/systx/");
			var theResponse1 = theResponseVal[0];
			var theResponse2 = theResponseVal[1];
			$("#productID_" + productIDVal).hide("slow",  function() {$(this).remove();});
			$("#totalvaleur").html(theResponse1);
			$("#sumpanier").html(theResponse2);
			$("#notificationsLoader").empty();	
			
		}  
		});  
		
	});
	
	

});

