function setQuantity(form) {

	$.ajax({
		type: "GET",
		url: '/store/ajax/',
		data: $(form).serialize(),
		dataType: 'json',
		cache: false,
		contentType: "application/x-www-form-urlencoded",
		beforeSend: function(jqXHR, settings) {
			//set activity indicator active, overlay the quantity form
			$('.productOverlay .busy', form.parentNode).css('display','block');
			$('.productOverlay .notice', form.parentNode).css('display','none');
			$('.productOverlay', form.parentNode).fadeIn(200);
		},
		success: function(data, textStatus, jqXHR) {
			// remove activity indicator and alert user to success or error - option to view cart
			$('.productOverlay .busy', form.parentNode).css('display','none');
			$('.productOverlay .notice', form.parentNode).css('display','block');
			$('.productOverlay .count', form.parentNode).html(data.count);
			$('.productOverlay a', form.parentNode).attr('href', '/store/cart/?returnPage=' + data.returnPage);
			$('#Cart span').html(data.count);
		},
		error: function(jqXHR, textStatus, errorThrown) {
			alert(errorThrown);
		},
		complete: function(jqXHR, textStatus) {
			// timeout and fade
			setTimeout(function(){ $(".productOverlay", form.parentNode).fadeOut(1000) }, 2000);
		}
	});

}

$(document).ready(function() {

	$('.product,.simpleProduct,.productDetails').each(function() {

		$("form", this).submit(function(event){
			event.preventDefault();
			setQuantity(this);
			return false;
		});

		overlay = document.createElement('div');
		overlay.className = 'productOverlay';
		this.appendChild(overlay);
		html = '<img class="busy" src="/i/busy.gif" width="30" height="30" alt="" />';
		html +='<p class="notice">Item added. <span class="count"></span>&nbsp;items in your cart.</p>';
		html +='<p class="notice"><a href="/store/cart/">View Cart</a>.</p>';
		$('.productOverlay', this).html(html);

	});

});


