$(document).ready(
		function() {
			// configuration Ajax
			initAjax("shoppingcart");
			// Step 1
			initAjaxShoppingCart();
			collapseDescription();
			// Step 2
			$("select.country").change(
					function() {
						var province = $(this).attr('id');
						province = province.replace('country', 'province');
						$.ajax({
							data: {
								action: "ajaxUpdateState",
								countryCode: $(this).val()
							},
							success: function(s) {
								$("#" + province).html('<option value="">Province</option>');
								var jsonObj = $.parseJSON(s, true);
								if (jsonObj != undefined) {
									var lang = $("html").attr("lang");
									for(var i in jsonObj) {
										$("#" + province).append('<option value="' + jsonObj[i].abreviation + '">' + jsonObj[i].name[lang] + '</option>');
									}
								}
							}
						});
					});
			$("#duplicate_address").click(
					function() {
						if($(this).attr('checked'))
							$("#shoppingcart_shipping_firstname").val($("#shoppingcart_billing_firstname").val());
							$("#shoppingcart_shipping_lastname").val($("#shoppingcart_billing_lastname").val());
							$("#shoppingcart_shipping_email").val($("#shoppingcart_billing_email").val());
							$("#shoppingcart_shipping_address").val($("#shoppingcart_billing_address").val());
							$("#shoppingcart_shipping_city").val($("#shoppingcart_billing_city").val());
							$("#shoppingcart_shipping_postalcode").val($("#shoppingcart_billing_postalcode").val());
							$("#shoppingcart_shipping_country").val($("#shoppingcart_billing_country").val());
							$("#shoppingcart_shipping_province").val($("#shoppingcart_billing_province").val());
							$("#shoppingcart_shipping_phone").val($("#shoppingcart_billing_phone").val());
					});
		}
);


function collapseDescription() {
	$('#shoppingcart .containDescription').each(
			function() {
				$(this).append('<img class="collapse" alt="." src="' + BASE_URL + 'skin/img/plus.gif"/>');
				$(this).children('div.description').addClass('closed');
				$(this).children('img.collapse').click(
						function(){
							$(this).prev().toggleClass('closed', 1000);
							if($(this).prev().hasClass('closed'))
								$(this).attr('src', BASE_URL + 'skin/img/min.gif');
							else
								$(this).attr('src', BASE_URL + 'skin/img/plus.gif');
						});
			}
	);
}

/*
function collapseDescription() {
	$('#shoppingcart .containDescription').each(
			function() {
				$(this).children('.description').before('<img class="collapse" alt="." src="' + BASE_URL + 'skin/img/plus.gif"/>');
				$(this).children('.description').addClass('closed');
				$(this).children('img.collapse').click(
						function(){
							$(this).next().toggleClass('closed', 1000);
							if($(this).next().hasClass('closed'))
								$(this).attr('src', BASE_URL + 'skin/img/min.gif');
							else
								$(this).attr('src', BASE_URL + 'skin/img/plus.gif');
						});
			}
	);
}
*/
