﻿BenefulMap.MapLocation = Class.extend({
	init: function(locationDiv, searchField) {
	    this.locationDiv = locationDiv;
	    this.searchField = searchField;
	    
	    this.updateListener();
	},
	getLocationDiv: function() {
	   return this.locationDiv;
	},
	getSearchField: function() {
	   return this.searchField;
	},
	update: function(mapState) {
        var cityAndState = mapState.getLocation();
		$(this.getLocationDiv()).text( cityAndState );
		if (cityAndState) {
		    $(document).trigger("update.searchbar", [cityAndState])
		}
	},
	updateListener: function() {
	   var self = this;
	   $(document).bind('location.update', function(event, mapState) {
	      console.log('location.update fired');
	      self.update(mapState); 
	   });
	}
});