dojo.declare("com.mgh.LocationsView", [com.mgh.CentersView], {
	constructor : function(){
		this.renderLayer = '#location div';		
		this.listLayout = '<ul>${0}</ul>';
		this.listElement = '<li>${0}</li>';
		this.model;
	},
	
	// this is where state is kept.	
	EvaluateView : function(id,name,type){
		/*
		 * 
		 * Center selected, this filters the list to display only the appropriate locations.
		 * 
		 */
		if(this.centerSelected == false){
			dojo.publish('requestAllLocationsData',[id,name,type]);
		} else {
			if (id == '') {
				this.RenderListViewFromExistingModel();
			} else {
				this.RenderListView(id, name, type);
			}			
		}
		
		//console.log(id + ' ' + name + ' ' + type);
		
		/* 
		 * When a location is selected, list view is rendered. When the show all locations button is
		 * pressed the location is no longer selected and new data needs to be retrieved.
		 * 
		 */
		if(!this.locationSelected) {
			//dojo.publish('requestAllLocationsData', [id,name,type]);
			//console.log('showAllLocations');
			//this.RenderListViewFromExistingModel();
		}
	},
		
	ToggleLocationSelected : function (id,name,type){
		this.locationSelected = this.locationSelected == false ? true : false;
	},	
		
	ToggleCenterSelected : function (id,name,type){
		this.centerSelected = this.centerSelected == false ? true : false;
	},
	
	RenderListView : function(model,type){
		//console.log('locationsView.renderListView');
		this.model = model;
		//var output = "";
		
		if (applicationState.getApplicationComponentState('location')) {
			var id = applicationState.model.location;
			this.RenderSelectedView(id, 'Location', 'Location');
		}
		else {	
		/*			
			for (var i = 0; i < this.model.length; i++) {
				output += dojo.string.substitute(this.listElement, [this.model[i].Format()]);
			}
			
			output = dojo.string.substitute(this.listLayout, [output]);
			
			jQuery(this.renderLayer).html(output);
		*/
		this.RenderListViewFromExistingModel();
		}
	},
	
	/*
	RenderListView : function(model,type){	
		try {							
			this.model = model;
			var output = "";		

			for (var i = 0; i < this.model.length; i++){
				output += dojo.string.substitute(this.listElement, [this.model[i].Format()]);
			}
			
			output = dojo.string.substitute(this.listLayout,[output]);	
							
			jQuery(this.renderLayer).html(output);				
		} catch (e) {
			console.log('com.mgh.LocationsView.RenderView error: ' + e);
		}
	},	
	*/

	FadeOutDisplay : function(){
		jQuery(this.renderLayer).fadeOut('fast');
	},
	
	FadeInDisplay : function(){
		jQuery(this.renderLayer).fadeIn('fast');
	}
});
