
	function cartUpdateSize(response){
		var _this = this;
		new Ajax.Request(this.siteRoot + '/store/products/index.cfm?action=ajaxcartsize',
			{'onSuccess' : 
				function (response){
					$('cartSize').innerHTML = response.responseText;
				},
			'onFailure' : 
				function (response){
					alert(response.responseText);
					_this.stopLoading();
				}
		});
	}

	function cartUpdateTotal(response){
		var _this = this;
		new Ajax.Request(this.siteRoot + '/store/products/index.cfm?action=ajaxcarttotal',
			{'onSuccess' : 
				function (response){
					$('cartTotal').innerHTML = response.responseText;
				},
			'onFailure' : 
				function (response){
					alert(response.responseText);
					_this.stopLoading();
				}
		});
d	}


	function cartDisplayMessage(message){
		alert(message);
	}
	
	function cartResetPosition(){
		//this.cartObj.style.top = Position.cumulativeOffset($('cartLink'))[1] + 'px';		
		//this.cartObj.style.left = Position.cumulativeOffset($('cartLink'))[0] + 'px';	
	}
	function cartReportError(errorMessage){
		this.contents.innerHTML = errorMessage;
	}

	function cartUpdateSummary(){
		if (!this.loading){
			this.startLoading();
			var _this = this;
			new Ajax.Request(this.siteRoot + '/store/products/index.cfm?action=ajaxcartsummary',
				{'onSuccess' : 
					function (response){
						_this.stopLoading();
						_this.contents.innerHTML = response.responseText;
					},
				'onFailure' : 
					function (response){
						_this.stopLoading();
						_this.reportError(response.responseText);
					}
			});
		}
	}

	function cartPreview() {
		this.show();
		this.updateSummary();
	}

	/*Cart Summary functions*/
	function cartUpdate(cartid,qty){
		this.show();
		this.startLoading();
		var _this = this;
		var a = new Ajax.Request(this.siteRoot + '/store/products/index.cfm?action=ajaxupdatecart' + '&cartid=' + cartid + '&qty=' + qty,
		{
		'onSuccess' : 
			function(response){
				_this.updateSize();
				_this.updateTotal();				
				_this.stopLoading();
				_this.updateSummary();
		}
		,'onFailure' : 
			function (response){
				_this.stopLoading();
				_this.reportError(response)
			}
		});
	}

	function cartShow(response){
//		if (this.cartObj.style.display != 'block')
		//	new Effect.Appear(this.cartObj,{duration: 0.4});
		this.cartObj.style.display = 'block';
	}

	function cartHide(){
//		if (this.cartObj.style.display != 'none')
//			new Effect.Fade(this.cartObj,{duration: 0.4});
		this.cartObj.style.display = 'none';
	}

	function cartVerifyQty(id){
		var qty= $('summ_qty_' + id);
		if (!checkPosInteger(qty.value)) {
			alert('Must enter a positive integer');
			qty.focus();
			qty.select();
		}
		else{
			this.update(id,qty.value);
		}
	}

	function cartDelete(id){
		if (!this.deleting){
			this.deleting = true;
			this.startLoading();
			var _this = this;
			var a = new Ajax.Request(this.siteRoot + '/store/products/index.cfm?action=ajaxupdatecart' + '&cartid=' + id + '&qty=' + 0,
			{'onSuccess' : 
				function(response){
					_this.deleting = false;
					_this.updateSummary();
				},
			'onFailure' : 
				function(response){
					_this.deleting = false;
					_this.reportError(response)
				}
			});
		}
		else
			alert('Wait for current remove operation to finish');
	}

	function cartStartLoading(){
		$('cartloadingimage').style.visibility="visible";
		this.loading = true;
	}

	function cartStopLoading(){
		$('cartloadingimage').style.visibility="hidden";
		this.loading = false;
	}

	function Cart(cartID,contents,siteRoot,registrar){
		this.siteRoot = siteRoot;
/*
		var blueLoading = new Image();
		blueLoading.src = this.siteRoot + '/images/blueLoading.gif';
		blueLoading.name= 'blueLoading';
		blueLoading.id = 'blueLoading';
	
		var yellowGrad = new Image();
		yellowGrad.src = this.siteRoot + '/images/bordergrad.gif';
		yellowGrad.name= 'yellowGrad';
		yellowGrad.id = 'yellowGrad';
*/
		this.registrar = registrar;
		this.loading = false;
		this.deleting = false;
		this.cartID = cartID;
		this.preview = cartPreview;
		this.show = cartShow;
		this.hide = cartHide;
		this.update = cartUpdate;
		this.updateSize = cartUpdateSize;
		this.updateSummary = cartUpdateSummary;
		this.updateTotal = cartUpdateTotal;		
		this.resetPosition = cartResetPosition;
		this.startLoading = cartStartLoading;
		this.stopLoading = cartStopLoading;
		this.displayMessage = cartDisplayMessage;
		this.remove = cartDelete;
//		this.updateSize = cartUpdateSize;

		this.verifyQty = cartVerifyQty;
		this.reportError = cartReportError;
		this.cartObj = $(cartID);
		this.cartObj.style.position = 'absolute';
		this.contents = $(contents);

		new Draggable(this.cartObj);
		this.cartObj.style.top = (Position.cumulativeOffset($('cartLink'))[1] - 185) + "px";
		this.cartObj.style.left = (Position.cumulativeOffset($('cartLink'))[0] + 73) + "px";
		this.positionedElement = new PositionedElement(this.cartObj,$('cartLink'),73,-185);
		this.registrar.register(this.positionedElement);		
	}
