function ShopBasket()
{
	this._podElem = null;
	this._wrapperElem = null;
	this._controller = '';
	
	this.setPodElem = function(objElem)
	{
		this._podElem = objElem;
	}
	
	this.setWrapperElem = function(objElem)
	{
		this._wrapperElem = objElem;
	}
	
	this.setController = function(strCont)
	{
		this._controller = strCont;
	}
	
	this.addItem = function(objForm)
	{
		if (! objForm) {
			return false;
		}

		caller = this;

		this._toggleButton(objForm.btnSubmit);

		ajax = this._getAjaxObj();
		ajax.setVar('a', 'add');

		if (params = getFormFields(objForm)) {
			for (x in params) {
				ajax.setVar(x, params[x]);
			}
		}
		ajax.onCompletion = function()
		{
			caller.refreshDisplay();
			caller._toggleButton(objForm.btnSubmit);
		}
		ajax.onError = function()
		{
			caller.showError('Could not add item to basket');
			caller._toggleButton(objForm.btnSubmit);
		}
		ajax.runAJAX();
	}

	this.removeItem = function(intIndex, objButton)
	{
		caller = this;

		this._toggleButton(objButton);

		ajax = this._getAjaxObj();
		ajax.setVar('a', 'remove');
		ajax.setVar('index', parseInt(intIndex));
		ajax.onCompletion = function()
		{
			caller.refreshDisplay();
			caller._toggleButton(objButton);
		}
		ajax.onError = function()
		{
			caller.showError('Could not remove item from basket');
			caller._toggleButton(objButton);
		}		
		ajax.runAJAX();
	}

	this.updateItem = function(objForm)
	{
		if (! objForm) {
			return false;
		}
		
		caller = this;

		caller._toggleButton(objForm.btnSubmit);

		ajax = this._getAjaxObj();
		ajax.setVar('a', 'update');

		if (params = getFormFields(objForm)) {
			for (x in params) {
				ajax.setVar(x, params[x]);
			}
		}

		ajax.onCompletion = function()
		{
			caller.refreshDisplay();
			caller._toggleButton(objForm.btnSubmit);
		}
		ajax.onError = function()
		{
			caller.showError('Could not update item');
			caller._toggleButton(objForm.btnSubmit);
		}		
		ajax.runAJAX();
	}

	this.emptyBasket = function()
	{
		caller = this;

		ajax = this._getAjaxObj();
		ajax.setVar('a', 'empty');
		ajax.onCompletion = function()
		{
			caller.refreshDisplay();
		}
		ajax.onError = function()
		{
			caller.showError('Could not empty basket');
		}		
		ajax.runAJAX();
	}

	this.showError = function(errMsg)
	{
		if (this._wrapperElem) {
			this._podElem.style.display = 'block';
			this._wrapperElem.innerHTML = '<p style="font-weight: bold;">' + errMsg + '</p>';
			this.flashBasket();
		}
	}

	this.refreshDisplay = function()
	{
		if (! (this._podElem && this._wrapperElem)) {
			return;
		}
		
		caller = this;
		
		ajax = this._getAjaxObj();
		ajax.setVar('a', 'get-item-count');
		ajax.onCompletion = function()
		{
			if (parseInt(ajax.response) == 0) {
				caller._podElem.style.display = 'none';
			} else {
				ajax2 = caller._getAjaxObj();
				ajax2.setVar('a', 'get-mini-basket');
				ajax2.elementObj = caller._wrapperElem;
				ajax2.onCompletion = function()
				{
					caller._podElem.style.display = 'block';
					caller.flashBasket();
				}
				ajax2.runAJAX();
			}
		}
		ajax.runAJAX();
	}
	
	this.flashBasket = function()
	{
		if (! this._wrapperElem) {
			return;
		}

		this._wrapperElem.style.backgroundColor = '#F4BD8C';
		var myEffect = new Fx.Tween(this._wrapperElem);
		myEffect.start('background-color', '#F68420');
	}

	this._toggleButton = function(objElem)
	{
		if (objElem) {
			objElem.disabled = (objElem.disabled ? false : true);
		}
	}

	this._getAjaxObj = function()
	{
		ajax = new sack();
		ajax.method = "POST";
		ajax.setVar('ajax', 1);
		ajax.requestFile = this._controller;
		return ajax;
	}
}