



/* on document ready...
*/
 $(document).ready(function() {


	



	$("form.add_to_cart").bind("submit", function(e){

		var form = this;

		$.blockUI({
			message:
				'<h1><img src="/images/busy.gif" />' + 
				'Please wait... adding selected item(s) to cart</h1>',
			css: {
				width: '275px',
				border: 'none',
				padding: '15px',
				backgroundColor: '#2D2D9B',
				'-webkit-border-radius': '10px',
				'-moz-border-radius': '10px',
				opacity: '.8',
				color: '#fff'
			}
		});



		var qty = this.qty.value;
		var stockcode = this.productid.value;


		$("#cart_embedded_div").html("refreshing");

		$.ajax({
			type: "POST",
			cache:false,
			url: "/cart_action.php",
			data: "stockcode=" + stockcode + "&qty=" + qty + "&action=add_item",
			error: function (e,a,b,c) {
				
				$.unblockUI();
				alert('Error doing manual submit: ' + e.status + ": " + e.statusText);
				if (form && form.submit) form.submit();
				
			},
			success: function(msg){

				// show updated cart
				$("#cart_embedded_div").html(msg);

				// notify user
				$.blockUI({
					message:
						"<h1>Item(s) successfully added to cart</h1>\n" +
						"<input type=\"button\" id=\"ok_atc\" value=\"Close\" />",
					css: {
						width: '275px',
						border: 'none',
						padding: '15px',
						backgroundColor: '#2D2D9B',
						'-webkit-border-radius': '10px',
						'-moz-border-radius': '10px',
						opacity: '.8',
						color: '#fff' }
				});

				// handle ok button in dialog
				$('#ok_atc').click(function() {
					$.unblockUI();
					return false;
				});


				setTimeout($.unblockUI, 5000);
			}
		});
		return false;
    });



})
