/*
*	@class: Controller
*	responds to events dispatched from the view with requests to the model
*/
function Controller(Model, View, CONSTANTS)
{
	/*
	*	@properties:
	*	@property: Controller.CONSTANTS.App constants
	*	@property: Controller.view.A reference to the application's view object
	*	@property: Controller.model.A reference to the application's model object
	*/
	this.CONSTANTS = CONSTANTS;
	this.view = View;
	this.model = Model;
	
	/*
	*	@method: Controller.notify
	*	handle events from the View 
	*/
	this.notify = function (EVENT)
	{ 
		switch(EVENT)
		{		
			case this.CONSTANTS.BUTTON_REFRESH_MAP_CLICKED:	
				this.refreshMap();  	break;
			case this.CONSTANTS.BUTTON_ENLARGE_MAP_CLICKED:	
				this.enlargeMap();	 break;
			case this.CONSTANTS.BUTTON_MINIMIZE_MAP_CLICKED:	
				this.minimizeMap();  break;
			case this.CONSTANTS.BUTTON_SELECTALL_CLICKED:	
				this.selectAll();	break;
			case this.CONSTANTS.SELECT_TOWN_CHANGED:	
				this.zoomToTown(); 	break;
			default: 
				break;
		}
	};	
	
	/*
	*	@method: Controller.init
	*	initialize controller
	*/
	this.init = function()
	{
		this.view.loadMap(this.model.getAllSites());
		this.view.loadSelects(0, this.model.getAllTowns());				
		this.view.clearAllCheckboxes();		
		this.view.setSelectWidth(this.model.getLongestTownLengthInLetters());
	}
	
	/*
	*	@method: Controller.refreshMap
	*	calls the update method of the View object
	*/
	this.refreshMap = function()
	{
		this.view.update(this.view.getSelectedItems(), 
									this.model.getCoordinatesForTown(this.view.getSelectedTown())
									);
	}
	
	/*
	*	@method: Controller.enlargeMap
	*	calls the enlargeMap method of the View object
	*/
	this.enlargeMap = function()
	{
		this.view.enlargeMap();
	}	
	
	/*
	*	@method: Controller.minimizeMap
	*	calls the minimizeMap method of the View object
	*/
	this.minimizeMap = function()
	{
		this.view.minimizeMap();
	}	
	
	/*
	*	@method: Controller.clearCheckboxes
	*	clears all ui elements selected by the user
	*/
	this.selectAll = function()
	{
		this.view.selectAllCheckboxes();
	}
	
	/*
	*	@method Controller.zoomToTown
	*	calls the zoomToTown method of the view object
	*/
	this.zoomToTown = function()
	{
		this.view.zoomToTown(this.model.getCoordinatesForTown(this.view.getSelectedTown()));
	}
		

}//end class Controller
