// JavaScript Document
var ge;
  var tour = null;
  
  google.load("earth", "1");

  function init() {
    google.earth.createInstance('map_tour', initCB, failureCB);
	
  }
  
  function initCB(instance) {
	  
    ge = instance;
    ge.getWindow().setVisibility(true);

    
    // add a navigation control
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
    // add some layers
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

    // create the tour by fetching it out of a KML file
 var href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + '/';
    href += 'static/ascenso.kmz';

    google.earth.fetchKml(ge, href, function(kmlObject) {
      if (!kmlObject) {
        // wrap alerts in API callbacks and event handlers
        // in a setTimeout to prevent deadlock in some browsers
        setTimeout(function() {
          alert('Bad or null KML.');
        }, 0);
        return;
		
      }
    
      tour = kmlObject;
      ge.getFeatures().appendChild(tour);
	  ge.getTourPlayer().setTour(tour);
	  
    });
	
	 //var href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + '/';
	 
    var href = 'http://www.staffmediapro.com/racetracker/kml/basecamp.kml';
    
    google.earth.fetchKml(ge, href, function(kmlObject) {
      if (!kmlObject) {
        // wrap alerts in API callbacks and event handlers
        // in a setTimeout to prevent deadlock in some browsers
        setTimeout(function() {
          alert('Bad or null KML.');
        }, 0);
        return;
      }
    	//campamentobase=kmlObject;
      // Show the entire KML file in the plugin.
      ge.getFeatures().appendChild(kmlObject);
    
	 // Walk the DOM looking for a KmlTour
     
    });
	 //var href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + '/';
    var href = 'http://www.staffmediapro.com/racetracker/kml/cima.kml';
    
    track = google.earth.fetchKml(ge, href, function(kmlObject) {
      if (!kmlObject) {
        // wrap alerts in API callbacks and event handlers
        // in a setTimeout to prevent deadlock in some browsers
        setTimeout(function() {
          alert('Bad or null KML.');
        }, 0);
        return;
      }
    	//track=kmlObject;
      // Show the entire KML file in the plugin.
      ge.getFeatures().appendChild(kmlObject);
    
	 // Walk the DOM looking for a KmlTour
     
    });
    
    //document.getElementById('installed-plugin-version').innerHTML =
      //ge.getPluginVersion().toString();
  }
  
  function failureCB(errorCode) {
  }
  
  function enterTour() {
    ge.getTourPlayer().setTour(tour);
  }
  
  function playTour() {
    ge.getTourPlayer().play();
  }
  
  function pauseTour() {
    ge.getTourPlayer().pause();
  }
  
  function resetTour() {
    ge.getTourPlayer().reset();
  }
  
  function exitTour() {
    // just like setBalloon(null)
    ge.getTourPlayer().setTour(null);
  }
  