var ShoppingCart = {
	add: function(id, amount) {
		url= '/shopping-cart/add/'+id+'/'+amount;
		if(arguments[2]=="full") {
			url+='?mode=full'
			//jQuery('#shoppingcart-sums').fadeTo("slow", 0.33,function() { jQuery('#shoppingcart-sums').fadeTo("slow",1.0); });
			jQuery('#maincontent').slideUp("normal");
		}
		jQuery.getJSON(url,ShoppingCart.updateJSON);

		if(jQuery('#order_cd_button_' + id )) {
			jQuery('#order_cd_button_' + id).animate({opacity:0.5}, 800); 
			jQuery('#order_cd_button_' + id).animate({opacity:1.0}, 800); 
		}

		return true;
	},
	
	remove: function(id) {
		jQuery('#maincontent').slideUp("normal",function() {jQuery.getJSON('/shopping-cart/remove/'+id,ShoppingCart.updateJSON)});
		return true;
	},

	updateJSON: function(data) {
		if(data["shoppingcart"]!="") {
			jQuery('#shoppingcart-wrapper').fadeTo("slow", 0.33,function() {
				jQuery('#shoppingcart').html(data["shoppingcart"]); 
				jQuery('#shoppingcart-wrapper').fadeTo("slow",1.0); 
			});
		}
		if(data["maincontent"]!="") {
			jQuery('#maincontent').html(data["maincontent"]);
			jQuery('#maincontent').slideDown("normal");
		}
		if(data["shoppingcart-sums"]!="") {
			jQuery('#shoppingcart-sums').html(data["shoppingcart-sums"]);
		}

		if(data["couponWrapper"]!="") {
			jQuery('#coupon-wrapper').fadeTo("slow", 0.33,function() {
				jQuery('#coupon-wrapper').html(data["couponWrapper"]); 
				jQuery('#coupon-wrapper').fadeTo("slow",1.0); 
			});
		}

		if(data["couponError"]!="") {
			jQuery('#couponError').html(data["couponError"]);
		}
	},

	getShippingCosts: function(type,country,payment) {
		jQuery('#shippingcosts').load('/shopping-cart/getShippingCosts?TYPE='+type+'&COUNTRY='+country+"&PAYMENT="+payment, 
			null, function(responseText, textStatus, XMLHttpRequest) {
				jQuery(this).prepend("+");
			});
	},

	addCoupon: function() {
		if(arguments[0]) {
			code=arguments[0];
		}
		else {
			code=jQuery('#couponCode').attr("value");
		}
		jQuery('#maincontent').slideUp("normal");
		jQuery.getJSON('/shopping-cart/setCoupon/'+code,ShoppingCart.updateJSON);

		return true;
	},

	removeCoupon:function() {
		jQuery('#maincontent').slideUp("normal");
		jQuery.getJSON('/shopping-cart/removeCoupon',ShoppingCart.updateJSON);

		return true;
	}
}
