﻿var googleMapsTag_windowonload = undefined;
var googleMapsTag_bDirections = false;
var googleMapsTag_directionsDiv = 'googleMapsTag_directions'; 
var googleMapsTag_location = '';
var googleMapsTag_locationFrom = null;
		
var googleMapsTag_map = undefined;
var googleMapsTag_geocoder = undefined;
var googleMapsTag_bSmallZoomControl = undefined;
var googleMapsTag_mapType = undefined;
var googleMapsTag_directions = undefined;
		
		
// let's update the directions	
function googleMapsTag_getDirections(paramFrom, paramTo) 
{
    googleMapsTag_directions.load(paramFrom + " to " + paramTo);
}

// let's show the address
function googleMapsTag_showAddress(address) 
{
    googleMapsTag_geocoder.getLatLng(
		address,
		function(point) 
		{
			if (!point) 
			{
			    googleMapsTag_showDefaultAddress('104 Bathurst St,Sydney,2000,NSW,Australia')
			} 
			else 
			{
			    googleMapsTag_map.setCenter(point, 15);
			    var googleMapsTag_marker = new GMarker(point);
			    googleMapsTag_map.addOverlay(googleMapsTag_marker);
			}
		}
    );
}
			
// let's show the address
function googleMapsTag_showDefaultAddress(address) 
{
    googleMapsTag_geocoder.getLatLng(
	    address,
		function(point) 
		{
		    if (!point) 
		    {
			    alert(address + " not found");
			} 
			else 
			{
			    googleMapsTag_map.setCenter(point, 13);
			    var googleMapsTag_marker = new GMarker(point);
			    googleMapsTag_map.addOverlay(googleMapsTag_marker);
			}
		}
	);
}
			
// pretty simple one here, let's draw the poyline in
function googleMapsTag_drawPolyline (paramWaypoints, paramWaypointLevels) 
{
	if (paramWaypoints.length > 1 && paramWaypointLevels.length > 1) 
	{
	    document.overlay = GPolyline.fromEncoded({color: "#0000FF",
		                weight: 10,
						points: paramWaypoints,
						zoomFactor: 32,
						levels: paramWaypointLevels,
						numLevels: 4
					});
		googleMapsTag_map.addOverlay(document.overlay);
	}
}

function googleMapsTag_init () 
{
    if (GBrowserIsCompatible()) 
    {
	    googleMapsTag_map = new GMap2(document.getElementById("googlemapstag"));
		googleMapsTag_geocoder = new GClientGeocoder();
				
		// define the variables to store map modification requirements
		googleMapsTag_bSmallZoomControl = true;
		googleMapsTag_mapType = 'Map';
				
		// on load, let's set the map type
		GEvent.addListener(googleMapsTag_map, "load", function () 
		{
		    // set the correct map type
			var googleMapsTag_aMapTypes = googleMapsTag_map.getMapTypes();
			for (var i in googleMapsTag_aMapTypes) 
			{
			    if (googleMapsTag_aMapTypes[i].getName().toLowerCase() == googleMapsTag_mapType.toLowerCase()) 
			    {
				    googleMapsTag_map.setMapType(googleMapsTag_aMapTypes[i]);
				}
			}
			
			// set the zoom control if required
			if (googleMapsTag_bSmallZoomControl) googleMapsTag_map.addControl(new GSmallZoomControl());
		});
		googleMapsTag_directions = new GDirections(googleMapsTag_map, document.getElementById(googleMapsTag_directionsDiv));
		googleMapsTag_showAddress(googleMapsTag_location); 
	}
			
	// is there a previous window.onload?
	if (googleMapsTag_windowonload != undefined) googleMapsTag_windowonload.apply(this);
}
