/* Amsta Cart */
var cart_url="/cart";

function cartUpdate(id, q, d)
{
	$("loading").show();
  new Ajax.Request(cart_url+"/update", 
	{
		method: "GET",
		parameters: {"id": id, "d": d, "q": q},
		onSuccess: function (transport)
		{
			$("cart_info").update(transport.responseText);
			$("loading").hide();
			top.location.href="/cart";
		},
		onFailuer: function()
		{
			$("loading").hide();
		  alert("Cart ERROR !");
		}
	}
	);
}

function addToCart(id)
{
  cartUpdate(id, -1, 1);
  
  carte_img = $("img_carte_"+id);
  
  //new Effect.Scale("img_carte_"+id, 10, { duration: 0.9 });
  
  /*
  // fly the book now
  carte_img = $("img_carte_"+id);
  carte_pos=carte_img.cumulativeOffset();
  
  cart_el = $("cart_icon");
  cart_pos = cart_el.cumulativeOffset();

  moveToX = parseInt(cart_pos[0] - carte_pos[0]);
  moveToY = parseInt(cart_pos[1] - carte_pos[1]);
  new Effect.Scale(carte_img, 10, { duration: 1 });
  return;
	  new Effect.Opacity("img_carte_"+id, 
	  	{
	  		to: 0.2,
	  		from: 1.0,
	  		sync: true,
	  		duration: 1
	  	});
  return;
  
  new Effect.Parallel(
  	[
	  new Effect.MoveBy("img_carte_"+id, moveToY, moveToX, {
		beforeStart: function(e) {
			//Element.addClassName($('channel_20'), 'demo')
		},
		afterFinish:function(e) {
			//replaceTab('channel_20', 1)
			//Element.removeClassName($('channel_20'), 'demo')
	  	},
	  	sync: true,
	  	}),
	  new Effect.Opacity("img_carte_"+id, 
	  	{
	  		to: 0.2,
	  		from: 1.0,
	  		sync: true
	  	})
	 ],
	 {
	 	duration: 0.7
	 }
	);
  //new Effect.MoveBy('channel_20', -1*moveToY, -1*moveToX, {duration: 0.5, queue:'end'});
  //alert(cart_pos[0]+" "+cart_pos[1]);
  //alert(carte_pos[0]+" "+carte_pos[1]);
  */
}

function updateCart(id, q)
{
  cartUpdate(id, q, 0);	
}

function removeFromCart(id)
{
	updateCart(id, 0, 0);
}

function golesteCart()
{
	$('cart_action').value='clean'; 
	$('cartForm').submit();
}

function comandaCart()
{
	$('cart_action').value='comanda';
	$('cartForm').submit();
}

function actualizeazaCart()
{
	$('cartForm').submit();
}
