	/* Google Maps API customised for www.flexicar.com.au
	Created by Ollie Nam for FlexiCar during May 2007.
	See http://www.google.com/apis/maps/documentation/
	Copyright 2007 Flexicar, Australia
	
	This script plots markers on a google map, with an information window
	and the ability to select from several icons.
	Added the ability to plot an external address and calculate distances.
	*/
		
    //<![CDATA[

// Global variables
	var map = null;
	var geocoder = null;
	var ficon = null;
	var ficon2 = null;
	var ficon3 = null;
	var nicon = null;

// these are used to calucate distances from an address/landmark
	var dpoint = null;
	var daddress = null;

// Creates markers with info window, is passed latitude, longitude, a title, and the icon to use.
	function createMarker(podlat, podlng, podname, podinfo, iconspec, dcalc) {
	var point = new GLatLng(podlat, podlng);
	var marker = new GMarker(point, iconspec);
	map.addOverlay(marker);
	
// Calulates distances to given address if passed a true value for dcalc (must have address input)
	if (dcalc) {
	var dist = (point.distanceFrom(dpoint)/1000).toFixed(2);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml("<b>" + podname + "</b><br><i>" + podinfo + "</i><br>is <b>" + dist + "km</b> away from<br><br>" + daddress, {maxWidth: 350});
	});
	} else {
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml("<b>" + podname + "</b><br><i>" + podinfo + "</i>", {maxWidth: 350});
	});
	}
	}


    function load() {
      if (GBrowserIsCompatible()) {
		  
		  
		  // If google_map element exists, print map for melb, otherwise print map for syd
		  if(document.getElementById("google_map")) {
			  map = new GMap2(document.getElementById("google_map"))
			  	map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
			//	map.enableScrollWheelZoom()
				geocoder = new GClientGeocoder();
	
			// Set Latitude and Longitude of map Center and Zoom.
        		//map.setCenter(new GLatLng(-37.8096, 144.9673), 11);
				map.setCenter(new GLatLng(-37.8142, 144.9398), 12);
				
		  } else {
			  map = new GMap2(document.getElementById("google_map_syd"))
			  	map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
			//	map.enableScrollWheelZoom()
				geocoder = new GClientGeocoder();
	
			// Set Latitude and Longitude of map Center and Zoom.
        		map.setCenter(new GLatLng(-33.837342, 151.234016), 12);			  
		  }


	// Icon Specifications, duplicate with a different name (eg. icon) for others
	// For standard icon, use null
	
	// Single flying 'f' icon
	ficon = new GIcon();
	ficon.image = "../uploader/images/uploaded/fmarker.png";
	ficon.shadow = "../uploader/images/uploaded/fshadow.png";
	ficon.iconSize = new GSize(20, 34);
	ficon.shadowSize = new GSize(37, 34);
	ficon.iconAnchor = new GPoint(10, 34);
	ficon.infoWindowAnchor = new GPoint(10, 1);
	
	// Double flying 'f' icon, eg. two cars at pod
	ficon2 = new GIcon();
	ficon2.image = "../uploader/images/uploaded/fmarker2.png";
	ficon2.shadow = "../uploader/images/uploaded/fshadow2.png";
	ficon2.iconSize = new GSize(24, 34);
	ficon2.shadowSize = new GSize(39, 34);
	ficon2.iconAnchor = new GPoint(12, 34);
	ficon2.infoWindowAnchor = new GPoint(12, 1);
	
	// Triple flying 'f' icon
	ficon3 = new GIcon();
	ficon3.image = "../uploader/images/uploaded/fmarker3.png";
	ficon3.shadow = "../uploader/images/uploaded/fshadow3.png";
	ficon3.iconSize = new GSize(28, 34);
	ficon3.shadowSize = new GSize(41, 34);
	ficon3.iconAnchor = new GPoint(15, 34);
	ficon3.infoWindowAnchor = new GPoint(15, 1);
	
	// Orange icon (new pod)
	nicon = new GIcon();
	nicon.image = "../uploader/images/uploaded/nmarker.png";
	nicon.shadow = "../uploader/images/uploaded/fshadow.png";
	nicon.iconSize = new GSize(20, 34);
	nicon.shadowSize = new GSize(37, 34);
	nicon.iconAnchor = new GPoint(10, 34);
	nicon.infoWindowAnchor = new GPoint(10, 1);
	
	plotPods(false);
	
      }
    }
	
  // Used to geocode and plot other addresses
	function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
	// Focus the map on the point
              map.setCenter(point, 13);
	// Clear all markers on the map
              map.clearOverlays();
	// Assign values so that distances can be calculated and referenced
              dpoint = point;
              daddress = address;
              var marker = new GMarker(point);
	// Execute pod plotting with distance calculation
              plotPods(true);
	// Plot current point and display its address
              map.addOverlay(marker);
              marker.openInfoWindowHtml("<b>" + address + "</b><br>*Click the pod icons to calculate<br>how far away they are");

            }
          }
        );
      }
    }

    //]]>