function initShop() {
	var Shop = new shop('MailItem','MailQuantity','price','price-sub','shipping','shipping-sub','sum');
}

function shop(item,quantity,price,price_sub,shipping,shipping_sub,sum) {
	this.itemInput = $(item);
	this.quantityInput = $(quantity);
	this.priceField = $(price);
	this.priceSubField = $(price_sub);
	this.shippingField = $(shipping);
	this.shippingSubField = $(shipping_sub);
	this.sumField = $(sum)

	this.price = parseFloat(this.priceField.innerHTML,10);
	this.shipping = parseFloat(this.shippingField.innerHTML,10);
	this.quantity = parseInt(this.quantityInput.value,10);

	var self = this;
	this.itemInput.observe('change',function() {self.getPrice(this)});
	this.quantityInput.observe('change',function() {self.reCalculate(this)});
}

shop.prototype.getPrice = function(inputobject) {
	var url = www_root+'publications/view/'+inputobject.value+'.json';
	var self = this;
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			self.updatePrice(transport)
		}
	});
}

shop.prototype.updatePrice = function(obj) {
	var json = obj.headerJSON;
	this.shipping = parseFloat(json.Publication.shipping,10);
	this.price = parseFloat(json.Publication.price,10);
	this.priceField.update(this.formatPrice(this.price));
	this.priceSubField.update(this.formatPrice(this.price*this.quantity));
	this.shippingField.update(this.formatPrice(this.shipping));
	this.shippingSubField.update(this.formatPrice(this.shipping*this.quantity));
	this.sumField.update(this.formatPrice((this.price*this.quantity)+(this.shipping*this.quantity)));
}

shop.prototype.reCalculate = function(inputobject) {
	this.quantity = parseInt(inputobject.value,10);
	this.sumField.update(this.formatPrice((this.price * this.quantity) + (this.shipping * this.quantity)));
	this.priceSubField.update(this.formatPrice(this.price * this.quantity));
	this.shippingSubField.update(this.formatPrice(this.shipping * this.quantity));
}

// function parsePrice(str) {
// 	if (str.match(/^\d*,\d*$/)) {
// 		str = str.replace(/^(\d*)(,)(\d*)$/,'$1.$3');
// 	}
// 	return parseFloat(str,10);
// }

shop.prototype.formatPrice = function(s) {
		str = new String(s);
		if (str.match(/^\d*$/)) {
			str = str.replace(/(^\d*$)/,'$1.00');
		}
		return str;
}

HELPERS.addLoadEvent(initShop);