jQuery(function() {	
				

	
	$(".trCart2").each(function (){
		var form = $(this).children('form');
		var url  = $(this).children('form').attr('action'); 
		
		var id = 0;
		$(".trCart2 .aggiungi").each(function(){
			id++;
			$(this).attr({'id':'img_'+id}) 
		});
		//bottone aggiungi		
		$(this).find('.plusQuantity').click(function(){	
			 									
			quantity = $(this).prev(".quantita").val();
			quantity = parseInt(quantity) + parseInt(1)
			if (quantity < 1){
				quantity = 1;
			}
			$(this).prev(".quantita").val(quantity);
		});
		
		//bottone  diminuisci		
		$(this).find('.moinsQuantity').click(function(){
			quantity = $(this).prev().prev(".quantita").val();
			quantity = parseInt(quantity) + parseInt(-1)
			if (quantity < 1){
				quantity = 1;
			}
			$(this).prev().prev(".quantita").val(quantity);								  
		});
		
		
		
		$(this).find(".aggiungi").click(function () {
			var str = null;	
			
			
			
			str = $(form).serialize();	

			$.post("js/cart/query.php",str, function(j){
					 $('#carrellodestra p span').empty();
					$('#carrellodestra p span').html(j);	
					//return true;
					//location.href = url;
					//alert(j);
					
			});//chiusura post

			$.add3cart($(this).attr('id'),'carrellodestra');			
			return false;
		});
		
		
		
		
		$(this).find(".deleteItem").click(function (e) {
			var str = null;	
			str = "type=delete&"+$(form).serialize();	
			
			$.post("js/cart/query.php",str, function(j){		
					//$('#carrelloHeader p span').html(j);
					location.href = url;
			});//chiusura post
			return true;
			//$.add2cart('addPhoto','carrelloHeader');
		});
		
		
		$(".reset").click(function (e) {

			var str = null;	
			str = "type=reset&";	
			$.post("js/cart/query.php",str, function(j){		
					//$('#carrelloHeader p span').html(j);
					//$('.trCart2').remove();					
					location.href = url;
			});//chiusura post	
			return true;
			//$.add2cart('addPhoto','carrelloHeader');
		});
		
		
	
		//add ITEM
		$("#addProducts").click(function () {
				
			var str = null;	
			str = $("form[name='cartForm']").serialize();
			
			//alert(str);
			
			$.post("js/cart/query.php",str, function(j){
							//alert(j);						 
					$('#carrellodestra p span').html(j);	
					return false;
			});//chiusura post
		
			$.add2cart('addProducts','carrellodestra');
		
			return false;	
		});
		
		
	})
	
})
