if(API) {
	oMaps=new Object();
	API.googleMaps=oMaps;
	oMaps.length=0;
	oMaps.New=function(containerId,controlNav,controlType) {
		API.googleMaps[this.length]=new googleMap(this.length,containerId,controlNav,controlType);
		this.length++;
		return API.googleMaps[this.length-1];

	}
	oMaps.Get=function(id) {
		if(API.googleMaps[id])
			return API.googleMaps[id];
		return false;
	}
	oMaps.LoadAll=function() {
		for(googleMaps=0;googleMaps<this.length;googleMaps++)
			API.googleMaps[googleMaps].Load();
	}
	oMaps.Unload=function() {
		try {
			GUnload();
		}
		catch(e) {

		}
	}
	window.onunload=oMaps.Unload;
}
function googleMap(mapId,containerId,controlNav,controlType) {

	this.id=mapId;
	this.containerId=containerId;

	this.controlNav=controlNav;
	this.controlType=controlType;
	this.controlDirections=false;

	this.directionsContainerId=null;
	this.directionsLoadHandler=null;
	this.directionsErrorHandler;

  	this.Directions=null;
	this.Object=null;
	this.Geocoder=null;

	this.markers=Array();

	this.addMarker=function(marker) {
		if(marker instanceof googleMapMarker) {
			marker.googleMap=this;
			this.markers.push(marker);
			return marker;
		}
		else
			return false;
	}
	this.addDirections=function(oDirections) {
		if(oDirections instanceof googleMapDirections) {
			this.controlDirections=true;
			oDirections.googleMap=this;
			this.Directions=oDirections;
			return oDirections;
		}
		else
			return false;
	}

	this.Load = function() {

		if (GBrowserIsCompatible()) {
			try{
				oContainer=document.getElementById(this.containerId);
				if(!oContainer)
					return false;
			    this.Object = new GMap2(oContainer);
			    this.Geocoder = new GClientGeocoder();
			    this.Geocoder.googleMap=this;
			    for(markersCount=0;markersCount<this.markers.length;markersCount++) {
			    	oMarker=this.markers[markersCount];
			    	oMarker.Load();
			    }

				if(this.controlNav)
					this.Object.addControl(new GSmallMapControl());
				if(this.controlType)
					this.Object.addControl(new GMapTypeControl());
				if(this.controlDirections) {
					this.Directions.Load();
				}
			}
			catch(e) {
				return false;
			}
		}
		else
			return false;
		return true;

	}
}

function googleMapDirections(containerId,loadHandler,errorHandler) {
	this.containerId=containerId;
	this.loadHandler=loadHandler;
	this.errorHandler=errorHandler;

	this.Object=null
	this.googleMap=null;
	this.Load =function() {
		oContainer=document.getElementById(this.containerId)
		if(!oContainer)
			return false;
		oDirections=new GDirections(this.googleMap.Object,oContainer);
		this.Object=oDirections;
		if(this.loadHandler)
			GEvent.addListener(this.Object, 'load', this.loadHandler);
		if(this.errorHandler)
			GEvent.addListener(this.Object, 'error', this.errorHandler);
	}
}
function googleMapMarker(location,infoWindow,centerZoom) {
	this.location=location;
	this.infoWindow=infoWindow;
	this.centerZoom=centerZoom;
	this.googleMap=null;

	this.Load = function() {
		if(this.googleMap instanceof googleMap) {
			this.googleMap.Geocoder.getLatLng(this.location,this.Mark);
		}
	}
	this.Mark=function(point) {
		if(oMarker) {
			if(!point) {
				alert("Google Maps: Could not determine coordinates for \""+oMarker.location+"\"!");
				return;
			}
			if(oMarker.centerZoom)
				oMarker.googleMap.Object.setCenter(point,oMarker.centerZoom);
			oGMarker=new GMarker(point);
			oMarker.googleMap.Object.addOverlay(oGMarker);
			oGMarker.openInfoWindowHtml(oMarker.infoWindow);
			GEvent.addListener(oGMarker,'click',oMarker.onClick);

		}
	}
	this.onClick=function() {
		oGMarker.openInfoWindowHtml(oMarker.infoWindow);
	}
}
