function UpdateCart()
{
	$("#ajaxcart").html("<div align='center'><img src='"+domain+"/img/loading.gif'><"+"/div>");
	UpdatePanelLayout( $("#cartpanel") );
	
	var xmlhttp = GetXmlHttpRequest();
	if (!xmlhttp)
		location.href = domain+"/carrello/"+id;
	else
	{
		xmlhttp.open("GET", domain+"/pages/ajaxcart/updatecart.php", true);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				$("#ajaxcart").html( xmlhttp.responseText );
				UpdatePanelLayout( $("#cartpanel") );
			}
		}
		
		xmlhttp.send(null);
	}
}

function AddToCart(link, id)
{
	var ajaxcart = $("#ajaxcart");
	ajaxcart.html("<div align='center'><img src='"+domain+"/img/loading.gif'><"+"/div>");
	UpdatePanelLayout( $("#cartpanel") );
	
	var img_prodotto = $(link).parent().parent().find("img").eq(0);
	var cart_offset = ajaxcart.offset();
	
	var cloned_img_prodotto = img_prodotto.clone();
	cloned_img_prodotto.css("opacity", "0.4");
	cloned_img_prodotto.css("filter", "alpha(opacity=40)");
	cloned_img_prodotto.css("position", "absolute");
	cloned_img_prodotto.css("top", img_prodotto.offset().top + "px");
	cloned_img_prodotto.css("left", img_prodotto.offset().left + "px");
	$(document.body).append(cloned_img_prodotto);
	
	cloned_img_prodotto.animate( {top: cart_offset.top+"px", left: cart_offset.left+"px"},
		{duration: "slow", easing: "swing", complete: function() { $(this).remove(); }} );
	
	var xmlhttp = GetXmlHttpRequest();
	if (!xmlhttp)
		location.href = domain+"/carrello/"+id;
	else
	{
		xmlhttp.open("GET", domain+"/pages/ajaxcart/addtocart.php?id="+id, true);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
				UpdateCart();
		}
		
		xmlhttp.send(null);
	}
}

function RemoveFromCart(id)
{
	$("#ajaxcart").html("<div align='center'><img src='"+domain+"/img/loading.gif'><"+"/div>");
	UpdatePanelLayout( $("#cartpanel") );
	
	var xmlhttp = GetXmlHttpRequest();
	if (!xmlhttp)
		location.href = domain+"/carrello/remove/"+id;
	else
	{
		xmlhttp.open("GET", domain+"/pages/ajaxcart/removefromcart.php?id="+id, true);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
				UpdateCart();
		}
		
		xmlhttp.send(null);
	}
}
