var miniCart = {
	form: null,
	ajaxAction: null,
	viewer: null,
	picker: null,
	
	initialize: function() {
		var addToCartButton = $('addToCartButton');
		if (addToCartButton != null) {
			this.MiniCart = true;
			this.form = addToCartButton.form;
			this.ajaxAction = this.form.ajaxAction.value;
			this.viewer = new easyViewer('ShopBag');
			addToCartButton.onclick = this.buttonHandler;
		}
	},
	
	ajaxSuccess: function(transport) {
		var response = transport.responseText;
		var splitted = response.split('$$$SPLITHERE$$$');
		$('shoppingBag').update(splitted[0]);
		$('ShopBagContent').update(splitted[1]);
		if ($('shopBagAction')) {
			$('shopBagAction').show();
		}
		miniCart.viewer.show();
	},
	
	addToCart: function() {
		if (this.form.pid.value != '' && this.form.availability.value != '' &&  this.form.availability.value != 'NOT_AVAILABLE') {	
			new Ajax.Request(this.ajaxAction, {method:'post', postBody: Form.serialize(this.form), onSuccess: this.ajaxSuccess, onFailure: function() {alert('failure');}});
		} else {
			this.picker.selectionStates.setMessage('force');		
		}
	},
	
	buttonHandler: function() {
		miniCart.addToCart();
		return false;
	}
}

/*document.observe('dom:loaded', function() {
	miniCart.initialize();
});*/
