$(function(){


	// Move User to the product info
	//$(document).scrollTop(195);
	$('.addtobag').live('click', function(){
			
	
		if($(this).parent().find('input').length){
			var qty = Number($(this).parent().find('input').val());
		} else {
			var qty = Number(1);
		}
		
		var itemPrice = Number($(this).attr('price')) * qty;
		
		
		$.ajax({
			url: 'ajax/add_to_bag.php',
			type: 'POST',
			data: {
				price: $(this).attr('price'),
				pid: $(this).attr('pid'),
				qty: qty
			},
			success: function(data){
				//alert(data);		
			}
		});
		
		
		// The success message is not inside the success function so that there is 
		// no delay when adding products to the basket
		var cartItems = Number($('#cartItems').text()) + qty;
		$('#cartItems').html(cartItems);
		
		var cartTotal = $('#cartTotal').text();
		cartTotal = cartTotal.replace(",", "");
		cartTotal = Number(cartTotal);
		cartTotal = cartTotal + itemPrice;		
		
		
		
		$('#cartTotal').html(cartTotal.toFixed(2));
		
		$('#notice section').html('Item added to your Shopping Basket - ' + cartItems + ' items @ &pound;' + cartTotal.toFixed(2));
		$('#notice')
			.stop(true, true)
			.slideDown()
			.animate({ opacity: 1}, 5000).slideUp();		
		
		
		return false;
	
	});
	

});
