var debug = 0;
var startZoom = 7;
var initMapType = G_SATELLITE_MAP;
if (debug) alert("Start");
var map = null;
var mgr = null;
var userAdded = 0;
var toc_hidden = 0;
var callbacklayer;

var layers = {
    "sav08": 
     {"url": "http://ware.vims.edu/ArcGIS/rest/services/sav2008google/MapServer",
      "link": "http://web.vims.edu/bio/sav/sav08/quadindex.html",
      "name": "2008 SAV",
      "type": "ArcGisService",
      "visible": true,
      "legend": "0-11:images/gm_sav08_beds.png:26;12-20:images/gm_sav08_beds_with_density.png:55",
      "id": 0},
    "areacharts":
     {"url": "",
      "link": "http://web.vims.edu/bio/sav/BayAreaChart.htm",
      "name": "SAV Area Charts",
      "type": "MarkerManager",
      "visible": true,
      "legend": "",
      "id": 2},
    "segments":
     {"url": "http://web.vims.edu/bio/sav/googlemap/kml/segments.kmz",
      "link": "http://web.vims.edu/bio/sav/sav07/bayseg.html",
      "name": "Segments",
      "type": "KML",
      "visible": false,
      "legend": "",
      "id": 1}
  };
if (debug) alert("Variables initalized");
// Creates a marker using the image.
function createMarker(lat,long, image,url) {
    var point = new GLatLng(lat, long);
    var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(50, 34);
    baseIcon.shadowSize = new GSize(50, 34);
    baseIcon.iconAnchor = new GPoint(25, 15);
    baseIcon.infoWindowAnchor = new GPoint(25, 15);
    baseIcon.imageMap = new Array(0,0,50,0,50,30,0,30,0,0);
    var chartIcon = new GIcon(baseIcon);
    
    chartIcon.image = "http://web.vims.edu/bio/sav/googlemap/charts/" + image.split('.')[0] + "_icon." + image.split('.')[1];
  //  chartIcon.image = "http://web.vims.edu/bio/sav/googlemap/charts/BayAreaChart_icon.png";

    // Set up our GMarkerOptions object
    markerOptions = { icon:chartIcon };
    var marker = new GMarker(point, markerOptions);

    GEvent.addListener(marker, "click", function() {
    var InfoWindowSource = "<a href='" + url + "' target='_blank'>"
    InfoWindowSource = InfoWindowSource + "<img border='0' height='200' width='373' src='http://web.vims.edu/bio/sav/googlemap/charts/" +         image + "'></a>";
    marker.openInfoWindowHtml(InfoWindowSource);
    });
    return marker;
}

// Create a chart at a location
function addChart(map, lat, long, image) {
    var point = new GLatLng(lat, long);
    map.addOverlay(createMarker(point, image));
}

// Add a TOC row
function addTR(id,zoomLevel) {
    if (debug) alert("AddTR1 " + layers[id].name);
    var layerTR = document.createElement("tr");
    var inputTD = document.createElement("td");
    var input = document.createElement("input");
    input.type = "checkbox";
    input.id = "check_" + id;
 //   input.defaultchecked = layers[id].visible;
    if (debug) alert("AddTR setting checkbox " + layers[id].visible);
    if (layers[id].type == "KML") {
        input.onclick = function () { toggleGeoXML(this.id, this.checked) };
    } else if (layers[id].type == "ArcGisService") {
        input.onclick = function () { toggleArcGisService(this.id, this.checked) };
    } else if (layers[id].type == "MarkerManager") {
        input.onclick = function () { toggleMarkerManager(this.id, this.checked) };
    }    
    inputTD.appendChild(input);
    var nameTD = document.createElement("td");
    var nameA = document.createElement("a");
    nameA.href = layers[id].link;
    nameA.target = "_blank";
    var name = document.createTextNode(layers[id].name);
    nameA.appendChild(name);
    nameTD.appendChild(nameA);
    
    // Add legend control
    var imgTD = document.createElement("td");
    var image = document.createElement("img");
    if (layers[id].legend != "") {
       image.src = "images/expanded.png";
       image.onclick = function () { toggleTOC(this.id) };
    } else {
        image.src = "images/space.png";
    }
    image.width = 11;
    image.height = 12;
    image.id = "toc_" + id;
    imgTD.appendChild(image);
    layerTR.appendChild(imgTD);
    layerTR.appendChild(inputTD);
    layerTR.appendChild(nameTD);
    document.getElementById("sidebarTBODY").appendChild(layerTR);
    if (layers[id].legend != "") {
       var LegendTR = document.createElement("tr");
       LegendTR.id = "Legend_" + id;
       var LegendTD = document.createElement("td");
       var thisLegendImage = document.createElement("img");
       thisLegendImage.src = LegendImage(id,zoomLevel);
       thisLegendImage.id = "LegendImage_" + id;
       LegendTD.colSpan = 3;
       LegendTD.appendChild(thisLegendImage);
       LegendTR.appendChild(LegendTD);
       LegendTR.style.display = '';
       document.getElementById("sidebarTBODY").appendChild(LegendTR);
       document.getElementById("sidebar").style.height = document.getElementById("sidebar").clientHeight + LegendTR.clientHeight;
       document.getElementById("toc_inner").style.height = document.getElementById("toc_inner").clientHeight + LegendTR.clientHeight;
    }

    document.getElementById(input.id).checked = layers[id].visible;
     if (layers[id].type == "KML") {
        toggleGeoXML("check_" + id, layers[id].visible);
    } else if (layers[id].type == "ArcGisService") {
        toggleArcGisService("check_" + id, layers[id].visible);
    } else if (layers[id].type == "MarkerManager") {
        toggleMarkerManager("check_" + id, layers[id].visible);
    }    
 
   
}

function toggleGeoXML(id, checked) {
    var layerID = id.split("_")[1];
    if (checked) {
        var geoXml = new GGeoXml(layers[layerID].url);
        layers[layerID].geoXml = geoXml;

        map.addOverlay(geoXml);
    } else if (layers[layerID].geoXml) {
        map.removeOverlay(layers[layerID].geoXml);
    }
}

function toggleArcGisService(id, checked) {
    var layerID = id.split("_")[1];
    if (checked) {
        callbacklayer = layerID;
        var dynamicMap = new esri.arcgis.gmaps.DynamicMapServiceLayer
          (layers[layerID].url,
          null, 1, dynmapcallback);
//        var tiledMap = new esri.arcgis.gmaps.TiledMapServiceLayer
//          (layers[layerID].url,
//          null, tiledmapcallback);
    } else if (layers[layerID].geoXml) {
        map.removeOverlay(layers[layerID].geoXml);
    }
}

function toggleMarkerManager(id, checked) {
    if (checked) {
       window.setTimeout(setupChartMarkers, 0);
    } else {
        mgr.clearMarkers();
    }
}

function dynmapcallback(mapservicelayer) {
    if (debug) alert("dynmapcallback " & callbacklayer);
    layers[callbacklayer].geoXml = mapservicelayer;
    map.addOverlay(mapservicelayer);
}

function tiledmapcallback(mapservicelayer) {
    if (debug) alert("tiledmapcallback " & callbacklayer);
    layers[callbacklayer].geoXml = mapservicelayer;
    map.addOverlay(mapservicelayer);
}


function toggleTOC(id) {
    var image = document.getElementById(id);
    var LayerID = id.substring(4,id.length);
    var LegendTR = document.getElementById("Legend_" + LayerID);
    if (image.src.indexOf("images/closed.png") != -1) {
        image.src = "images/expanded.png";
        LegendTR.style.display = '';
        document.getElementById("sidebar").style.height = document.getElementById("sidebar").clientHeight + LegendTR.clientHeight;
        document.getElementById("toc_inner").style.height = document.getElementById("toc_inner").clientHeight + LegendTR.clientHeight;

    } else {
        image.src = "images/closed.png";
        document.getElementById("sidebar").style.height = document.getElementById("sidebar").clientHeight - LegendTR.clientHeight;
        document.getElementById("toc_inner").style.height = document.getElementById("toc_inner").clientHeight - LegendTR.clientHeight;
        LegendTR.style.display = 'none';
    }
}

function adjustTOC(zoomLevel) {
    for(var layer in layers) {
        if (layers[layer].legend != "") {
            var thisLegendImage = document.getElementById("LegendImage_" + layer);
            var currentHeight = thisLegendImage.height;
            thisLegendImage.src = LegendImage(layer,zoomLevel);
            thisLegendImage.height = LegendHeight(layer,zoomLevel);
            var image = document.getElementById("toc_" + layer);
            // Adjust TOC box height if expanded
            if (image.src.indexOf("images/expanded.png") != -1) {
                document.getElementById("sidebar").style.height = document.getElementById("sidebar").clientHeight - currentHeight + thisLegendImage.height + "px";
                document.getElementById("toc_inner").style.height = document.getElementById("toc_inner").clientHeight - currentHeight + thisLegendImage.height + "px";
            }
            if (debug) alert("check_" + layer + ":" + image.src + ":" + image.src.indexOf("images/expanded.png") + ":" + zoomLevel + ":" + currentHeight + ":" + thisLegendImage.height);
        }
    }
}

function LegendImage(layerID, zoomlevel) {
    var legendStr = layers[layerID].legend;
    var legends = legendStr.split(";");
    for(var legend in legends) {
        var scaleRange = legends[legend].split(":")[0];
        var scaleImage = legends[legend].split(":")[1];
        var scaleRangeStart = scaleRange.split("-")[0];
        if (scaleRange.split("-").length == 2) {
           var scaleRangeEnd = scaleRange.split("-")[1];
        } else {
            var scaleRangeEnd = scaleRangeStart;
        }
        if (zoomlevel >= scaleRangeStart && zoomlevel <= scaleRangeEnd) {
            return scaleImage;
        }
    }
    return null;
}

function LegendHeight(layerID, zoomlevel) {
    var legendStr = layers[layerID].legend;
    var legends = legendStr.split(";");
    for(var legend in legends) {
        var scaleRange = legends[legend].split(":")[0];
        var scaleHeight = legends[legend].split(":")[2];
        var scaleRangeStart = scaleRange.split("-")[0];
        if (scaleRange.split("-").length == 2) {
           var scaleRangeEnd = scaleRange.split("-")[1];
        } else {
            var scaleRangeEnd = scaleRangeStart;
        }
        if (zoomlevel >= scaleRangeStart && zoomlevel <= scaleRangeEnd) {
            return scaleHeight;
        }
    }
    return null;
}   

function initialize() {
    if (GBrowserIsCompatible()) {
        if (debug) alert("Test");
        map = new GMap2(document.getElementById("googlemap"));
        if (debug) alert("Test0a");
        // var mgrOptions = { borderPadding: 50, maxZoom: 15, trackMarkers: true };
        if (debug) alert("Test0b");
        if (debug) alert("Test0cb");
	map.setMapType(initMapType);
        map.setCenter(new GLatLng(38, -76), startZoom);

        map.setUIToDefault();
        map.enableGoogleBar();
        if (debug) alert("Test8");
        ov = new GOverviewMapControl(null);
        map.addControl(ov);
        
	if (debug) alert("Test1");
        for(var layer in layers) {
            if (debug) alert("In addTR loop: " + layers[layer].name);
            addTR(layer,startZoom);
        }
        adjustTOC(startZoom);

        GEvent.addListener(map, "zoomend", function (oldLevel, newLevel) { 
                adjustTOC(newLevel);
            }
       ); 
     }
  
}

function getBayChartMarkers() {
    var chartMarkers = [];
    var BayURL = "http://www.vims.edu/bio/sav/BayAreaChart.htm";
    if (debug) alert("getSegmentChartMarkers");
    chartMarkers.push(createMarker(38.6275727394043,-76.4036693715216,"BayAreaChart.png",BayURL));
    return chartMarkers;
}

function getZoneChartMarkers() {
    var chartMarkers = [];
    var ZoneURL = "http://www.vims.edu/bio/sav/ZoneAreaChart.htm?Zone=";
    if (debug) alert("getSegmentChartMarkers");
    chartMarkers.push(createMarker(39.1039324934,-76.3166516696,"ZoneAreaChartUpper.png",ZoneURL + "1"));
    chartMarkers.push(createMarker(38.4009474002,-76.4353969843,"ZoneAreaChartMiddle.png",ZoneURL + "2"));
     chartMarkers.push(createMarker(37.3719296507,-76.2205347256,"ZoneAreaChartLower.png", ZoneURL + "3"));
    return chartMarkers;
}

function getSegmentChartMarkers() {
    var chartMarkers = [];
    var SegmentURL = "http://www.vims.edu/bio/sav/SegmentAreaChart.htm?Segment=";
    if (debug) alert("getSegmentChartMarkers");
    chartMarkers.push(createMarker(38.4141688724,-75.0866347621,"SegmentAreaChartAAWPH.png",SegmentURL + "AAWPH"));
    chartMarkers.push(createMarker(38.8910333353,-76.9935651207,"SegmentAreaChartANATF.png",SegmentURL + "ANATF"));
    chartMarkers.push(createMarker(37.2641967061,-77.430892276,"SegmentAreaChartAPPTF.png",SegmentURL + "APPTF"));
    chartMarkers.push(createMarker(39.2746456501,-76.4455414241,"SegmentAreaChartBACOH.png",SegmentURL + "BACOH"));
    chartMarkers.push(createMarker(38.0448272346,-75.7809033138,"SegmentAreaChartBIGMH1.png",SegmentURL + "BIGMH1"));
    chartMarkers.push(createMarker(38.0917392359,-75.7203787556,"SegmentAreaChartBIGMH2.png",SegmentURL + "BIGMH2"));
    chartMarkers.push(createMarker(39.4579139734,-75.8994888529,"SegmentAreaChartBOHOH.png",SegmentURL + "BOHOH"));
    chartMarkers.push(createMarker(39.3715512644,-76.2631329461,"SegmentAreaChartBSHOH.png",SegmentURL + "BSHOH"));
    chartMarkers.push(createMarker(39.524053527,-75.8291902133,"SegmentAreaChartCDOH.png",SegmentURL + "CDOH"));
    chartMarkers.push(createMarker(39.4386639286,-76.0602595205,"SegmentAreaChartCB1TF1.png",SegmentURL + "CB1TF1"));
    chartMarkers.push(createMarker(39.5060902357,-76.0495245406,"SegmentAreaChartCB1TF2.png",SegmentURL + "CB1TF2"));
    chartMarkers.push(createMarker(39.3169747491,-76.2067278696,"SegmentAreaChartCB2OH.png",SegmentURL + "CB2OH"));
    chartMarkers.push(createMarker(39.1039324934,-76.3166516696,"SegmentAreaChartCB3MH.png",SegmentURL + "CB3MH"));
    chartMarkers.push(createMarker(38.5650272278,-76.4257926892,"SegmentAreaChartCB4MH.png",SegmentURL + "CB4MH"));
    chartMarkers.push(createMarker(37.7670702287,-76.2853019581,"SegmentAreaChartCB5MH.png",SegmentURL + "CB5MH"));
    chartMarkers.push(createMarker(37.4314265713,-76.19827445,"SegmentAreaChartCB6PH.png",SegmentURL + "CB6PH"));
    chartMarkers.push(createMarker(37.4369745575,-76.0691644599,"SegmentAreaChartCB7PH.png",SegmentURL + "CB7PH"));
    chartMarkers.push(createMarker(36.9880157306,-76.1404661531,"SegmentAreaChartCB8PH.png",SegmentURL + "CB8PH"));
    chartMarkers.push(createMarker(37.3764481265,-76.9036238316,"SegmentAreaChartCHKOH.png",SegmentURL + "CHKOH"));
    chartMarkers.push(createMarker(38.0518228887,-75.2962893527,"SegmentAreaChartCHNPH.png",SegmentURL + "CHNPH"));
    chartMarkers.push(createMarker(38.6856321526,-76.1908777332,"SegmentAreaChartCHOMH1.png",SegmentURL + "CHOMH1"));
    chartMarkers.push(createMarker(38.598625683,-76.0282287697,"SegmentAreaChartCHOMH2.png",SegmentURL + "CHOMH2"));
    chartMarkers.push(createMarker(38.7371332865,-75.9427734767,"SegmentAreaChartCHOOH.png",SegmentURL + "CHOOH"));
    chartMarkers.push(createMarker(38.8575853008,-75.8943062559,"SegmentAreaChartCHOTF.png",SegmentURL + "CHOTF"));
    chartMarkers.push(createMarker(38.9903879047,-76.2203244901,"SegmentAreaChartCHSMH.png",SegmentURL + "CHSMH"));
    chartMarkers.push(createMarker(39.1723889644,-76.0197880773,"SegmentAreaChartCHSOH.png",SegmentURL + "CHSOH"));
    chartMarkers.push(createMarker(39.2599176485,-75.9502574859,"SegmentAreaChartCHSTF.png",SegmentURL + "CHSTF"));
    chartMarkers.push(createMarker(37.7378984406,-76.4581905783,"SegmentAreaChartCRRMH.png",SegmentURL + "CRRMH"));
    chartMarkers.push(createMarker(38.8739229523,-76.284610291,"SegmentAreaChartEASMH.png",SegmentURL + "EASMH"));
    chartMarkers.push(createMarker(36.8451341441,-76.2473519059,"SegmentAreaChartEBEMH.png",SegmentURL + "EBEMH"));
    chartMarkers.push(createMarker(36.8375549595,-76.3279952905,"SegmentAreaChartELIPH.png",SegmentURL + "ELIPH"));
    chartMarkers.push(createMarker(39.4278857225,-75.9598656098,"SegmentAreaChartELKOH1.png",SegmentURL + "ELKOH1"));
    chartMarkers.push(createMarker(39.5801315365,-75.8290494331,"SegmentAreaChartELKOH2.png",SegmentURL + "ELKOH2"));
    chartMarkers.push(createMarker(38.3887990468,-76.0450633846,"SegmentAreaChartFSBMH.png",SegmentURL + "FSBMH"));
    chartMarkers.push(createMarker(39.329986351,-76.3221742492,"SegmentAreaChartGUNOH1.png",SegmentURL + "GUNOH1"));
    chartMarkers.push(createMarker(39.3761646483,-76.3220971987,"SegmentAreaChartGUNOH2.png",SegmentURL + "GUNOH2"));
    chartMarkers.push(createMarker(38.3026596389,-76.1390039365,"SegmentAreaChartHNGMH.png",SegmentURL + "HNGMH"));
    chartMarkers.push(createMarker(38.3753213306,-75.1038937919,"SegmentAreaChartIOWPH.png",SegmentURL + "IOWPH"));
    chartMarkers.push(createMarker(37.0253432659,-76.5489899304,"SegmentAreaChartJMSMH.png",SegmentURL + "JMSMH"));
    chartMarkers.push(createMarker(37.1884574402,-76.7900212366,"SegmentAreaChartJMSOH.png",SegmentURL + "JMSOH"));
    chartMarkers.push(createMarker(36.9910642129,-76.3337486121,"SegmentAreaChartJMSPH.png",SegmentURL + "JMSPH"));
    chartMarkers.push(createMarker(37.2880240709,-77.1454043022,"SegmentAreaChartJMSTF1.png",SegmentURL + "JMSTF1"));
    chartMarkers.push(createMarker(37.4192730462,-77.264400885,"SegmentAreaChartJMSTF2.png",SegmentURL + "JMSTF2"));
    chartMarkers.push(createMarker(36.915219888,-76.3044543197,"SegmentAreaChartLAFMH.png",SegmentURL + "LAFMH"));
    chartMarkers.push(createMarker(38.5186589543,-76.295377533,"SegmentAreaChartLCHMH.png",SegmentURL + "LCHMH"));
    chartMarkers.push(createMarker(36.8994538014,-76.0346350128,"SegmentAreaChartLYNPH.png",SegmentURL + "LYNPH"));
    chartMarkers.push(createMarker(39.0668806915,-76.4615344897,"SegmentAreaChartMAGMH.png",SegmentURL + "MAGMH"));
    chartMarkers.push(createMarker(38.127096201,-75.8669184805,"SegmentAreaChartMANMH1.png",SegmentURL + "MANMH1"));
    chartMarkers.push(createMarker(38.1570967964,-75.7255969094,"SegmentAreaChartMANMH2.png",SegmentURL + "MANMH2"));
    chartMarkers.push(createMarker(38.5720861708,-77.1471353876,"SegmentAreaChartMATTF.png",SegmentURL + "MATTF"));
    chartMarkers.push(createMarker(39.312229539,-76.4011694818,"SegmentAreaChartMIDOH.png",SegmentURL + "MIDOH"));
    chartMarkers.push(createMarker(37.2280041147,-76.3407876159,"SegmentAreaChartMOBPH.png",SegmentURL + "MOBPH"));
    chartMarkers.push(createMarker(37.6147819298,-76.7970306034,"SegmentAreaChartMPNOH.png",SegmentURL + "MPNOH"));
    chartMarkers.push(createMarker(37.7225391796,-76.9518502869,"SegmentAreaChartMPNTF.png",SegmentURL + "MPNTF"));
    chartMarkers.push(createMarker(38.3356058256,-75.836633696,"SegmentAreaChartNANMH.png",SegmentURL + "NANMH"));
    chartMarkers.push(createMarker(38.4517424447,-75.7375751654,"SegmentAreaChartNANOH.png",SegmentURL + "NANOH"));
    chartMarkers.push(createMarker(38.5834055938,-75.710723481,"SegmentAreaChartNANTF.png",SegmentURL + "NANTF"));
    chartMarkers.push(createMarker(39.5520714677,-75.9828595497,"SegmentAreaChartNORTF.png",SegmentURL + "NORTF"));
    chartMarkers.push(createMarker(39.1827508016,-76.491726138,"SegmentAreaChartPATMH.png",SegmentURL + "PATMH"));
    chartMarkers.push(createMarker(38.4174993512,-76.5883549676,"SegmentAreaChartPAXMH1.png",SegmentURL + "PAXMH1"));
    chartMarkers.push(createMarker(38.5114013481,-76.6886410294,"SegmentAreaChartPAXMH2.png",SegmentURL + "PAXMH2"));
    chartMarkers.push(createMarker(38.3497061065,-76.435216549,"SegmentAreaChartPAXMH3.png",SegmentURL + "PAXMH3"));
    chartMarkers.push(createMarker(38.3384475676,-76.5246423178,"SegmentAreaChartPAXMH4.png",SegmentURL + "PAXMH4"));
    chartMarkers.push(createMarker(38.4239413684,-76.4780674038,"SegmentAreaChartPAXMH5.png",SegmentURL + "PAXMH5"));
    chartMarkers.push(createMarker(38.4383172081,-76.5304741509,"SegmentAreaChartPAXMH6.png",SegmentURL + "PAXMH6"));
    chartMarkers.push(createMarker(38.6228873524,-76.6776985976,"SegmentAreaChartPAXOH.png",SegmentURL + "PAXOH"));
    chartMarkers.push(createMarker(38.7666354452,-76.6829331416,"SegmentAreaChartPAXTF.png",SegmentURL + "PAXTF"));
    chartMarkers.push(createMarker(37.5030982684,-76.3965585207,"SegmentAreaChartPIAMH.png",SegmentURL + "PIAMH"));
    chartMarkers.push(createMarker(38.690052551,-76.9923704763,"SegmentAreaChartPISTF.png",SegmentURL + "PISTF"));
    chartMarkers.push(createMarker(37.5509480758,-76.9041765394,"SegmentAreaChartPMKOH.png",SegmentURL + "PMKOH"));
    chartMarkers.push(createMarker(37.615232553,-77.0274216769,"SegmentAreaChartPMKTF.png",SegmentURL + "PMKTF"));
    chartMarkers.push(createMarker(37.8757052374,-75.7578706328,"SegmentAreaChartPOCMH.png",SegmentURL + "POCMH"));
    chartMarkers.push(createMarker(37.9822846048,-75.5815996403,"SegmentAreaChartPOCOH.png",SegmentURL + "POCOH"));
    chartMarkers.push(createMarker(38.1334268952,-75.5202911287,"SegmentAreaChartPOCTF.png",SegmentURL + "POCTF"));
    chartMarkers.push(createMarker(38.1839997673,-76.6604422275,"SegmentAreaChartPOTMH.png",SegmentURL + "POTMH"));
    chartMarkers.push(createMarker(38.3553834719,-77.1803240824,"SegmentAreaChartPOTOH1.png",SegmentURL + "POTOH1"));
    chartMarkers.push(createMarker(38.5152399444,-77.0174850895,"SegmentAreaChartPOTOH2.png",SegmentURL + "POTOH2"));
    chartMarkers.push(createMarker(38.4691150316,-77.1511069304,"SegmentAreaChartPOTOH3.png",SegmentURL + "POTOH3"));
    chartMarkers.push(createMarker(38.6017744344,-77.2234681317,"SegmentAreaChartPOTTF.png",SegmentURL + "POTTF"));
    chartMarkers.push(createMarker(38.8878634372,-76.5481692076,"SegmentAreaChartRHDMH.png",SegmentURL + "RHDMH"));
    chartMarkers.push(createMarker(37.8194968277,-76.6750009409,"SegmentAreaChartRPPMH.png",SegmentURL + "RPPMH"));
    chartMarkers.push(createMarker(38.0237346906,-76.9594363048,"SegmentAreaChartRPPOH.png",SegmentURL + "RPPOH"));
    chartMarkers.push(createMarker(38.130915509,-77.1552618017,"SegmentAreaChartRPPTF.png",SegmentURL + "RPPTF"));
    chartMarkers.push(createMarker(39.3762665559,-76.0252426536,"SegmentAreaChartSASOH1.png",SegmentURL + "SASOH1"));
    chartMarkers.push(createMarker(39.3821236934,-75.901637345,"SegmentAreaChartSASOH2.png",SegmentURL + "SASOH2"));
    chartMarkers.push(createMarker(36.7979084822,-76.3211105478,"SegmentAreaChartSBEMH.png",SegmentURL + "SBEMH"));
    chartMarkers.push(createMarker(38.997225525,-76.5193352373,"SegmentAreaChartSEVMH.png",SegmentURL + "SEVMH"));
    chartMarkers.push(createMarker(38.9162278137,-76.4948316397,"SegmentAreaChartSOUMH.png",SegmentURL + "SOUMH"));
    chartMarkers.push(createMarker(38.256423355,-75.1431693485,"SegmentAreaChartSPXPH.png",SegmentURL + "SPXPH"));
    chartMarkers.push(createMarker(37.4060766232,-75.7616191163,"SegmentAreaChartSVCPH.png",SegmentURL + "SVCPH"));
    chartMarkers.push(createMarker(37.9724284433,-75.9600044854,"SegmentAreaChartTANMH1.png",SegmentURL + "TANMH1"));
    chartMarkers.push(createMarker(38.2023423078,-75.9305447583,"SegmentAreaChartTANMH2.png",SegmentURL + "TANMH2"));
    chartMarkers.push(createMarker(36.8154207323,-76.4022509802,"SegmentAreaChartWBEMH.png",SegmentURL + "WBEMH"));
    chartMarkers.push(createMarker(38.8012707636,-76.7441217345,"SegmentAreaChartWBRTF.png",SegmentURL + "WBRTF"));
    chartMarkers.push(createMarker(38.2530971823,-75.7558126756,"SegmentAreaChartWICMH.png",SegmentURL + "WICMH"));
    chartMarkers.push(createMarker(38.8396327972,-76.550397837,"SegmentAreaChartWSTMH.png",SegmentURL + "WSTMH"));
    chartMarkers.push(createMarker(37.3862130196,-76.6646294299,"SegmentAreaChartYRKMH.png",SegmentURL + "YRKMH"));
    chartMarkers.push(createMarker(37.2939823502,-76.547657593,"SegmentAreaChartYRKPH.png",SegmentURL + "YRKPH"));
    return chartMarkers;
}

function setupChartMarkers() {
  mgr = new MarkerManager(map);
  mgr.addMarkers(getSegmentChartMarkers(), 9);
  mgr.addMarkers(getZoneChartMarkers(), 8,8);
  mgr.addMarkers(getBayChartMarkers(), 5,7);
  mgr.refresh();
}


function hideShowTOC() {
        if (debug) alert("hideShowTOC");
        var tocdiv = document.getElementById("sidebar");
        var tocimg = document.getElementById("hideShowTOCImage");
        if (toc_hidden) {
            tocdiv.style.visibility = 'visible'; 
            tocimg.src = "hide.png";
        } else {
            tocdiv.style.visibility = 'hidden'; 
            tocimg.src = "show.png";
        }
        toc_hidden = !toc_hidden;
       
}

