/* map.js - 
*/
var ourLatLng;
var map;
var dirRender;
var infowindow;
function mapinit () {
  ourLatLng = new google.maps.LatLng(41.82446, -88.2108);
  var myOptions = {
      zoom: 16
    , center: ourLatLng
    , mapTypeId: google.maps.MapTypeId.HYBRID
    , disableDefaultUI: false
    , mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      }
    , navigationControlOptions: {
        style: google.maps.NavigationControlStyle.SMALL
      }
  };

  dirRender = new google.maps.DirectionsRenderer();
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  dirRender.setMap(map);
  dirRender.setPanel(document.getElementById("map_directions"));

  var image = '/images/map-pin.png';
  var marker = new google.maps.Marker({
        position: ourLatLng 
      , map: map 
      , title:"D&R Classic"
      , icon: image
  });

  infowindow = new google.maps.InfoWindow({
      content: 'placeholder'
  });
  
  infowindow.setContent (document.getElementById("balloon").innerHTML)

  infowindow.open(map,marker);
  google.maps.event.addListener(marker, 'click'
    , function() { infowindow.open(map,marker); })
}
function recenter () { map.setCenter (ourLatLng); }
function getdirections () {
  from = document.getElementById("from").value;
  var directionsService = new google.maps.DirectionsService();
  if (from) { 
    dr = { destination: ourLatLng
         , origin: from
         , provideTripAlternatives: false
         , travelMode: google.maps.DirectionsTravelMode.DRIVING
         , unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
         };
    directionsService.route(dr, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        infowindow.close();
        dirRender.setDirections(response);
      }
    });

  }
  return false;
}

