var map = null;
var geoXmlzone1;
var geoXmlzone2;
var geoXmlzone3;
var geoXmlzone4;
var geoXmlzone5;
var geoXmlzone6;
var geoXmlzone7;
var geoXmlLogos;
geoXmlzone1 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Saturday_Placemark.kmz");
geoXmlzone2 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Saturday_Route1.kmz");
geoXmlzone3 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Saturday_Route2.kmz");
geoXmlzone4 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Saturday_Route3.kmz");
geoXmlzone5 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Sunday_Placemark.kmz");
geoXmlzone6 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Sunday_Route1.kmz");
geoXmlzone7 = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Sunday_Route2.kmz");
geoXmlLogos = new GGeoXml("http://brightgis.com/bikems/atlanta/kmz/Logos.kmz");


function load() {

  if (GBrowserIsCompatible()) {
    
    document.controlsForm.name="saturdayBreakpoints".checked = true;
    document.controlsForm.name="saturdayRoute1".checked = true;
    document.controlsForm.name="saturdayRoute2".checked = true;
    document.controlsForm.name="saturdayRoute3".checked = true;
    document.controlsForm.name="sundayBreakpoints".checked = true;
    document.controlsForm.name="sundayRoute1".checked = true;
    document.controlsForm.name="sundayRoute2".checked = true;
    
    
    // define the crosshair tile layer and its required functions
    //var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
    //crossLayer.getTileUrl =  function(tile, zoom) {
    //  return "tile_crosshairs.png";
    //}
    //crossLayer.isPng = function() {return true;}
    
    // Create a new map type incorporating the tile layer
    //var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0], crossLayer ];
    //var mtTerCross = new GMapType(layerTerCross, G_PHYSICAL_MAP.getProjection(), "Ter+");

    map = new GMap2(document.getElementById("map"), { size: new GSize(1000,500) } );
    map.addMapType(G_PHYSICAL_MAP);
    //map.addMapType(mtTerCross);
    map.setCenter(new GLatLng(32.933776,-84.984741), 10);
    map.addControl(new GLargeMapControl())
    
    var mapControl = new GHierarchicalMapTypeControl();
    
    // Set up map type menu relationships
    mapControl.clearRelationships();
    mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
    //mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");
    
    // Add control after you've specified the relationships
    map.addControl(mapControl);
    
    //map.setMapType(mtTerCross);
    
    map.setMapType(G_PHYSICAL_MAP);
    
    
    
    
    
    var boundaries;
    var logo;
    boundaries = new GLatLngBounds(new GLatLng(32.92756303796283,-85.59609193695441), new GLatLng(33.08643227255177,-85.25303253260903));
    logo = new GGroundOverlay("http://brightgis.com/bikems/atlanta/graphics/aggregate.png", boundaries);
    map.addOverlay(logo);
    
    
    boundaries = new GLatLngBounds(new GLatLng(32.70104709234057,-85.6022060721622), new GLatLng(32.92421679430101,-85.24630687042));
    logo = new GGroundOverlay("http://brightgis.com/bikems/atlanta/graphics/aggregate_01.png", boundaries);
    map.addOverlay(logo);
    
    
    boundaries = new GLatLngBounds(new GLatLng(32.71834849697694,-84.63269000033733), new GLatLng(32.90481435185531,-84.33080340294205));
    logo = new GGroundOverlay("http://brightgis.com/bikems/atlanta/graphics/aggregate_02.png", boundaries);
    map.addOverlay(logo);
    
    
    boundaries = new GLatLngBounds(new GLatLng(33.09640637485524,-85.59780638830428), new GLatLng(33.19111902490416,-85.25603934129879));
    logo = new GGroundOverlay("http://brightgis.com/bikems/atlanta/graphics/callaway3.png", boundaries);
    map.addOverlay(logo);

    boundaries = new GLatLngBounds(new GLatLng(33.03831395967717,-84.95835597289208), new GLatLng(33.2396326714328,-84.47086972856813));
    logo = new GGroundOverlay("http://brightgis.com/bikems/atlanta/graphics/cox_mattedit2.png", boundaries);
    map.addOverlay(logo);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    //var trees = getNL(url);
    //trees.setVisibility(fal//);
    //map.getEarthInstance(getEarthInstanceCB);
    //kmltrees = getNL(url);
    //kmltrees.setVisibility(true);//

    //GEvent.addListener(map, "moveend", moveEnd);
    //map.addMapType(G_SATELLITE_3D_M//);
    moveEnd();

} else {
  // display a warning if the browser was not compatible
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

}

//var ge;
//function getEarthInstanceCB(object) {
//  ge = object;
//  var url = 'http://www.brightgis.com/AveryRanch/Avery.kmz';
//  kmltree = getNL(url);
//  kmltree.setVisibility(true);
//  //var url = 'http://www.brightgis.com/AveryRanch/Trees-BrightGISVersion2_EK.kmz';
//  //kmltree1 = getNL(url);
//  //kmltree1.setVisibility(true);
//  //var url = 'http://www.brightgis.com/AveryRanch/Trees2.kmz';
//  //kmltree2 = getNL(url);
//kmltree2.setVisibility(true);
//}



function moveEnd() {
  updateStatusBar()
}

function updateStatusBar() {
  checkKmz("saturdayBreakpoints");
  checkKmz("saturdayRoute1");
  checkKmz("saturdayRoute2");
  checkKmz("saturdayRoute3");
  checkKmz("sundayBreakpoints");
  checkKmz("sundayRoute1");
  checkKmz("sundayRoute2");
}



function checkKmz(kmz) {
	switch(kmz)
  {
  case "saturdayBreakpoints":
    if (!document.controlsForm.saturdayBreakpoints.checked){
      map.removeOverlay(geoXmlzone1);
      //map.removeOverlay(geoXmlLogos);
    }
    else{
    	map.addOverlay(geoXmlzone1);
    	//map.addOverlay(geoXmlLogos);
    }
    break;
  case "saturdayRoute1":
    if (!document.controlsForm.saturdayRoute1.checked)
      map.removeOverlay(geoXmlzone2)
    else
    	map.addOverlay(geoXmlzone2);
    break;
  case "saturdayRoute2":
    if (!document.controlsForm.saturdayRoute2.checked)
      map.removeOverlay(geoXmlzone3)
    else
    	map.addOverlay(geoXmlzone3);
    break;
  case "saturdayRoute3":
   if (!document.controlsForm.saturdayRoute3.checked)
      map.removeOverlay(geoXmlzone4)
    else
    	map.addOverlay(geoXmlzone4);
    break;
  case "sundayBreakpoints":
    if (!document.controlsForm.sundayBreakpoints.checked)
      map.removeOverlay(geoXmlzone5)
    else
    	map.addOverlay(geoXmlzone5);
    break;
  case "sundayRoute1":
    if (!document.controlsForm.sundayRoute1.checked)
      map.removeOverlay(geoXmlzone6)
    else
    	map.addOverlay(geoXmlzone6);
    break;
  case "sundayRoute2":
    if (!document.controlsForm.sundayRoute2.checked)
      map.removeOverlay(geoXmlzone7)
    else
    	map.addOverlay(geoXmlzone7);
    break;
  }
}