if (typeof(SWG_GMaps_base) == "undefined") {
	var SWG_Google_Maps_lookup = new Array();
	var SWG_GMaps__base = {
		geocoder : new GClientGeocoder(),
		initialized : false,
		markers : new Array(),
		map : null,
		bounds: null,
		
		Init : function(mapId) {
			if (GBrowserIsCompatible()) {
				// create map
				this.map = new GMap(document.getElementById(mapId));
	
				// have to set a center before adding markers
				this.map.setCenter(new GLatLng(0,0),0);

				this.bounds = new GLatLngBounds();
			}
			this.initialized = true;
		},
		
		//------ Use Geocodes add a marker to the map ------
		Marker_add : function(latitude, longitude, name, popup) {
			if (!this.initialized) {
				alert("Error: Map not initialized.");
				return false;
			}				
			if (GBrowserIsCompatible()) {
				// get attributes for each marker
				var point = new GLatLng(latitude, longitude);
				var marker_new = new GMarker(point);
				
				marker_new.name = name;
				if (typeof(popup) != "undefined" && popup != null) {
					// add click listener for info window
					GEvent.addListener(marker_new, "click", function() {
						marker_new.openInfoWindow(popup);
					});
				}
				//add the marker to the overlay
				this.map.addOverlay(marker_new)
				
				//extend the bounds of the map
				this.bounds.extend(point);
				
				this.markers[name] = marker_new;
			}
			
			return true;
		},
		
		GeoCode_finalize : function (result)	{
			if (result.Status.code = G_GEO_SUCCESS) {
				var name	= result.name;
				for (var i = 0; i < result.Placemark.length; i++) 
				{
					var placemark = result.Placemark[i].Point.coordinates;
					var reference = SWG_Google_Maps_lookup[name];

					reference.gmap.Marker_add(placemark[1], placemark[0], reference.name, reference.popup);
					reference.gmap.CenterAndZoom();
				}
				
				return true;
			} else {
				// lookup failed.  Failure Codes:
				// G_GEO_SUCCESS            	= "Success";
				// G_GEO_MISSING_ADDRESS    	= "Missing Address: The address was either missing or had no value.";
				// G_GEO_UNKNOWN_ADDRESS    	= "Unknown Address:  No corresponding geographic location could be found for the specified address.";
				// G_GEO_UNAVAILABLE_ADDRESS 	= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
				// G_GEO_BAD_KEY            	= "Bad Key: The API key is either invalid or does not match the domain for which it was given";
				// G_GEO_TOO_MANY_QUERIES]  	= "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
				// G_GEO_SERVER_ERROR       	= "Server error: The geocoding request could not be successfully processed.";
				
				// var reason = result.Status.code
				return false;
			}
		},
		
		//------ Use Address to get GeoCode ------
		Marker_add_address : function(address, name, popup) {
			if (GBrowserIsCompatible()) {
				if (!this.initialized) {
					alert("Error: Map not initialized.");
					return false;
				}				
				// do the geocoding.  Geocoder requests are asyncrhonous
				SWG_Google_Maps_lookup[address] = {
					gmap : this,
					name : name,
					popup : popup
				};
				this.geocoder.getLocations(address, this.GeoCode_finalize);
			}
			
			return true;
		},
		
		Marker_focus : function(name) {
			if (!this.initialized) {
				alert("Error: Map not initialized.");
				return false;
			}
			if (GBrowserIsCompatible()) {
				if (this.markers[name] != null) {
					GEvent.trigger(this.markers[name], "click");
					return true;
				}
			}
			return false;
		},
		
		//------- Zoom and center to the markers that have been added to the map ------
		CenterAndZoom : function() {
			if (!this.initialized) {
				alert ("Error: Map not initialized.");
				return false;
			}
			// determine zoom level from bounds
			this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));

			// determine center from bounds
			this.map.setCenter(this.bounds.getCenter());

			return true;
		}		
	}
}
