$(function() {
	function change_quantity(amount) {
		amount = amount || 1;

			var quantity = parseInt($('#cart_quantity_display').html());

		quantity += amount;

			if(quantity == 1) {
				$('#items_in_cart_text').html('item in cart');
			} else {
				$('#items_in_cart_text').html('items in cart');
			}

			$('#cart_quantity_display').text(parseInt(quantity));
			$('#cart_button').effect("bounce", {}, 250);
	}

	$('.button_add_to_cart').click(function () {
		var this_button = $(this);
		var product_id		= $(this).attr("product_id");
		var button_text		= $(this).html();
		
		if(button_text == 'Add to Cart'){
			if(product_id > 0){
				$.ajax({
					type: "POST",
					url: "/cart/add_item/" + product_id,
					success: function(msg){
						change_quantity();
						this_button.css({
							'background-color' : '#009933',
							'font-weight' : 'bolder',
							'color' : 'white'
						});
						this_button.addClass('video_buttons_cart_down');
						this_button.html('Checkout');
					}
				});
			}
		} else {
			window.location = '/cart/';
		}
	});
});

