	
	function ajaxifyAddToCartRefresh() {
		$('.cart-add-item-to-cart').each(function(i){
			var rel = $(this).attr('rel');
			if(global_foodcard_path == undefined) var global_foodcard_path = "/";
			$(this).click(function(e){
				//e.preventDefault();
				$.ajax({
					type	:	'GET',
					dataType:	'text',
					url		:	escape(global_foodcard_path + 'foodcart/add/' + rel + '/ajax/'+new Date().getTime()),
					beforeSend: function() {
						//alert(this.url);
					},
					success	: function(msg){
						$('#cart_setup').remove();
						$('#cart').replaceWith(msg);
						ajaxifyAddToCartRefresh();
						ajaxifyRemoveFromCartRefresh();
						
						//var targetOffset = $('#cart').offset().top;
						//$('html,body').animate({scrollTop: targetOffset}, 1);
						
					},
					error	: function(a,b,c) {
						alert (a+ '\n' + b + '\n' + c);
					}
				});
				return false;
			});
			
		});
	}
	
	
	function ajaxifyRemoveFromCartRefresh() {
		$('.cart-subtract-item-from-cart').each(function(j){
			var rel = $(this).attr('rel');
			if(global_foodcard_path == undefined) var global_foodcard_path = "/";
			$(this).click(function(e){
				//e.preventDefault();
				
				$.ajax({
					type	:	'GET',
					dataType:	'text',
					url		:	escape(global_foodcard_path + 'foodcart/subtract/' + rel + '/ajax/'+new Date().getTime()),
					beforeSend: function() {
						//alert(this.url);
					},
					success	: function(msg){
						$('#cart_setup').remove();
						$('#cart').replaceWith(msg);
						ajaxifyAddToCartRefresh();
						ajaxifyRemoveFromCartRefresh();
					},
					error	: function(a,b,c) {
						alert (a+ '\n' + b + '\n' + c);
					}
				});
				return false;
			});
			
		});
	}

$(document).ready(function(){
	
	// Turn On Ajax Add/Remove to/from Cart
	ajaxifyAddToCartRefresh();
	ajaxifyRemoveFromCartRefresh();
	
});

