var gmap = null;
var geocoder = null;
var xmlHttp = null;
var addressSearchHandler = null;

addLoadEvent(init, window);
addUnloadEvent(GUnload, window);
function init()
{	 
		fullurl = document.location.href;
		if(fullurl.indexOf('?') > 0)			
			$('zip').value = fullurl.substring(fullurl.indexOf('=') + 1, fullurl.length);
		gmap = new GMap2($("map"));		
		geocoder = new GClientGeocoder();
		xmlHttp = getXmlHTTPObject();
		var markerFuture = new MarkerFuture(gmap);
		var mapUpdater = new MapUpdater(gmap, markerFuture);
		var mapGeocoder = new MapGeocoder(geocoder, new GeocodeCallbackHandler(gmap, markerFuture));
		var handlerArray = [mapUpdater, mapGeocoder];
		var xmlHandler = new CompositeXMLHandler(handlerArray);
		setup(gmap, xmlHttp,  xmlHandler); 		
}
	
function setup(googlemap, xmlHttpObj, xmlHandler){
		googlemap.setCenter(UNITED_STATES_LAT_LONG, UNITED_STATES_ZOOM_LEVEL); //default view, centered over the United States
		googlemap.addControl(new GSmallMapControl());
        googlemap.enableScrollWheelZoom();
        var setupMapServiceCallbackHandler = new MapServiceCallbackHandler(xmlHttpObj, xmlHandler);
		invokeMapService(setupMapServiceCallbackHandler);
}


function invokeMapService(mapServiceCallbackHandler){
      xmlHttp.open("GET", "ProcPrefEthanolPlants.xml", true);
      xmlHttp.onreadystatechange = function(){
        mapServiceCallbackHandler.callback();
      };
      xmlHttp.send(null);
}