google.load("earth", "1");

google.setOnLoadCallback(function() {
  window.google.earth.doOneClickSetup();
  setInstallLinks();
  
  if (!google.earth.isSupported()) {
    var downloadButton = document.getElementById('download-button');
    downloadButton.innerHTML =
        '<p>See the System Requirements below for a list of supported ' +
        'web browsers and operating systems.</p>';
  } else if (google.earth.isInstalled()) {
    var downloadButton = document.getElementById('download-button');
    downloadButton.style.display = 'none';
    var promoNode = document.getElementById('index_promo');
    promoNode.style.display = 'none';
    var alreadyInstalledNode = document.getElementById('already-installed');
    alreadyInstalledNode.style.display = '';
    
    google.earth.setLanguage('en');
    document.getElementById('map3d').innerHTML = '';
    google.earth.createInstance("map3d", function(pluginInstance) {
      ge = pluginInstance;
      ge.getWindow().setVisibility(true);

      var cam = ge.getView().copyAsCamera(ge.ALTITUDE_ABSOLUTE);
      cam.setAltitude(12000000);
      ge.getView().setAbstractView(cam);
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);

      document.getElementById('plugin-version').innerHTML =
          '(Version ' + ge.getPluginVersion() + ')';
    });
  }
});
