Ajax.Responders.register({
	onCreate: function() {
		if($('systemWorking') && Ajax.activeRequestCount> 0)
			Effect.Appear('systemWorking',{duration: 0.25, queue: {position:'front', scope:'systemWorking', limit: 50}});
	},
	onComplete: function() {
		if($('systemWorking') && Ajax.activeRequestCount == 0)
			Effect.Fade('systemWorking',{duration: 0.25, queue: {position:'end', scope:'systemWorking', limit: 50}});
	}
});

var total = 0;

function removeFromCart(id) {

	if($('checkout_itemName_'+id)) $('checkout_itemName_'+id).innerHTML = "Deleting...";
	$('itemName_'+id).innerHTML = "Deleting...";

	var url = 'ajax/removeFromCart.php';
	var pars = 'id=' + id;

	new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: function(transport) { _removeFromCartComplete(transport, id); } });		
	
}

function _removeFromCartComplete(transport, id) {
	
	var done = updateDone(transport, 'topResponse', 'Deleted product from box');
	if(!done) return false;

	total -= transport.responseText;
	if($('shippingPrice')) {
		total -= shippingAmount;
	}
	
	if($('checkout_item_'+id)) $('checkout_item_'+id).style.display = "none";
	$('item_'+id).style.display = "none";

	updatePrice();

}

function updatePrice() {
	if($('subTotal')) {
		$('subTotal').innerHTML = "$" + total.toFixed(2);
		if(total >= shippingFree) {
			$('shippingNote').innerHTML = "For spending more than $"+shippingFree.toFixed(2)+"<br />you have received free shipping!";
			$('shippingPrice').innerHTML = "$0.00";
			
		} else {
			$('shippingNote').innerHTML = "If you spend more than $"+shippingFree.toFixed(2)+"<br />you will receive free shipping!";
			$('shippingPrice').innerHTML = "$" + shippingAmount.toFixed(2);
			total += shippingAmount;
		}
		$('totalPrice').innerHTML = "$" + total.toFixed(2);
	}
}