/************************************************************************
** googleearth.js
**
** Description:
** googleearth.js stores all of the common routines and vars necessary
** to perform Google Earth integration.  Include this script in any page
** that requires Google Earth.
**
** Note:  It is assumed that you have registered your URL for a key
**		  to use Google mapping.  See http://www.google.com/apis/maps/
**		  for more information
**
** Prior to including this file, you should issue a line similar to the
** following in your page:
** 	<script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAbzEDVQfFk5sIOvGK-Y7OuBTqUM-tBxgpJWnk6YvqKRS_ByyapxQSgZnieK65DiDvpMfZlgo3GFBVOQ" type="text/javascript"></script>
** needless to say, the key=<value> should be your registered key
**
**
*************************************************************************/

var ge = null;
var geocoder;

function init() {
  geocoder = new GClientGeocoder();
  google.earth.createInstance("map3d", initCB, failureCB);
}

function initCB(object) {
  ge = object;
  ge.getWindow().setVisibility(true);
}

function failureCB(object) {
}

/* note: this function courtesy of GoogleEarth and used mainly as a GeoCoder example */
function submitLocation() {
  var address = document.getElementById('address').value;
  geocoder.getLatLng(
    address, 
    function(point) {
      if (point && ge != null) {
        var la = ge.createLookAt('');     
        la.set(point.y, point.x, 100, ge.ALTITUDE_RELATIVE_TO_GROUND, 
               0, 0, 4000);
        ge.getView().setAbstractView(la);
      }
    }
  );
}

function showControls() {
	var navControl = ge.getNavigationControl();
  	navControl.setVisibility(ge.VISIBILITY_SHOW);
}

function hideControls() {
	var navControl = ge.getNavigationControl();
	navControl.setVisibility(ge.VISIBILITY_HIDE);
}
