//turn on RSH on the page
if (navigator.userAgent.indexOf('Safari') == -1 && navigator.userAgent.indexOf('MSIE') == -1)
  var dHist = true;
//create and render the Map, Photos, and ? Tabs
function addMainTabs(menuWidget) {
  var tab = new Tab();
  tab.title = 'Map';
  var div = dec('div');  
  div.style.height = '100%';
  var innerDiv = dec('div')
  innerDiv.id = 'reportListId'
  innerDiv.style.height = '100%';
  var iiDiv = dec('div');
  var h1 = dec('h1');
  h1.appendChild(dct('Using the Map'));
  iiDiv.appendChild(h1);
  iiDiv.appendChild(tipsHTML());
  innerDiv.appendChild(iiDiv);
  div.appendChild(innerDiv);
  tab.html = div;
  menuWidget.addTab(tab, true);        
  menuWidget.addBasicTab('Pics', 'photosId') 
  menuWidget.addBasicTab('?','helpId');  
  menuWidget.refresh();
  return menuWidget;
}
//create and render the ReportList, PhotoWidget, and Help
function renderMainWidgets() {
  //override the ReportList callback, the news page uses the normal callback
  ReportList.prototype.getReportsCallback = ReportList.prototype.searchCallback;
  placeSearchWidget = new ReportList('reportListId');
  map.registerWidget(placeSearchWidget);
  map.search = placeSearchWidget;
  var commentWidget = new CommentWidget();
  map.registerWidget(commentWidget);
  map.commentWidget = commentWidget;
  var photoWidget = new PhotoWidget('photosId');
  map.registerWidget(photoWidget);
  gel('photosId').style.height = '100%';
  photoWidget.photosDiv.appendChild(photoWidget.initialText())
  gel('helpId').appendChild(helpHTML());      
  addStandardMapControls();
}
//adds controls
function addStandardMapControls() {
  map.addControl(new DataControl())
  map.addControl(new SearchControl());
  map.addControl(new AmazonControl())
  map.addControl(new DownloadControl);
  map.addControl(new HomeControl);
  //map.addControl(new CoordsControl);
  addLegend();
  addDragzoom();
  /*var adPos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 85));  
  map.gam = new GAdsManager(map, "ca-pub-9746116471259182", {"style": 'adunit', 
	                                              "position": adPos, 
	                                              "minZoomLevel": 10, 
	                                              "maxAdsOnMap": 2}); 
  map.gamListener = GEvent.addListener(map,'zoomend', function() {
    if (map.getZoom() > 8) {
      map.gam.enable();    
    } else {
      map.gam.disable();    
    }
    });*/
    fetchAds("Home", "Books");

  GEvent.addListener(map, 'singlerightclick', function(latLng, src, overlay){
    latLng = map.fromContainerPixelToLatLng(latLng);
    if (map.clickMarker) {
      map.removeOverlay(map.clickMarker);
      map.clickMarker = null;
    }
    map.clickMarker = new GMarker(latLng);
    map.addOverlay(map.clickMarker);
    var geocoder = new GClientGeocoder();
    geocoder.getLocations(latLng, showInfoWindow);
  });

}
