function add_to_cart(id) {
	if ($('indicator_icon')) Element.show('indicator_icon');
	if ($('cart_content').style.display != "none") hide_cart();
	var myAjax = new Ajax.Updater('cart_contents', '/cart/add_to_cart/'+id, {
		method: 'get',
		onComplete: function() {
			if ($('indicator_icon')) Element.hide('indicator_icon');
			update_total_price();
			slide_cart();
		}
	});
}

function remove_from_cart(id) {
	if ($('updating_cart_indicator')) Element.show('updating_cart_indicator');
	var myAjax = new Ajax.Updater('cart_contents', '/cart/delete_item/'+id, {
		onComplete: function() {
			if ($('updating_cart_indicator')) Element.hide('updating_cart_indicator');
			update_total_price();
		}
	});
}

function update_quantity(deliverable, quantity) {
	if ($('updating_cart_indicator')) Element.show('updating_cart_indicator');
	var params = "id=" + deliverable + "&quantity=" + quantity;
	var myAjax = new Ajax.Updater('cart_contents', '/cart/update_quantity/'+deliverable, {
		method: 'post',
		parameters: params,
		onComplete: function() {
			if ($('updating_cart_indicator')) Element.hide('updating_cart_indicator');
			update_total_price();
		}
	});
}

function load_cart() {
	if ($('indicator_cart')) Element.show('indicator_cart');
	var myAjax = new Ajax.Updater('cart_contents', '/cart/display_cart', {
		method: 'get',
		onComplete: function() {
			if ($('indicator_cart')) Element.hide('indicator_cart');
			update_total_price();
			slide_cart();
		}
	});
}

function slide_cart() {	
	new Effect.SlideDown('cart_content', {
		duration: 0.5,
		afterFinish: function() {
			new Effect.ScrollTo('iamstillalive');
			$('cart_handle_link').className = 'over';
		}
	});
	if ($('flash_notice_wrap').style.display != "none") hide_flash_notice();
}

function show_cart() {
	if ($('indicator_cart')) Element.show('indicator_cart');
	var myAjax = new Ajax.Updater('cart_contents', '/cart/display_cart', {
		method: 'get',
		onComplete: function() {
			if ($('indicator_cart')) Element.hide('indicator_cart');
			slide_cart();
		}
	});
}

function hide_cart() {
	new Effect.SlideUp('cart_content', {
		duration: 0.5,
		afterFinish: function() {
			new Effect.ScrollTo('iamstillalive');
			$('cart_handle_link').className = '';
		}
	});
}

function toggle_cart() {
	if ($('cart_content').style.display == "none") show_cart();
	else hide_cart();
}

function update_total_price() {
	new Effect.Fade('price_total', {duration: 0.2});
	var myAjax = new Ajax.Updater('price_total', '/cart/total_price', {
		onComplete: function() {
			new Effect.Appear('price_total', {duration: 0.2});
		}
	});
}

function hide_flash_notice() {
	new Effect.SlideUp('flash_notice_wrap', {
		duration: 0.5
	});
}
