      var ge;
      var geEnabled = true;
      var lon;
      var lat;
      var google;
      var placemark;
      var latitude;
      var longitude;
      google.load("earth", "1");
      google.setOnLoadCallback(init);

      function init() {
         google.earth.createInstance('map3d', initCB, failureCB);
      }

      function initCB(instance) {
        ge = instance;
        ge.getWindow().setVisibility(true);
        ge.getOptions().setStatusBarVisibility(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 placemark
        placemark = ge.createPlacemark('');

        var point = ge.createPoint('');
        if (!geEnabled) return false;
        ge.getOptions().setMapType(ge.MAP_TYPE_SKY);
      }

      function failureCB(errorCode) {
        var isSup  = google.earth.isSupported();
        var isInst = google.earth.isInstalled();
        var noSup  = "Your browser doesn't support Google Earth, but you can still view the images.<br />\n";
        var noInst = "The Google Earth Plugin is not installed.<br />\nYou can install the Google Earth Plugin <a href='http://dl.google.com/tag/s/appguid%3D%7B2BF2CA35-CCAF-4E58-BAB7-4163BFA03B88%7D%26iid%3D%7BEC7CF670-BABB-50AB-C1C7-C6C01FBCAD1B%7D%26lang%3Den%26browser%3D3%26usagestats%3D0%26appname%3DGoogle%2520Earth%2520Plug-in%26needsadmin%3DTrue%26BRAND%3DGGEP/earth/plugin/GoogleEarthPluginSetup.exe'>here</a>.<br />\n";
        var inH = (!isSup) ? noSup : (!isInst) ? noInst : "";
        geEnabled = false;
        document.getElementById('map3d').style.visibility = "hidden";
        document.getElementById('sf1').checked = false;
        document.getElementById('sf1').disabled = true;
        document.getElementById('sf2').checked = true;
        document.getElementById('alternate').innerHTML = inH;
        document.getElementById('installed-plugin-version').innerHTML = "Failed to load!";
      }

      function showSky() {
        if (!geEnabled) return false;
        ge.getOptions().setMapType(ge.MAP_TYPE_SKY);
        setTimeout(function() {
          // Zoom in on a nebula.
          var oldFlyToSpeed = ge.getOptions().getFlyToSpeed();
          ge.getOptions().setFlyToSpeed(.2);  // Slow down the camera flyTo speed.
          var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND); // View the Horsehead Nebula.
          lookAt.set(-2.45, -94.721916666666666666666666666667, 0,
                        ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 36817);
          ge.getView().setAbstractView(lookAt);
          ge.getOptions().setFlyToSpeed(oldFlyToSpeed);
        }, 500);  // Start the zoom-in after one second.
        return false;
      }

      function getCoords(q, tName) {
        //showSky();
        //alert("initializing Telescope.");
        showDiv("telescope");
        if (tName != data.name) return false;
        if (q == "") return false;
        var i = document.getElementById("sf2");
        var URL = "getCoords.php";
        //alert("URL = " + URL);//http://www.google.com/url?sa=D&q=http://www.google.com/maps%3Foutput%3Dkml%26q%3Dsky:Barnard%252033%26hl%3Den&usg=AFQjCNFiUA6dicO0gisiO_YaifFqMBTeoQ
        var ajax = new ajaxRequestObject();
        //var nul = ajaxFunction(ajax, URL, "outputDiv");
        var params = "q=" + q;
        params += (i.checked === true) ? "&imageOnly=1" : "";
        params += (geEnabled === true) ? "" : "&geDisabled=1";
        var nul = ajaxPostEval(ajax, URL, params, false);
        //deleteNotification(data.name, q, "telescope")
        return false;
      }

      function scopeNav() {
        document.getElementById('map3d').style.visibility = "visible";
        document.getElementById('alternate').style.visibility = "hidden";
        //if (lat.value == "" || lon.value == "") return false;
        latitude  *= 1;
        longitude *= 1;
        //alert ("latitude = " + latitude);
        var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
        lookAt.setLatitude(latitude);
        lookAt.setLongitude(longitude);
        ge.getView().setAbstractView(lookAt);
        return false;
      }

      function switchFrames(e) {
        //alert(e.value);
        switch (e.value * 1) {
          case 1:
            document.getElementById('map3d').style.visibility = "visible";
            document.getElementById('alternate').style.visibility = "hidden";
            break;
          default:
            document.getElementById('map3d').style.visibility = "hidden";
            document.getElementById('alternate').style.visibility = "visible";
        }
      }

      function showDiv(div) {
        document.getElementById(div).style.visibility = "visible";
      }
      function showScope() {
        var t = document.getElementById("telescope");
        var m = document.getElementById("map3d");
        var a = document.getElementById("alternate");
        t.style.visibility = "visible";
        if (geEnabled) m.style.visibility = "visible";
        else a.style.visibility = "visible";
      }

