var gmap;
var gdir;
var geocoder = null;
var addressMarker;

var API_KEY   = 'ABQIAAAAHCyFgRmVo9aHALecYnm15xQaiXOauccABmNs46D0kGGnx6WkvhTINjMl5QaeFztlSLJzhvAMWfUMAg';
var locale    = 'en_US';
var idMap     = 'map';
var idDirections = 'directions';

var toAddress_Canyon   = '9271 Arrow Route Rancho Cucamonga, CA 91730';
var toAddress_Tibbetts = '9271 Arrow Route Rancho Cucamonga, CA 91730';
var toAddress_Rancho   = '9271 Arrow Route Rancho Cucamonga, CA 91730';


load_gDirections = function() {
  if (GBrowserIsCompatible()) {      
    gmap = new GMap2(document.getElementById(idMap));
    gdir = new GDirections(gmap, document.getElementById(idDirections));

    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", gMap_handleErrors);

	geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(toAddress_Tibbetts, 
		function(latLong){
			gmap.setCenter(latLong, 14);
		}
	);

	/*
    gmap = new GMap2(document.getElementById('map-canyon'));
    gdir = new GDirections(gmap, document.getElementById(idDirections));

    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", gMap_handleErrors);

	geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(toAddress_Canyon, 
		function(latLong){
			gmap.setCenter(latLong, 14);
		}
	);
	
	
	
	gmap = new GMap2(document.getElementById('map-rancho'));
    gdir = new GDirections(gmap, document.getElementById(idDirections));

    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", gMap_handleErrors);

	geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(toAddress_Rancho, 
		function(latLong){
			gmap.setCenter(latLong, 14);
		}
	);
	*/
  }

  delete load_gDirections; 
}

function getDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
}

function gMap_handleErrors(){
	alert('An error has occurred and we may not process your request');   
}

function onGDirectionsLoad(){ }


Event.observe(window, 'load', load_gDirections, false);

