var GRGeocoder = (function(){
	var that = this;
	
	that.filterSuggestions = function(results){
		var suggestions = new Array();
		
		var suggestionTypesToExclude = new Array("postal_code", "administrative_area_level_1", "administrative_area_level_2", "administrative_area_level_3", "country", "route");
		
		var localitiesToInclude = new Array("Grand Rapids", "East Grand Rapids", "Wyoming", "Grandville", "Walker", "Byron Center", "Comstock Park", "Allendale", "Marne", "Caledonia", "Kentwood");
		
		for(var i = 0; i < results.length; i++){
			var includeSuggestion = true;
			
			// exclude by type of suggestion
			for(var j = 0; j < results[i].types.length; j++){
				if(arrayFind(suggestionTypesToExclude, results[i].types[j]) == true){
					includeSuggestion = false;
				}
			}
			
			// exclude by city (locality) name
			var components = results[i].address_components;
			for(var j = 0; j < components.length; j++){
				// only consider the loacilty result address component
				if(arrayFind(components[j].types, "locality") == true){
					var allLocalitiesFalse = true;
					
					// get the name of the locality
					var localityName = components[j].long_name + "";
					
					// go through each acceptable locality
					for(var k = 0; k < localitiesToInclude.length; k++){
						// see if the current locality name has the locality to include in it (ie. Grand Rapids Charter Township has Grand Rapids)
						if(localityName.indexOf(localitiesToInclude[k]) > -1){
							allLocalitiesFalse = false;
						}
					}
					
					if(allLocalitiesFalse == true){
						includeSuggestion = false;
					}
				}
			}
			
			if(includeSuggestion == true){
				suggestions.push(results[i]);
			}
		}
		
		return suggestions;
	};
	
	that.resolveAddress = function(address, callback){
		var geocoder = new google.maps.Geocoder();
		
		var bounds = {
			"SW" : ["42.827638636242284","-85.92201232910156"],
			"NE" : ["43.05484087957652","-85.52169799804688"]
		};
		
		var gbounds = new google.maps.LatLngBounds(new google.maps.LatLng(parseFloat(bounds.SW[0]), parseFloat(bounds.SW[1])), new google.maps.LatLng(parseFloat(bounds.NE[0]), parseFloat(bounds.NE[1])));
		
		geocoder.geocode({'address':address,"bounds":gbounds}, function(results, status){
			// filter the results in order to 
			var suggestions = that.filterSuggestions(results);
			//var suggestions = results;
			
			callback(suggestions, status);
		});
	};
	
	return that;
}());
