var EditShpLst = new Class({
	initialize: function(onSuccess, onRequest, id) {
		this.actionToCall = '/wikifood/de/struts/editShoppingList.do?method=add&id=';
		this.action;
		this.myTimer;
		this.onSuccess = onSuccess;
		this.onRequest = onRequest;
		this.id = id;
		// variable to store message box fade out object
		this.mBoxFadeOut;
		
	},
	
	addToShoppingList: function(id) {
		this.myTimer = $clear(this.myTimer); //Cancels setQty.
		this.action = this.actionToCall + id;
		// send form to update session attribute
		this.myTimer = this.sendToServer.bind(this).delay(500);
	},
	
	sendToServer: function () {
		this.action = this.action.trim();
		var req = new Request({ url: this.action, method:'get', onRequest: function() {
				$('overlay').setStyle('display','block');
				$('overlay').setStyle('opacity','1');
	            $('message-box').set('text', this.onRequest);
	            if(this.mBoxFadeOut != null) {
	                // cancel running fade out of message box
	            	this.mBoxFadeOut.cancel();
	            }
	            this.mBoxFadeOut = new Fx.Tween('overlay', {property: 'opacity'});
	       }.bind(this),
	        onSuccess: function() {
	    	   	$('overlay').setStyle('display','block');
	    	   	$('message-box').set('text',this.onSuccess);

	    	   	// start fade out of message box after a delay of 2 seconds
		        this.fadeOut.bind(this).delay(2000);
	        }.bind(this)
	    }).send();
	},
	// function to fade out message box
   	fadeOut: function fadeOut() {
   		this.mBoxFadeOut.start(0);
	}
});

