$(document).ready(function() {

    jQuery.fn.blink =
        function() {
            this.each(function() {
                $(this).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
            });
        }

	$('.cart-item-add').each(function() {
		if ($(this).attr('item_id')) {
			$(this).click(function(e) {
				e.preventDefault();
				e.stopPropagation();

				$.post(
						'/cart/add.html',
						{
							item_id: $(this).attr('item_id')
						},
						function(data, textstatus) {
							if (data.error) {
								alert(data.error);
								return;
							}

							if (data.ok) {
								window.location = '/cart/';
								return;
							}

							alert('Unkown server response');
						},
						'json'
				);
			});
		}
	});
})
