// JavaScript Document

var GOOGLE_MAPS = new Array();

function GoogleMap( div_id, address, scale, point_lat, point_long, centre_lat, centre_long, point_text )
	{
	this.div_id =	div_id;		// The id of the div which will contain the map.
	this.address =	address;	// The address to be shown on the map.
	this.scale =	scale;		// The required map scale.
	
	// Define the latitude and longitude of the point to be shown on the map
	if( point_lat && point_long)
		this.point_coords = new GLatLng( point_lat, point_long);
	
	// Define the latitude and longitude of the centre of the map
	if( centre_lat && centre_long)
		this.centre_coords = new GLatLng( centre_lat, centre_long);

	// Define the text attached to the point.
	if( point_text)	
		this.point_text = point_text;
	else
		this.point_text = this.address;
	}

function LCBC_setUpGoogleMaps()
	{
	//alert( "LCBC_setUpGoogleMaps");
	if( GBrowserIsCompatible() ) 
		{
		for( var i=0; i < GOOGLE_MAPS.length; i++)
			{
			// If no point coords, get point coords and draw map
			if( ! GOOGLE_MAPS[i].point_coords)
				LCBC_getGoogleMapCoords( GOOGLE_MAPS[i] );
			// Otherwise, draw map
			else
				LCBC_drawGoogleMap( GOOGLE_MAPS[i] );
			}
		}
	}

function LCBC_getGoogleMapCoords( google_map)
	{
	//alert( "LCBC_getGoogleMapCoords");

	var geocoder = new GClientGeocoder();

	geocoder.getLatLng(
		google_map.address,
		function (point)
			{
			if( !point )
				alert( google_map.address + " not found");
			else
				{
				//alert( "point=" + point);
				var map = new GMap2( document.getElementById( google_map.div_id) );
				var marker = new GMarker( point);
				map.setCenter( point, google_map.scale);
				map.addControl( new GScaleControl() );
				map.addControl( new GSmallMapControl() );
				map.addOverlay( marker);
				GEvent.addListener( 
					marker, "click", function() { marker.openInfoWindowHtml( point + "<br>" + google_map.point_text); } );
				}
			}
		);

	}

function LCBC_drawGoogleMap( google_map)
	{
	//alert( "LCBC_drawGoogleMap");
	var map = new GMap2( document.getElementById( google_map.div_id) );
	var marker = new GMarker( google_map.point_coords);
	if( google_map.centre_coords)
		map.setCenter( google_map.centre_coords, google_map.scale);
	else
		map.setCenter( google_map.point_coords, google_map.scale);
	map.addControl( new GScaleControl() );
	map.addControl( new GSmallMapControl() );
	map.addOverlay( marker);
	GEvent.addListener( marker, "click", function() { marker.openInfoWindowHtml( google_map.point_text); } );
	}
