
	function GoogleMapManager() {
	
		var Me=this;
	
		this.map_initialized = 0;
		this.browser_compatible = 0;
	
		this.map_div_name 		 = 'google_map';
		this.center_address;
		this.center_latitude;
		this.center_longitude;
		this.center_zoom = 13;
		
		this.callback_browser_not_compatible;
		this.callback_display_message;

		this.directions_enabled  = 0;
		this.directions_initialized = 0;
		this.directions_div_name = 'google_directions';
		this.directions_display_error_code = 0;

		this.icon_image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
		this.icon_shadow_image = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

		this.icon_size_x = 12;
		this.icon_size_y = 20;
		this.icon_shadow_size_x = 22;
		this.icon_shadow_size_y = 20;
		this.icon_anchor_size_x = 6;
		this.icon_anchor_size_y = 20;
		this.icon_window_anchor_size_x = 5;
		this.icon_window_anchor_size_y = 1;
		
		this.map_control_enabled = true;
		this.map_type_control_enabled = false;
		
		this.overlay_clear_for_directions = true;
		
		this._Map_obj;
		this._Directions_obj;
		this._Geocoder;
		this._Icon_options = new Array();
		
		this.initialize = initialize;
		this.display_message = display_message;
		this.directions_display = directions_display;
		this.directions_initialize = directions_initialize;
		this.center_map = center_map;
		this.center_by_address = center_by_address;
		this.center_by_point = center_by_point;
		this.center_by_lat_long = center_by_lat_long;
		this.check_browser_compatibility = check_browser_compatibility;
		this.browser_not_compatible = browser_not_compatible;
		this.get_geocoder = get_geocoder;
		this.get_icon_obj = get_icon_obj;
		this.add_icon_at_address = add_icon_at_address;
		this.add_icon_at_point = add_icon_at_point;
		this.handle_directions_error = handle_directions_error;
		
		this._Handle_exception = _Handle_exception;
		
		function initialize() {
		
			try {
				if ( this.check_browser_compatibility() ) {
					this._Map_obj = new GMap2(document.getElementById(this.map_div_name));

					if ( this.map_control_enabled ) {
						this._Map_obj.addControl(new GSmallMapControl());
					}

					if ( this.map_type_control_enabled ) {
						this._Map_obj.addControl(new GMapTypeControl());
					}

					this.map_initialized = true;
					this.center_map();
					
					if ( this.directions_enabled ) {
						this.directions_initialize();
					}
					
				}
				
			}
			catch( e ) {
				this._Handle_exception( e );
			}
		
		}
		
		function directions_initialize() {

			try {
			
				if ( this.map_initialized ) {
					this._Directions_obj = new GDirections(this._Map_obj, document.getElementById(this.directions_div_name));
    	  			GEvent.addListener( this._Directions_obj, "error", Me.handle_directions_error );
    	  			this.directions_initialized = true;
    	  		}
    	  		
			}
			catch( e ) {
				this._Handle_exception( e );
			}

		
		}
		
		function directions_display( direx_string ) {
		
			try { 		
			
				if ( this.directions_initialized ) {
					if ( this.overlay_clear_for_directions ) {
						this._Map_obj.clearOverlays();
					}
					
					this._Directions_obj.load( direx_string ); 
				}
				
			}
			catch( e ) {
				this._Handle_exception( e );
			}
				 
		}
		
		function check_browser_compatibility() {
	
			try {
				if ( GBrowserIsCompatible() ) {
					this.browser_compatible = true;
					return true;				
				}
				else {
					this.browser_compatible = 0;
					this.browser_not_compatible();
				}

			}
			catch( e ) {
				this._Handle_exception( e );
			}

		
		}
		
		function browser_not_compatible() {

			try {
				if ( this.callback_browser_not_compatible && (typeof(this.callback_browser_not_compatible) == 'function') ) {
					this.callback_browser_not_compatible();
				}
			}
			catch( e ) {
				this._Handle_exception( e );
			}
			
		
		}
		
		function display_message( message ) {

			try {
				if ( this.callback_display_message && (typeof(this.callback_display_message) == 'function') ) {
					this.callback_display_message(message);
				}
				else {
					alert( message );
				}
			}
			catch( e ) {
				this._Handle_exception( e );
			}
			
		
		}
	
		function center_map() {

			try {
				
				if ( this.center_address ) {
					this.center_by_address(this.center_address);
				}
				else if ( this.center_latitude || this.center_longitude ) {
					this.center_by_lat_long(this.center_latitude, this.center_longitude);
				}
		
			}
			catch( e ) {
				this._Handle_exception( e );
			}
			
		
		}
		
		function center_by_lat_long( lat, long ) {
		
			try {

				if ( this.map_initialized ) {
					this._Map_obj.setCenter(new GLatLng(lat, long), this.center_zoom);
				}		 

			}
			catch( e ) {
				this._Handle_exception( e );
			}
		
		}
		
		function center_by_address(address) {

			try {

				if ( this.map_initialized ) {

					geocoder = this.get_geocoder();
			
					geocoder.getLatLng( 
							address, 
							this.center_by_point );
							
				}
			
			}
			catch( e ) {
				this._Handle_exception( e );
			}

		
		}
		
		function center_by_point( point ) {

			try {
			
				if ( !point ) {
					Me.display_message( 'Address not found. Please try again.' );
				}
				
				if ( Me.map_initialized ) {
				
					Me._Map_obj.setCenter(point, Me.center_zoom);
				}
			
			}
			catch( e ) {
				Me._Handle_exception( e );
			}
			
		
		}
		
		function get_geocoder() {
		
			try {
				if ( !this._Geocoder ) {
					this._Geocoder = new GClientGeocoder();
				}		
				
				return this._Geocoder;
			}
			catch( e ) {
				this._Handle_exception( e );
			}
		
		
		}
		
		function handle_directions_error() {
	
			try {
				var message = '';
			
				if ( Me._Directions_obj ) {
					if ( Me._Directions_obj.getStatus().code == G_GEO_UNKNOWN_ADDRESS )
					    message = "No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.";
			   		else if ( Me._Directions_obj.getStatus().code == G_GEO_SERVER_ERROR )
	     				message = "A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.";	   
			   		else if ( Me._Directions_obj.getStatus().code == G_GEO_MISSING_QUERY )
	     				message = "The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.";
				   	else if ( Me._Directions_obj.getStatus().code == G_GEO_BAD_KEY )
	     				message = "The given key is either invalid or does not match the domain for which it was given.";
				   	else if ( Me._Directions_obj.getStatus().code == G_GEO_BAD_REQUEST )
	     				message = "A directions request could not be successfully parsed.";
				   	else
				   		message = "An unknown error occurred.";
				   	
				   	if ( Me.directions_display_error_code ) {
				   		message = message + "\nError code: " + Me._Directions_obj.getStatus().code;
				   	}
				   	
				   	Me.display_message( message );
				}
				else {
				   	Me.display_message("An unknown error occurred.");
				}
			}
			catch( e ) {
				Me._Handle_exception( e );
			}

		}
		
		function _Handle_exception( e ) {
		
			try {
				alert( e.message );
			}
			catch( e ) {
			}
		
		}
		
		function add_icon_at_address( address, options ) {
		
			try {		
				
				if ( typeof(this._Icon_options) == 'undefined' ) {
						this._Icon_options = new Array();
				}
			
				if ( this.map_initialized ) {


					geocoder = this.get_geocoder();

					if ( typeof(options) == 'undefined' ) {
						options = new Array();
					}
					
					this._Icon_options.push(options);
					
					geocoder.getLatLng( 
							address, 
							this.add_icon_at_point );
				}
			}
			catch( e ) {
				Me._Handle_exception( e );
			}
			
		
		}

		function add_icon_at_point( point, options ) {
		
			try {

				var content;
				
				if ( typeof(options) == 'undefined' ) {
					if ( typeof(Me._Icon_options) != 'undefined' && (Me._Icon_options.length > 0) ) {
						options = Me._Icon_options.pop();
					}
				}

				if ( typeof(options['content'] != 'undefined') ) {
					content = options['content'];
				}
			
				if ( Me.map_initialized && point ) {

					var icon = Me.get_icon_obj();
					var marker = new GMarker(point, icon);

					if ( typeof(content) != 'undefined' ) {
						GEvent.addListener(marker, 
											"click", 
											function() { marker.openInfoWindowHtml(content); } 
										  );
					}
														  
					Me._Map_obj.addOverlay(marker);

					if ( typeof(options) != 'undefined' && typeof(options['content_display']) != 'undefined' ) {
						if ( options['content_display'] ) {
							marker.openInfoWindowHtml(content);
						}
					}
					
				}
			
			}
			catch( e ) {
				Me._Handle_exception( e );
			}
		
		
		}
		
		function get_icon_obj() {
		
			try {
				
				var icon = new GIcon();
				icon.image = Me.icon_image;
				icon.shadow = Me.icon_shadow_image;
				icon.iconSize = new GSize(Me.icon_size_x, Me.icon_size_y);
				icon.shadowSize = new GSize(Me.icon_shadow_size_x, Me.icon_shadow_size_y);
				icon.iconAnchor = new GPoint(Me.icon_anchor_size_x, Me.icon_anchor_size_y);
				icon.infoWindowAnchor = new GPoint(Me.icon_window_anchor_size_x, Me.icon_window_anchor_size_y);
				
				return icon;

			}
			catch( e ) {
				Me._Handle_exception( e );
			}
			
		
		}
		
		
		
	}
