var frontEndBasket = {
	replaceBasket : function(id) {
		return function(e) {
			var text, rem_item = true, item_total_price;
			if (e.summary.amount > 0) {
				text = e.summary.price.actual + ' ' + e.summary.price.suffix + '.';
				for (var i in e.items.item) {
					var item = e.items.item[i];
					if (item.id == id) {
						rem_item = false;
						item_total_price = item["total-price"].actual + ' ' + item["total-price"].suffix + '.';
					}
				}
				if (rem_item) {
					if (jQuery('.cart_item_' + id)) {
						jQuery('.cart_item_' + id).remove();
						jQuery('.cart_summary').text(text);
					}
				}
				else {
					jQuery('.cart_item_price_' + id).text(item_total_price);
					jQuery('.cart_summary').text(text);
				}
				text = e.summary.amount + ' шт товаров на сумму ' + text;
			}
			else {
				text = 'В корзине нет ни одного товара.';
				if (jQuery('.basket')) {
					jQuery('.basket').text(text);
				}
			}
			jQuery('.basket_info_summary').text(text);
		};
	},
	add : function(id) {
		basket.putElement(id, {}, frontEndBasket.replaceBasket(id));
	},
	modify : function(id, amount_new, amount_old) {
		if (amount_new.replace(/[\d]+/) == 'undefined' && amount_new != amount_old) {
			basket.modifyItem(id, {amount:amount_new}, frontEndBasket.replaceBasket(id));
		}
	},
	remove : function(id) {
		basket.removeItem(id, frontEndBasket.replaceBasket(id));
	}
};