	
var WishListManager = new Class({
	
	Implements: [Options],
	options:{},
	initialize: function(){

	},

	currentPropertyIndex: 0,
	ADD: 'Add',
	REMOVE: 'Remove',
	
	/**
	* Adds or removes a property in the wish-list
	*/
	doWishList: function(wishListQueryString, sessionId, propertyIndex){

		var addOrRemoveObj = $('addOrRemove' + propertyIndex);
		var addOrRemoveParam = addOrRemoveObj.value;
		//set currentPropertyIndex static variable
		currentPropertyIndex = propertyIndex;

		//var myRequest = new Request({
		var myRequest = new Request.JSON({
			url: '/includedocs/houseInclude/DoWishList.jsp;jsessionid=' + sessionId,
			method: 'get',
			onComplete: function(responseClass){
				toggleAddOrRemove(responseClass);
				this.flagWishList(responseClass, addOrRemoveObj.value);
			}
		});

		var queryString = wishListQueryString;
		queryString += "&doWishList=" + addOrRemoveParam;
		queryString += "&tm=" + new Date().getTime();
		myRequest.send(queryString);

	},
	
	/**
	* Adds or removes a property in the wish-list
	*/
	doWishList: function(accommodationIndex){
		var ajaxQueryString = $('ajaxQueryString' + accommodationIndex).value;
		var sessionId = $('jsessionid').value;
		var addOrRemoveObj = $('addOrRemove' + accommodationIndex);
		var addOrRemoveParam = addOrRemoveObj.value;
		//set currentPropertyIndex static variable
		currentPropertyIndex = accommodationIndex;

		//var myRequest = new Request({
		var myRequest = new Request.JSON({
			url: '/includedocs/houseInclude/DoWishList.jsp;jsessionid=' + sessionId,
			method: 'get',
			onComplete: function(responseClass){
				this.toggleAddOrRemove(responseClass);
				this.flagWishList(responseClass, addOrRemoveObj.value);
			}.bind(this)
		},this);

		var queryString = ajaxQueryString;
		queryString += "&doWishList=" + addOrRemoveParam;
		queryString += "&tm=" + new Date().getTime();
		myRequest.send(queryString);

	},
	
	/**
	* Adds or removes a property in the wish-list
	*/
	doWishListAccommodation: function(accommodationIndex){
		//set currentPropertyIndex static variable
		currentPropertyIndex = accommodationIndex;

		var myRequest = new Request.JSON({
			url: '/includedocs/houseInclude/DoWishList.jsp;jsessionid=' + $('jsessionid').value,
			method: 'get',
			onComplete: function(responseClass){
				this.toggleAddOrRemove(responseClass);
				this.showWishListChangesToClient(responseClass);
			}.bind(this)
		},this);

		myRequest.post($('wlForm'));
		
	},
	
	showWishListChangesToClient: function(responseClass){
		
		this.setTheWishListButtonText(responseClass);
		var addOrRemoveText = $('addOrRemove' + currentPropertyIndex).get('value');
		
		if(addOrRemoveText === this.ADD){
			$('wishListButton' + currentPropertyIndex).set('class','smallButtons');
			$('info' + currentPropertyIndex).setStyle('backgroundColor', '#ffffff');
		}else{
			$('wishListButton' + currentPropertyIndex).set('class','smallClearButtons');
			$('info' + currentPropertyIndex).setStyle('backgroundColor', '#eeeeee');
			$('sideColumnWishListLink').set('class','orangeBackgroundLink');
		}

		
	},
	
	setTheWishListButtonText: function(responseClass){
		var theButton = $('wishListButton' + currentPropertyIndex);
		theButton.set('value', responseClass.linkOrButtonText);
	},
			
	toggleAddOrRemove: function(responseClass){

		var addOrRemoveObj = $('addOrRemove' + currentPropertyIndex);
		var addOrRemoveText = $('addOrRemove' + currentPropertyIndex).value;

		if(addOrRemoveText == this.ADD){
			addOrRemoveObj.value = this.REMOVE;
		}else{
			addOrRemoveObj.value = this.ADD;
		}//end if

	},

	/**
	 * Indicates visually on the page, by updating certain values, that the wish-list action
	 * has been completed, and removes the house visually
	 */
	flagWishList: function(responseClass, addOrRemoveText){
		
		$('wishListButton' + currentPropertyIndex).value = $('wishListButtonText' + addOrRemoveText).value;

		
		if(addOrRemoveText === this.ADD){
			$('wishListButton' + currentPropertyIndex).set('class','smallButtons');
			$('info' + currentPropertyIndex).setStyle('backgroundColor', '#ffffff');
		}else{
			$('wishListButton' + currentPropertyIndex).set('class','smallClearButtons');
			$('info' + currentPropertyIndex).setStyle('backgroundColor', '#eeeeee');
			$('sideColumnWishListLink').set('class','orangeBackgroundLink');
		}
		
		if(responseClass.wishListIsEmpty === true){
			$('sideColumnWishListLink').set('class','blackLink');			
		}
		
		if(this.isWishListPage()){
			//Page needs updating if we've remove something, so we refresh the page. 
			//Removing stuff via javascript only is a logistical nightmare. 
			document.location = '/mainsearch/results/WishList.jsp';
		}
		
		
		/*
		if($defined($('wishListText' + currentPropertyIndex))){
			$('wishListText' + currentPropertyIndex).innerHTML = responseClass.wishListText;
		}
		*/		
	},//end flagWishList
	
	
	isWishListPage: function(){
		return (document.location.href.indexOf('WishList.jsp') > 0);		this.flagWishList(responseClass, addOrRemoveObj.value);
		

	}
});
