// JavaScript Document
// <![CDATA[

var DS_ge;
var DS_geHelpers;
var DS_map;

google.load("jquery", "1");
google.load("maps", "2.99");
google.load("earth", "1");

function DS_init() {
  $('#directions-form input').attr('disabled', 'disabled');
  $('#simulator-form input').attr('disabled', 'disabled');
  
  google.earth.createInstance(
    'earth',
    function(ge) {
      DS_ge = ge;
      DS_ge.getWindow().setVisibility(true);
      DS_ge.getLayerRoot().enableLayerById(DS_ge.LAYER_BUILDINGS, true);
      DS_ge.getLayerRoot().enableLayerById(DS_ge.LAYER_BORDERS, true);
	  DS_ge.getLayerRoot().enableLayerById(DS_ge.LAYER_TERRAIN, true);
	  DS_goDirections();

      DS_geHelpers = new GEHelpers(DS_ge);
      
      DS_ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
      
      DS_map = new GMap2($('#map-container').get(0));
      DS_map.setCenter(new GLatLng(52.09, 19.18), 5);
      DS_map.addControl(new GSmallMapControl());
      DS_map.enableContinuousZoom();
      
      $('#directions-form input').removeAttr('disabled');
    },
    function() {
      alert('Nie udało się załadować Widoku Satelitarnego!');
    });

function submitLocation() {
  var address = el('address').value;
  geocoder.getLatLng(
    address, 
    function(point) {
      if (point && geMaster != null)
        var la = DS_geMaster.createLookAt('');
        la.set(point.y, point.x, 0, DS_geMaster.ALTITUDE_RELATIVE_TO_GROUND, 
               100, 0, 1000000);
        DS_geMaster.getView().setAbstractView(la);
    }
  );
}

  function onresize() {
    var clientHeight = document.documentElement.clientHeight;

    $('#route-details, #earth-container, #map-container').each(function() {
      $(this).css({
        height: (clientHeight - $(this).position().top - 30).toString() + 'px' });      
    });
  }
  
  $(window).resize(onresize);
  onresize();
}

google.setOnLoadCallback(DS_init);


// ]]>
