<!--
  google.load("maps", "2.x");
  google.load("earth", "1");

  var Ds_ge = null;		// The GE API instance.
  var DS_simulator = null;	// The driving simulator instance.
  var pathSegments = [];	// Array for kml path segment files.
  var lsPlacemark = null;	// Holds the current path linestring.
  var defaultSpeed = 6;		// The starting speed, at 1x.
  var multSpeed = 1;		// A holding variable to store the speed multiplier.
  var path = [];		// Array for the path points as parsed from the kml file.
  var track = 1;                // The track number to run the train on.
  var allowSound = true;	// Controls whether any sounds play on the site.

  /**************************************************************************************
    Load the various path segments...
    The kml files are minimalized! They should include only the xml, kml placemark, 
    linestring and coordinates tags.  Anything else jeopardizes the kml parser.

    Place an entry for each segment in the path Select HTML element, with its value 
    set to the index of the pathSegments array & name to something meaningful.
  ***************************************************************************************/
  pathSegments[1] = "http://gaialab.asu.edu/Metro/KML/WestboundTrack.kml";
  pathSegments[2] = "http://gaialab.asu.edu/Metro/KML/EastboundTrack.kml";

  //-------------------------------------------------------------------------------
  // Ds_init - Starts the driving simulator...
  //-------------------------------------------------------------------------------
  function Ds_init() {
	Ds_geocoder = new GClientGeocoder();
	google.earth.createInstance("map3d", Ds_initCB, Ds_failureCB);
  }

  //-------------------------------------------------------------------------------
  // fetchFinished - Sets up the path array and path line string
  //-------------------------------------------------------------------------------
  function fetchFinished(kmlObject) {
    // create the array of GLatLng coordinates
    var coordsKmlObj = kmlObject.getGeometry().getCoordinates();
    var coordsArray = [];
    var n = coordsKmlObj.getLength();

    // create the linestring geometry
    var lineString = Ds_ge.createLineString('');
    lineString.setTessellate(true);
    for (var i = 0; i < n; i++) {
         var coord = coordsKmlObj.get(i);
         coordsArray.push(new google.maps.LatLng(coord.getLatitude(), coord.getLongitude()));
         lineString.getCoordinates().pushLatLngAlt(coord.getLatitude(), coord.getLongitude(), 0);
	}

    // drive speed (in meters per second)
    var speed = defaultSpeed * multSpeed;

    // create the path
    var geHelpers = new GEHelpers(Ds_ge);
    path = [];
    for (var i = 0; i < n; i++) {
         if (i == coordsArray.length - 1) {
             // last coordinate
             path.push({
			loc: coordsArray[i],
			step: 0,
			distance: 0,
			duration: 0
			});
         } else {
                 var distance = geHelpers.distance(coordsArray[i], coordsArray[i + 1]);
                 path.push({
                            loc: coordsArray[i],
                            step: 0,
                            distance: distance,
                            duration: distance / speed
                            });
		}
    }

    // create the linestring placemark and add it to Earth
    if (lsPlacemark != null) {Ds_ge.getFeatures().removeChild(lsPlacemark); }
    lsPlacemark = Ds_ge.createPlacemark('');
    lsPlacemark.setGeometry(lineString);
    Ds_ge.getFeatures().appendChild(lsPlacemark);
    if (!lsPlacemark.getStyleSelector()) { lsPlacemark.setStyleSelector(Ds_ge.createStyle(''));}
    // The Style of a Feature is retrieved as feature.getStyleSelector().
    // The Style itself contains a LineStyle, which is what we manipulate
    // to change the color and width of the line.
    var lineStyle = lsPlacemark.getStyleSelector().getLineStyle();
    lineStyle.setWidth(lineStyle.getWidth() + 3);
    lineStyle.getColor().set('8800ff00'); // aabbggrr format

    // now you can use path to create a DDSimulator...
    // Uncomment the next line to start automatically...
    DS_simulator = new DDSimulator(Ds_ge, path);
  }

  //-------------------------------------------------------------------------------
  // startSimulator - starts the simulation...
  //-------------------------------------------------------------------------------
  function startSimulator() {
    clearSpeedButtons ();
    rollButton('btn6', 'images/FullUp.png');
    DS_simulator.initUI();
    changeSimulatorSpeed(1);
    DS_simulator.start();
  }

  //-------------------------------------------------------------------------------
  // resetSimulator - resets the simulation...
  //-------------------------------------------------------------------------------
  function resetSimulator() {
    try {
         if (DS_simulator) { 
             DS_simulator.destroy(); 
             DS_simulator = new DDSimulator(Ds_ge, path);
         }
        }
    catch(err) {}
    startSimulator();
  }

  //-------------------------------------------------------------------------------
  // pauseSimulator - pauses the simulation...
  //-------------------------------------------------------------------------------
  function pauseSimulator() {
    if (DS_simulator) { DS_simulator.stop(); }
  }

  //-------------------------------------------------------------------------------
  // resumeSimulator - resumes the simulation...
  //-------------------------------------------------------------------------------
  function resumeSimulator() {
    if (DS_simulator) { 
        DS_simulator.start(); 
        playSound('Sounds/trolley2.wav');     // Ring the trollley bell.
    }
  }

  //-------------------------------------------------------------------------------
  // changeSimulatorSpeed - change the movement speed...
  // Parameters: speedMultiplier -> an integer value to change speed; can be: 1, 2, 4, 8, 16
  //-------------------------------------------------------------------------------
  function changeSimulatorSpeed(speedMultiplier) {
    if (DS_simulator) 
      { DS_simulator.options.speed = defaultSpeed * speedMultiplier; 
        multSpeed = speedMultiplier;
      }
  }

  //-------------------------------------------------------------------------------
  // Ds_initCB - Google's callback function
  //-------------------------------------------------------------------------------
  function Ds_initCB(object) {
    Ds_ge = object;
    Ds_ge.getWindow().setVisibility(true);
    Ds_ge.getNavigationControl().setVisibility(Ds_ge.VISIBILITY_AUTO);
    Ds_ge.getLayerRoot().enableLayerById(Ds_ge.LAYER_TERRAIN, true);
    Ds_ge.getLayerRoot().enableLayerById(Ds_ge.LAYER_BUILDINGS, true);
    Ds_ge.getOptions().setGridVisibility(false);  
    Ds_ge.getOptions().setFlyToSpeed(.25);
    createIcons();
    loadStations();
    addKMLToEarth("http://gaialab.asu.edu/Metro/KML/LRStationView.kml", true);
    google.earth.fetchKml(Ds_ge,pathSegments[1],fetchFinished);
  }

  //-------------------------------------------------------------------------------
  // Ds_failureCB - If the GE startup fails
  //-------------------------------------------------------------------------------
  function Ds_failureCB(object) {
    alert('load failed');
  }

  //-------------------------------------------------------------------------------
  // changeSegment - Set up a new path segment.
  // Parameters: mySegment -> The index to the pathSegments array, set up at load time.
  // Operation:  This function destroys the current driving simulator instance (if it exists)
  //             and creates a new one with the kml path indicated by mySegment.  It calls
  //             fetchKml->fetchFinished, which parses the kml file and loads the operating
  //             arrays and draws the highlighted path as a linestring.
  //-------------------------------------------------------------------------------
  function changeSegment(mySegment) {
    google.earth.fetchKml(Ds_ge,pathSegments[mySegment],fetchFinished);
    try {
         if (DS_simulator) 
           { DS_simulator.destroy(); 
             DS_simulator = new DDSimulator(Ds_ge, path);
             track = mySegment;
           }
        }
    catch(err) {}
  }

  //-------------------------------------------------------------------------------
  // addKMLToEarth - Add networked kml file to the GE API - this is adapted from Google.
  // Parameters: myURL -> full path to the kml file to be opened.
  //             flyToIt -> boolean to cause zoom to the kml extent if set to true.
  //-------------------------------------------------------------------------------
  function addKMLToEarth(myURL, flyToIt){
    var nl = Ds_ge.createNetworkLink("");
    nl.setFlyToView(flyToIt); 	// Zooms to the .kml view extent...
    var link = Ds_ge.createLink("");
    link.setHref(myURL);
    nl.setLink(link);
    Ds_ge.getGlobe().getFeatures().appendChild(nl);
    return nl;
  }

  //-------------------------------------------------------------------------------
  // rollButton - Performs general image button rollovers.
  //-------------------------------------------------------------------------------
  function rollButton(img_name, img_src) {
    document[img_name].src = img_src;
  }

  //-------------------------------------------------------------------------------
  // rollSpeedButton - Performs speed button image rollovers.
  //-------------------------------------------------------------------------------
  function rollSpeedButton(img_name, img_src) {
    
    switch (img_name) {
      case ('btn4'):
        if (multSpeed == .25) 
           { clearSpeedButtons ();
             img_src = "images/QuartUp.png";}
        else { img_src = "images/Quart" + img_src + ".png";}
        break;
      case ('btn5'):
        if (multSpeed == .5) 
           { clearSpeedButtons ();
             img_src = "images/HalfUp.png";}
        else { img_src = "images/Half" + img_src + ".png";}
        break;
      case ('btn6'):
        if (multSpeed == 1) 
           { clearSpeedButtons ();
             img_src = "images/FullUp.png";}
        else { img_src = "images/Full" + img_src + ".png";}
        break;
      case ('btn7'):
        if (multSpeed == 2) 
           { clearSpeedButtons ();
             img_src = "images/DoubleUp.png";}
        else { img_src = "images/Double" + img_src + ".png";}
        break;
      case ('btn8'):
        if (multSpeed == 4) 
           { clearSpeedButtons ();
             img_src = "images/QuadUp.png";}
        else { img_src = "images/Quad" + img_src + ".png";}
        break;
    }
    document[img_name].src = img_src;
  }

  //-------------------------------------------------------------------------------
  // clearSpeedButtons - Sets all speed buttons to "Out" state.
  //-------------------------------------------------------------------------------
  function clearSpeedButtons () {
    rollButton('btn4', 'images/QuartOut.png');
    rollButton('btn5', 'images/HalfOut.png');
    rollButton('btn6', 'images/FullOut.png');
    rollButton('btn7', 'images/DoubleOut.png');
    rollButton('btn8', 'images/QuadOut.png');
  }

  //-------------------------------------------------------------------------------
  // rollTrackButton - Performs track button image rollovers.
  //-------------------------------------------------------------------------------
  function rollTrackButton(img_name, img_src) {
    switch (img_name) {
      case ('btn9'):
        if (track == 1) 
           { clearTrackButtons ();
             img_src = "images/WestUp.png";}
        else { img_src = "images/West" + img_src + ".png";}
        break;
      case ('btn10'):
        if (track == 2) 
           { clearTrackButtons ();
             img_src = "images/EastUp.png";}
        else { img_src = "images/East" + img_src + ".png";}
        break;
    }
    document[img_name].src = img_src;
  }

  //-------------------------------------------------------------------------------
  // clearTrackButtons - Sets all track buttons to "Out" state.
  //-------------------------------------------------------------------------------
  function clearTrackButtons () {
    rollButton('btn9', 'images/WestOut.png');
    rollButton('btn10', 'images/EastOut.png');
  }

   //-----------------------------------------------------------------------------------------
   // playSound - Play sound effect.
   //-----------------------------------------------------------------------------------------
   function playSound(sURL) {
     if (allowSound == true) {
         document.getElementById("soundspan").innerHTML= "<embed src='"+sURL+"' hidden=true autostart=true loop=false>";
     }
   }

-->