var map = null;
var findTask = null;
var params = null;
var mapExtension = null;
var gOverlays = null;

function init() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(centerLat, centerLon), zoom);
   
		var dynamicMap = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://maps.arvada.org/ArcGIS/rest/services/City_Council/MapServer", null, 0.5);
		map.addOverlay(dynamicMap);
		
		//Create MapExtension utility class
		mapExtension = new esri.arcgis.gmaps.MapExtension(map);

		// Find Task
		findTask = new esri.arcgis.gmaps.FindTask("http://maps.arvada.org/ArcGIS/rest/services/City_Council/MapServer");

		// You can execute a task and listen for the complete event or use the callback to get the results
		GEvent.addListener(findTask, "executecomplete", function() {
		  //console.debug("'find task complete' event fired!!!");
		});

		// Find Parameters
		params = new esri.arcgis.gmaps.FindParameters();
		params.layerIds = [0,1,2];
		params.searchFields = ["ADDRESS"];

		/*if (newmarker == 1) {
			var point = new GLatLng(centerLat, centerLon);
			map.addOverlay(new GMarker(point));

			new Effect.Highlight("form-results", { startcolor: "#ffff99",endcolor: "#ffffff", duration: 5.0 });
		}*/
	}
	else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
	}
}

function executeFind(searchText) {
	// clear map overlays and event listeners using MapExtension removeFromMap
	mapExtension.removeFromMap(gOverlays);
	
	// set find parameters
	params.searchText = searchText;
	
	// execute find task
	findTask.execute(params, findCompleteCallback);
}

function findCompleteCallback(findResults) {
	// add the findresutls to google map without any style
	gOverlays = mapExtension.addToMap(findResults);
}

window.onload = init;
window.onunload = GUnload;
