$(document).ready(function(){   

	$(".addtobasket").submit(function(){
		
		var addtobasket = $(this);
		
		if ($('#variant').attr("selectedIndex") == 0){
		   alert('Please select a product option'); 
		   return false;
		}
	   
		$.getJSON('/ajax/addtobasket.php', $(this).serialize(), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").animate({opacity: '0'}, 200, function() {
					$("#basketsummary").html(data.basketsummary);
					$("#basketsummary").animate({opacity: '1'}, 200);
			    });
				$("#bigbasketsummary").animate({opacity: '0'}, 200, function() {
					$("#bigbasketsummary").html(data.bigbasketsummary);
					$("#bigbasketsummary").animate({opacity: '1'}, 200);
			    });
				$.prompt('This product has been added to your shopping basket.<br/>'+data.basketsummary,{ 
					buttons:{"checkout now":true, "continue shopping":false},
					overlayspeed: "fast",
					top: "35%",
					callback: function(v){
						if (v) { location.href="/shopping-basket"; }
					}
				});
			}
		});

	});
	$(".plusone").live('click', function(){
		$.getJSON('/ajax/plusonebasket.php?plus='+$(this).attr("rel"), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").html(data.basketsummary);
				$("#bigbasketsummary").html(data.bigbasketsummary);
			}
		});
	});

	$(".removeone").live('click', function(){
		$.getJSON('/ajax/plusonebasket.php?remove='+$(this).attr("rel"), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").html(data.basketsummary);
				$("#bigbasketsummary").html(data.bigbasketsummary);
			}
		});
	});
});
