// JavaScript Document
function bodyLoad() {
  highlight();
  if (GBrowserIsCompatible()){
    loadMap();
  }
}

function loadMap() {
  glotowns();
  var map = new GMap2(document.getElementById("mapdiv"));
  map.setCenter(new GLatLng(0,0),0);
  // eventually should add to search_region table so we don't need bounds
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  var bounds = new GLatLngBounds();
  var keyboard = new GKeyboardHandler(map);
    
  /* How to return gps
  GEvent.addListener(map, "click", function(overlay, point){
      if (overlay == null){
        alert('lat= ' + point.x + ' lon= ' + point.y);
      }
    });
  */
  
  //reposition map to previous postion afer closing the InfoWindow
  GEvent.addListener(map.getInfoWindow(), "closeclick", function() {
     map.returnToSavedPosition();
  });
  
  // add attraction markers
  for (var m = towns.length; m < (attArray.length); m++) {
    attractionMarker(map,'region',m,blat,blng);
  }
   
  // add town markers
  for (var m= 0; m < towns.length; m++) {
    townMarker(map,bounds,'region',towns);
  }

  map.setCenter(bounds.getCenter());
  map.setZoom(map.getBoundsZoomLevel(bounds));

} // end of loadMap()

function link(userName){
  document.location = 'http://www.wheretostay.co.za/'+ userName;
}
