$(document).ready(function(){ 
	$(".cart_add").click( function(){ basket($(this).attr("id")) } );
	
	$(".sizes").change(function(){calculate_price()});
});

function basket(id){
	
	var product = id.split("_")[1];
	var mode = "";
	
	if($("#"+id).attr("class") == "cart_add"){
		$("#"+id).attr("class", "cart_add_wait");
		mode = "add";
	}else{
		$("#"+id).attr("class", "cart_remove_wait");
		mode = "remove";
	}
	
	$.post(
		"ajax.php",
		"action=basket&product="+product+"&mode="+mode+"&"+$("#konfiguracja").serialize(),
		function(response){
			$("#"+id).attr("class", "cart_add");
			if(mode == "remove"){
				response = response.split("||");
				$(".cart_content").html(response[0]);
				$(".small_cart_content").html(response[1]);
			}else{
				$(".small_cart_content").html(response);
			}
		}
	);
	
}

function calculate_price(){
	
	var width = $("#roz_def_szerokosc").val();
	var height = $("#roz_def_wysokosc").val();
	var product = $("#product").val();
	
	$.post(
		'ajax.php',
		'action=calculate_price&product='+product+'&width='+width+'&height='+height,
		function(response){
			$(".product_price").html(response);
		}
	);
	
}
