var basket = {
		
	init: function() {
		// bind to quantity buttons
		$('input.additem').live('click', function() {
			basket.additem($('input[name*="productid"]', $(this).parent()).val());
			return false;
		});
		$('input.removeitem').live('click', function() {
			basket.removeitem($('input[name*="productid"]', $(this).parent()).val());
			return false;
		});
	},
	
	additem: function(productid) {
		$.ajax({
			url: '/ajax/basket.php',
			data: 'mode=additem&productid=' + productid,
			success: function(xml) {
				switch ($("status", xml).text()) {
					case '0':
						alert($("message", xml).text(), 'Error');
						break;
					case '1':
						var bodyhtml = $("body", xml).text();
						$('#basket').html(bodyhtml);
						break;
					default:
						alert('Unexpected Response: ' + $("message", xml).text(), 'Message');
						break;
				}
			},
			error: function(xml, type) {
				alert('There was an error establishing a connection with the server, or the server did not respond as expected. Please check your internet connection and try again.', 'Communication Error (' + type + ')');
			}
		});			
	},
	
	removeitem: function(productid) {
		$.ajax({
			url: '/ajax/basket.php',
			data: 'mode=removeitem&productid=' + productid,
			success: function(xml) {
				switch ($("status", xml).text()) {
					case '0':
						alert($("message", xml).text(), 'Error');
						break;
					case '1':
						var bodyhtml = $("body", xml).text();
						$('#basket').html(bodyhtml);
						break;
					default:
						alert('Unexpected Response: ' + $("message", xml).text(), 'Message');
						break;
				}
			},
			error: function(xml, type) {
				alert('There was an error establishing a connection with the server, or the server did not respond as expected. Please check your internet connection and try again.', 'Communication Error (' + type + ')');
			}
		});			
	},
	
	removeproduct: function(productid) {
		
	}
		
};

var address = {

	init: function() {

	}

};

$(function() {

	basket.init();
	
});
