if(API) {
	oMaps=new Object();
	API.googleMaps=oMaps;
	API.googleMaps.version=3;
	oMaps.length=0;
	oMaps.New=function(containerId,controlNav,controlType) {
		switch(this.version) {
			case 3:
				API.googleMaps[this.length]=new googleMap3(this.length,containerId,controlNav,controlType);
				break;
			default:
				API.googleMaps[this.length]=new googleMap(this.length,containerId,controlNav,controlType);
				break;
		}
		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 {
			switch(this.version) {
				case 3:
				
					break;
				default:
					GUnload();
					break;
			}
		}
		catch(e) {

		}
	}
	oMaps.Marker=function(location,infoWindow,centerZoom,noInfoWindow,$lat,$lng) {
		switch(this.version) {
			case 3:
				return new googleMap3Marker(location,infoWindow,centerZoom,noInfoWindow,$lat,$lng);				
			default:
				return new googleMapMarker(location,infoWindow,centerZoom,noInfoWindow);				
		}
	}
	oMaps.Directions=function(containerId,loadHandler,errorHandler) {
		switch(this.version) {
			case 3:
				return new googleMap3Directions(containerId,loadHandler,errorHandler);				
			default:
				return new googleMapDirections(containerId,loadHandler,errorHandler);				
		}
	}
	if(this.version<3)
		window.onunload=oMaps.Unload;
}

function googleMap3(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.currentMarker=0;
	
	this.defaultZoom=10;
	this.autoInfoWindow=true;
	
	this.currentInfoWindow=null;
	this.customMarker=null;
	this.customMarkerMax=100;
	this.customMarkerDefault='blank';
	
	
	this.startLocation=null;
	this.startZoom=null;
	
	
	this.bounds={'lLat' : null,'lLng' :null,'hLat':null,'hLng':null};
	
	this.setBounds=function(lat,lng) {
		if(this.bounds['lLat']===null || this.bounds['lLat']>lat)
			this.bounds['lLat']=lat;
		if(this.bounds['hLat']===null || this.bounds['hLat']<lat)
			this.bounds['hLat']=lat;
		if(this.bounds['lLng']===null || this.bounds['lLng']>lng)
			this.bounds['lLng']=lng;
		if(this.bounds['hLng']===null || this.bounds['hLng']<lng)
			this.bounds['hLng']=lng;
	}
	var oContainer=null;
	this.Load = function() {
		oContainer=document.getElementById(this.containerId);
		if(!oContainer)
			return false;
			
		var mapOptions=	{
		      zoom: 4,		      
		      mapTypeControl: this.controlType,		      
		      navigationControl: this.controlNav,		      
		      mapTypeId: google.maps.MapTypeId.ROADMAP      
		    }
	    this.Object = new google.maps.Map(oContainer,mapOptions);
	    
	    this.Geocoder = new google.maps.Geocoder();
	    this.Geocoder.googleMap=this;	    
		if(this.controlDirections) {
			this.Directions.Load();
		}
		
		if(this.startLocation) {			
			this.googleMap.Object.setCenter(this.startLocation,this.startZoom? this.startZoom : this.defaultZoom);
		}
		else if(!this.startLocation && this.markers.length>1) {						
			var low=new google.maps.LatLng(this.bounds['lLat'],this.bounds['lLng']);
			var high=new google.maps.LatLng(this.bounds['hLat'],this.bounds['hLng']);
			var bounds=new google.maps.LatLngBounds(low,high);									
			this.Object.fitBounds(bounds);			
		}
		this.currentMarker=0;		
		this.LoadNextMarker();
	}
	this.LoadNextMarker=function() {	
		if(this.markers.length>this.currentMarker) {			
	    	oMarker=this.markers[this.currentMarker];
	    	this.currentMarker++;	    	
	    	oMarker.Load();
	    	
		} 
	}
	
	this.addMarker=function(marker) {	
		if(marker instanceof googleMap3Marker) {
			marker.googleMap=this;
			this.markers.push(marker);
			
			if(marker.lat!==null && marker.lng!==null) {
				this.setBounds(marker.lat,marker.lng)
			}
			return marker;
		}
		else
			return false;
	}
	this.addDirections=function(oDirections) {
		if(oDirections instanceof googleMap3Directions) {
			this.controlDirections=true;
			oDirections.googleMap=this;
			this.Directions=oDirections;
			return oDirections;
		}
		else
			return false;
	}
	this.getMarker=function(marker) {
		if(this.markers.length==0)
			return null;
		if(marker) {
			return this.markers[marker];
		}
		return this.markers[0];
	}
	this.getDirections=function(from,to) {
		this.Directions.getDirections(from,to);
	}
	this.closeInfoWindow=function() {
		if(this.currentInfoWindow) {		
			this.currentInfoWindow.close();
			this.currentInfoWindow=null;
		}
	}
	this.setInfoWindow=function(infoWindow) {
		
		this.currentInfoWindow=infoWindow;
	}
}

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

	this.Object=null
	this.googleMap=null;
	this.to=null;
	var me=this;
	this.Load =function() {
		oContainer=document.getElementById(this.containerId)
		if(!oContainer)
			return false;
		oDirections=new google.maps.DirectionsRenderer();
		oDirections.setMap(this.googleMap.Object);
		oDirections.setPanel(oContainer);
		this.service=new google.maps.DirectionsService();
		this.Object=oDirections;
		//if(this.loadHandler)
		//	GEvent.addListener(this.Object, 'load', this.loadHandler);
		//if(this.errorHandler)
		//	GEvent.addListener(this.Object, 'error', this.errorHandler);
	}
	
	this.getDirections=function(from,to) {
		if(!to)
			to=this.to;
		var request = {
		        origin:from, 
		        destination:to,
		        travelMode: google.maps.DirectionsTravelMode.DRIVING
		};		
		this.service.route(request, function(response, status) {
	      if (status == google.maps.DirectionsStatus.OK) {
	        me.Object.setDirections(response);
	      }
	    }); 
	}
	this.setDefaultTo=function(to) {
		this.to=to;
	}
}

function googleMap3Marker(location,infoWindow,centerZoom,noInfoWindow,lat,lng) {
	this.location=location;
	this.infoWindow=infoWindow;
	this.centerZoom=centerZoom;
	this.googleMap=null;
	this.oInfoWindow=null;
	this.noInfoWindow=noInfoWindow;
	this.lat=lat;
	this.lng=lng;
	this.Load = function() {	
		if(this.googleMap instanceof googleMap3) {
			var oGoogleMapMarker=this;
			if(this.lng && this.lat) {
				var oLocation= new google.maps.LatLng(this.lat,this.lng);
				this._Mark(oLocation);
				var marker=this;
				 window.setTimeout(function() {
					 marker.googleMap.LoadNextMarker();
					},1);
			}
			else {
				this.googleMap.Geocoder.geocode({ 'address' : this.location},function(result,status) {
					oGoogleMapMarker.Mark(result,status);
				});
			}
		}
	}
	this.Mark=function(result,status) {		
		 if (status == google.maps.GeocoderStatus.OK) {					
			 this._Mark(result[0].geometry.location);
		}
		 var marker=this;
		 window.setTimeout(function() {
				marker.googleMap.LoadNextMarker();
			},150);
	}
	this._Mark=function(location) {
		if(this.googleMap.startLocation===null) {
			if(this.centerZoom && this.googleMap.markers.length==1) {
				this.googleMap.Object.setZoom(this.centerZoom);
				this.googleMap.Object.setCenter(location,this.centerZoom);				
			}
			else if(this.googleMap.markers.length>1) {
				/*
				if(this.googleMap.currentMarker==1) {
					this.googleMap.Object.setZoom(this.googleMap.defaultZoom);
					this.googleMap.Object.setCenter(location,this.centerZoom);
				}
				this.googleMap.setBounds(location.lat(),location.lng());
				*/
			}
		}
		var markerOptions={ map: this.googleMap.Object,
				position:  location,
				animation: google.maps.Animation.DROP};
		
		if(this.googleMap.customMarker!==null) {
			var seq=this.googleMap.customMarkerDefault;
			if(this.googleMap.markers.length>1) {
				if(this.googleMap.currentMarker<9) {
					seq='0'+this.googleMap.currentMarker;
				}
				else {
					seq=this.googleMap.currentMarker;
					if(seq>this.googleMap.customMarkerMax)
						seq=this.googleMap.customMarkerDefault;
				}
			}
			var icon=this.googleMap.customMarker.replace('[SEQ]',seq);
			markerOptions['icon']=icon;
			
		}
		this.marker=new google.maps.Marker(markerOptions);
		this.marker.marker=this;	
		this.oInfoWindow=new google.maps.InfoWindow({content:this.infoWindow});
		if(!this.noInfoWindow  && this.googleMap.markers.length==1 && this.googleMap.autoInfoWindow) {
			this.oInfoWindow.open(this.googleMap.Object,this.marker);			
			
			
		}
		var marker=this;
		 google.maps.event.addListener(this.marker, 'click', function() {
			marker.focus();
		});
		
	}
	this.focus=function() {
		this.googleMap.closeInfoWindow();
		if(this.oInfoWindow) {
			this.oInfoWindow.open(this.googleMap.Object,this.marker);
			this.googleMap.setInfoWindow(this.oInfoWindow);
		}
		if(this.googleMap.Directions)
			this.googleMap.Directions.setDefaultTo(this.location);
		
	}
	
	this.onClick=function() {
	
		this.openInfoWindowHtml(this.marker.infoWindow);
	
	}
}

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,noInfoWindow) {
	this.location=location;
	this.infoWindow=infoWindow;
	this.centerZoom=centerZoom;
	this.googleMap=null;
	this.noInfoWindow=noInfoWindow;
	this.Load = function() {
		if(this.googleMap instanceof googleMap) {
			var oGoogleMapMarker=this;
			this.googleMap.Geocoder.getLatLng(this.location,function(point) {
				oGoogleMapMarker.Mark(point);
			});
		}
	}
	this.Mark=function(point) {		
		if(!point) {
			//alert("Google Maps: Could not determine coordinates for \""+oMarker.location+"\"!");
			return;
		}
		if(this.centerZoom)
			this.googleMap.Object.setCenter(point,this.centerZoom);
		this.GMarker=new GMarker(point);
		this.GMarker.marker=this;	
		this.googleMap.Object.addOverlay(this.GMarker);
		if(!this.noInfoWindow)
			this.GMarker.openInfoWindowHtml(this.infoWindow);
		
		GEvent.addListener(this.GMarker,'click',this.onClick);
		
	}
	this.onClick=function() {
		this.openInfoWindowHtml(this.marker.infoWindow);
	}
}

