$(document).ready( function() {
  /** Sponsor rotator */
  if( $('.show-off').children().length > 1 ) {
    $('.show-off').jshowoff({
      effect: 'fade',
      speed:7000,
      changeSpeed: 3500,
      controls: false,
      links: false,
      hoverPause: true
    });
  }

  /** Google maps API */
  if( GBrowserIsCompatible() ) {
    var map      = new GMap2( document.getElementById( 'map-canvas' ) );
    var geocoder = new GClientGeocoder();

    geocoder.getLatLng(
      '17558 Dry Mill Road, 20175',
      function( point ) {
        if( !point ) {
          alert( address + ' not found' );
        }
        else {
          map.setCenter( point, 14 );
          var marker = new GMarker( point );
          map.addOverlay( marker );
        }
      }
    );
  }

  $('#drive-it').click( function( e ) {
    var directionsPanel = document.getElementById( 'route' );
    var directions      = new GDirections( map, directionsPanel);
    
    e.preventDefault();
    
    $(this).colorbox({
      inline: true,
      innerWidth: 500,
      innerHeight: 600,
      href: '#route',
      onCleanup: function() {
        /**
         * If we don't empty the element, the directions just appear
         * beneath the map when the colorbox closes.
         */
        $('#route').empty();
      }    
    });
    directions.load( 'from: ' + $('#from').val() + ' to: 17558 Dry Mill Road, 20175' );
  });
});

$(window).unload( function() {
  GUnload();
});

