      // function to load bank information
      function loadBankInformation()  {
        var request = GXmlHttp.create();
        request.open("GET", "xmls/banks.xml", true);
        request.onreadystatechange = function()  {
          if (request.readyState == 4)  {
            var xmlDoc = request.responseXML;
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            for (var j=0; j<markers.length; j++)  {
              // obtain attributes for each marker
              var lat = parseFloat(markers[j].getAttribute("lat"));
              var lon = parseFloat(markers[j].getAttribute("lon"));
              var point = new GLatLng(lat,lon);
              var bank_name = markers[j].getAttribute("name");
              var description = markers[j].getAttribute("description");
              var detailsURL = markers[j].getAttribute("url");
              var thumbnail = markers[j].getAttribute("thumbnail");
              var dives = markers[j].getAttribute("dives");
              if (detailsURL != "")  {
                var summary = '<div class="infoWindow"><b><div class="titleFrame">'+bank_name+'</div></b><p />'+description+'<br /><center><img src="images/'+thumbnail+'" width="206" height="163"></center><br /><p /><a href="'+detailsURL+'" target="_blank"><font color="navy"><b><u>More Details</u></b></a></font>&nbsp;&nbsp;<i><font color="black">(from GulfBase.org)</font></i></div>';
              }
              else {
                var summary = '<div class="infoWindow"><b><div class="titleFrame">'+bank_name+'</div></b><p />'+description+'<br /><center><img src="images/'+thumbnail+'" width="206" height="163"></center><br /></div>';
              }
              var marker = createBankMarker(point,bank_name,summary,dives);
              mapFGB.addOverlay(marker);
            }
          }
        }
        request.send(null);

        var requestimage = GXmlHttp.create();
        requestimage.open("GET", "xmls/banksimages.xml", true);
        requestimage.onreadystatechange = function()  {
          if (requestimage.readyState == 4)  {
            var xmlImage = requestimage.responseXML;
            var markers = xmlImage.documentElement.getElementsByTagName("marker");
            for (var j=0; j<markers.length; j++)  {
              // obtain attributes for each marker
              var north = parseFloat(markers[j].getAttribute("north"));
              var south = parseFloat(markers[j].getAttribute("south"));
              var east = parseFloat(markers[j].getAttribute("east"));
              var west = parseFloat(markers[j].getAttribute("west"));
              var bathyImg = markers[j].getAttribute("bathymetry");
              var reliefImg = markers[j].getAttribute("shaded_relief");
              var bathy_relief_Img = markers[j].getAttribute("bathy_shdrelief");
              var box = new GLatLngBounds(new GLatLng(south,west), new GLatLng(north,east));
              // create overlays
              banksBathyOverlay[j] = EInsert.groundOverlay(bathyImg,box,-1);
              banksReliefOverlay[j] = EInsert.groundOverlay(reliefImg,box,-1);
              banksBathyReliefOverlay[j] = EInsert.groundOverlay(bathy_relief_Img,box,-1);
              mapFGB.addOverlay(banksReliefOverlay[j]);
            }
          }
        }
        requestimage.send(null);

      }

      // initialize sidebar
      function initialize_sidebar()  {
        var sidebar_html = "";
        //sidebar_html += '<br /><div class="smallText2"><center>To view photographs, use the dropdown list to select a geologic bank or click on one of geologic banks (red dots) on the map.</center><br /><center>If there are any photographs available for a geologic bank, a new tab called "Images" can be used to access the pictures. You can view photographs by selecting a particular dive for the geologic bank.</center><br /><center>To better orient where any of the photographs have been taken, use the check box next to "Shaded Relief of Banks" to drape a relief image of the bank onto the map.</center></div>';
        sidebar_html += '<br /><div class="smallText2"><center>There are two ways to view photographs.</center><p />1) Use the dropdown list to select a geologic bank or click on one of geologic banks (red dots) on the map. If there are any photographs available for a geologic bank, a new tab called "Images" can be used to access the pictures. You can view photographs by selecting a particular dive for the geologic bank.<p />2) If the remote operated vehicle&apos;s dive tracks are drawn on the map (yellow lines), clicking on any of these lines will generate a popup window containing links to the photos of that particular dive.<p /><center>To better orient where any of the photographs have been taken, use the check box next to "Shaded Relief of Banks" to drape a relief image of the bank onto the map.</center></div>';

        document.getElementById("sidebar").innerHTML = sidebar_html;
      }             

      // function to create marker symbol for banks
      function createBankMarker(point,name,html,dives)  {
        // create icon symbol
        var icon = new GIcon();
        icon.image = "images/banks.png"; 
        icon.iconSize = new GSize(15, 15);
        icon.iconAnchor = new GPoint(10, 10);
        icon.infoWindowAnchor = new GPoint(10, 10);

        // create marker
        var marker = new GMarker(point,{icon:icon,title:name});
        marker.bankName = name;
        if (dives.length != 0)  {
          marker.dives = dives;
          var tab1 = "Overview";
          var html1 = html;
          var tab2 = "Images";
          if (navigator.appVersion.indexOf("MSIE") != -1)  {
            var bank_link = "&#39;" + name + "&#39;";
          }
          else {
            var bank_link = "&apos;" + name + "&apos;";
          }
          var html2 = '<div class="infoWindow"><b><div class="titleFrame">'+name+'</div></b>';
          html2 += '<br /><center><b>Click on a dive link to see only photographs from that particular dive.</b></center>';
          if (dives.indexOf(";") != -1)  {
            html2 += '<br /><center><input type="button" class="infoWindowButton" value="Remove Dive" onClick="removeDiveByBank('+bank_link+')"></center>';
            html2 += '<br /><table border="2" colspan="3" align="left">';
            var arrayOfDives = dives.split(";");
            var ccount = 1;
            var endOfRow = false;
            for (var j=0; j<arrayOfDives.length; j++)  {
              var individualDives = arrayOfDives[j].split(":");
              if (navigator.appVersion.indexOf("MSIE") != -1)  {
                var divetrack_link = "&#39;" + arrayOfDives[j] + "&#39;";
              }
              else {
                var divetrack_link = "&apos;" + arrayOfDives[j] + "&apos;";
              }
              if (ccount == 1)  {
                html2 += '<tr>';
              }
              html2 += '<td><a href="javascript:addDiveTrack('+divetrack_link+')"><font color="navy">'+individualDives[1]+': '+individualDives[2]+'</font></a></td>';
              if (ccount == 3)  {
                html2 += '</tr>';
                ccount = 1;
                endOfRow = true;
              }
              else  {
                ccount = ccount + 1;
                endOfRow = false;
              }
            }
            if (!endOfRow)  {
              html2 += '<td> </td></tr>';
            }
            html2 += '</table>';
            html2 += '<p />';
          }
          else {
            var individualDives = dives.split(":");
            if (navigator.appVersion.indexOf("MSIE") != -1)  {
              var divetrack_link = "&#39;" + dives + "&#39;";
            }
            else  {
              var divetrack_link = "&apos;" + dives + "&apos;"; 
            }
            html2 += '<p /><table align="center">';
            html2 += '<td><a href="javascript:addDiveTrack('+divetrack_link+')"><font color="navy">'+individualDives[1]+': '+individualDives[2]+'</font></a></td>';
            html2 += '</table>';
          }
          html2 += '</div>';
        }
        else  {
          var tab1 = "Overview";
          var html1 = html;
          var tab2 = "";
          var html2 = "";
          marker.dives = "";
        }

        GEvent.addListener(marker, "click", function()  {
          if ((html1.length != 0) && (html2.length == 0))  {
             marker.openInfoWindowTabsHtml([new GInfoWindowTab(tab1,html1)]);
          }
          if ((html1.length != 0) && (html2.length != 0))  {
             marker.openInfoWindowTabsHtml([new GInfoWindowTab(tab1,html1), new GInfoWindowTab(tab2,html2)]);
          }
        });

        bmarkers.push(marker);
        return marker;
      }

      // function to load dive information
      function loadDiveInformation()  {
        var requestpoly = GXmlHttp.create();
        requestpoly.open("GET","xmls/divetracks.xml", true);
        requestpoly.onreadystatechange = function()  {
          if (requestpoly.readyState == 4)  {
            var xmlTracks = requestpoly.responseXML;
            // obtain array of polylines and loop through it
            var polylines = xmlTracks.documentElement.getElementsByTagName("pline");
            // obtain points that make up each polyline
            for (var j=0; j<polylines.length; j++)  {
              // obtain the attributes of each pline
              var cruise = polylines[j].getAttribute("cruise");
              var dive = polylines[j].getAttribute("dive");
              var location = polylines[j].getAttribute("bank");
              var sw = polylines[j].getAttribute("sw");
              var ne = polylines[j].getAttribute("ne");
              var mapCenter = polylines[j].getAttribute("mapCenter");
              var polyPoints = polylines[j].getElementsByTagName("point");
              var points = [];
              for (var k=0; k<polyPoints.length; k++)  {
                points.push(new GLatLng(parseFloat(polyPoints[k].getAttribute("lat")), parseFloat(polyPoints[k].getAttribute("lng"))));
              }
              createDiveTrack(cruise,dive,location,sw,ne,mapCenter,points);
            }
          }
        }
        requestpoly.send(null);
      }

      // creates a divetrack
      function createDiveTrack(cruise,dive,location,sw,ne,mapCenter,points)  {
	 var pcolor = "#ffffff";
        var layerDefs = [];
        layerDefs[0] = "Cruise='";
        layerDefs[0] += cruise;
        layerDefs[0] += "'";
        layerDefs[0] += " and Dive='";
        layerDefs[0] += dive;
        layerDefs[0] += "'";
        layerDefs[0] += " and Bank='";
        layerDefs[0] += location;
        layerDefs[0] += "'";
        var imageParams = new esri.arcgis.gmaps.ImageParameters();
        imageParams.format = "png";
        imageParams.transparent = true;
        imageParams.layerIds = [3];
        imageParams.layerDefinitions = layerDefs;
        var line = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", imageParams, 1.0, null);     
        line.cruise = cruise;
        line.dive = dive;
        line.bank = location;
        line.sw = sw;
        line.ne = ne;
        line.mapCenter = mapCenter;
        dtracks.push(line);
      }

      // function to create marker symbol for dive photos
      function createDivePhotoMarker(point,title,cruise,dive,location,photo,summaryHTML,speciesHTML)  {
        // create icon symbol
        var icon = new GIcon();
        icon.image = "images/photos.png"; 
        icon.iconSize = new GSize(15, 15);
        icon.iconAnchor = new GPoint(5, 5);
        icon.infoWindowAnchor = new GPoint(5, 5);

        // create marker
        var marker = new GMarker(point,{icon:icon,title:title});
        marker.cruise = cruise;
        marker.dive = dive;
        marker.bank = location;
        marker.title = title;
    
        var tab1 = "Summary";
        var tab2 = "Species";

        GEvent.addListener(marker, "click", function()  {
          //marker.openInfoWindow(summaryHTML);
          if (speciesHTML.length == 0)  { 
            marker.openInfoWindowTabsHtml([new GInfoWindowTab(tab1,summaryHTML)]);
          }
          else  {
            marker.openInfoWindowTabsHtml([new GInfoWindowTab(tab1,summaryHTML), new GInfoWindowTab(tab2,speciesHTML)]);
          }
        });
        dmarkers.push(marker);
        return marker;
      }

      // create ship markers based on observations
      function createShipMarker(point,name,vessel,dateTime,html,count)  {
        // create icon symbol
        var icon = new GIcon();
        if (count == 0)  {
          icon.image = "images/star.png";
          icon.iconSize = new GSize(16, 16);
          icon.iconAnchor = new GPoint(10, 10);
          icon.infoWindowAnchor = new GPoint(5, 1);
        }
        else {
          icon.image = "images/ship.png";
          icon.iconSize = new GSize(15, 15);
          icon.iconAnchor = new GPoint(10, 10);
          icon.infoWindowAnchor = new GPoint(10, 10);
        }
        var marker = new GMarker(point,{icon:icon,title:name});
        marker.shipID = vessel;
        marker.dateTime = dateTime;
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindow(html);
        });
        smarkers.push(marker);
        return marker;
      }
 
      // create ship track 
      function createShipTrack(vessel,points)  {
        // create line color symbol
        pcolor = "#0000ff";
        var line = new GPolyline(points,pcolor,2,0.8);
        var bounds = line.getBounds();
        line.shipID = vessel;
        line.bounds = bounds;
        tracks.push(line);
      }

      // function to find bank selected from dropdown list and zoom to its location
      function findBank()  {
        var selectedBank = document.getElementById("bank_name");
        bankID = selectedBank.value;
        if (bankID > -1)  {
          GEvent.trigger(bmarkers[bankID],"click");
          mapFGB.setCenter(bmarkers[bankID].getLatLng(), 12);
          mapFGB.addOverlay(bmarkers[bankID]);
        }
        else  {
          mapFGB.closeInfoWindow();
        }
      }

      // handles turning off and on bank markers
      function addBanksToMap()  {
        var selectedBanks = document.getElementById("banks");
        chkSelectedBanks = selectedBanks.checked;
        if (chkSelectedBanks)  {
          for (var j=0; j<bmarkers.length; j++)  {
            mapFGB.addOverlay(bmarkers[j]);
          }
        }
        else {
          for (var j=0; j<bmarkers.length; j++)  {
            mapFGB.removeOverlay(bmarkers[j]);
          }
        }
      }

      // handles adding specific dive track and photos to map
      function addDiveTrack(dive_id)  {
        // remove any old tracks and photos
        for (var j=0; j<dtracks.length; j++)  {
          dtracks[j].hide();
        }
        for (var j=0; j<dmarkers.length; j++)  {
          mapFGB.removeOverlay(dmarkers[j]);
        }
        // add only selected dive track and photos to map
        var arrayOfDiveInfo = dive_id.split(":");
        for (var j=0; j<dtracks.length; j++)  {
          if ((dtracks[j].bank == arrayOfDiveInfo[0]) && (dtracks[j].cruise == arrayOfDiveInfo[1]) && (dtracks[j].dive == arrayOfDiveInfo[2]))  {           
            var neCoords = dtracks[j].ne.split(",");
            var topLat = parseFloat(neCoords[0]);
            var topLng = parseFloat(neCoords[1]);
            var swCoords = dtracks[j].sw.split(",");
            var botLat = parseFloat(swCoords[0]);
            var botLng = parseFloat(swCoords[1]);
            var centerCoords = dtracks[j].mapCenter.split(",");
            var centerLat = parseFloat(centerCoords[0]);
            var centerLng = parseFloat(centerCoords[1]); 
            var neCorner = new GLatLng(topLat,topLng);
            var swCorner = new GLatLng(botLat,botLng); 
            var bounds = new GLatLngBounds (swCorner, neCorner);
            var mapZoomLevel = mapFGB.getBoundsZoomLevel(bounds);
            var mCenter = new GLatLng(centerLat,centerLng);
            mapFGB.setCenter(mCenter, mapZoomLevel);
            //mapFGB.addOverlay(dtracks[j]);  // this covers if the particular dive track has not been drawn yet
            //dtracks[j].show();  // this covers if the particular dive track has been drawn
          }
        }

        if (arrayOfDiveInfo[0] == "Alderdice Bank")  current_bank_id = 0;
        if (arrayOfDiveInfo[0] == "Bouma Bank")  current_bank_id = 1;
        if (arrayOfDiveInfo[0] == "Bright Bank")  current_bank_id = 2;
        if (arrayOfDiveInfo[0] == "East Flower Garden Bank")  current_bank_id = 3;
        if (arrayOfDiveInfo[0] == "Geyer Bank")  current_bank_id = 4;
        if (arrayOfDiveInfo[0] == "Jakkula Bank")  current_bank_id = 5;
        if (arrayOfDiveInfo[0] == "MacNeil Bank")  current_bank_id = 6;
        if (arrayOfDiveInfo[0] == "McGrail Bank")  current_bank_id = 7;
        if (arrayOfDiveInfo[0] == "Rankin Bank")  current_bank_id = 8;
        if (arrayOfDiveInfo[0] == "Rezak-Sidner Banks")  current_bank_id = 9;
        if (arrayOfDiveInfo[0] == "Sonnier Banks")  current_bank_id = 10;
        if (arrayOfDiveInfo[0] == "Stetson Bank")  current_bank_id = 11;
        if (arrayOfDiveInfo[0] == "West Flower Garden Bank")  current_bank_id = 12;

        var sidebar_html = "";
        sidebar_html += '<br /><div class="smallText2"><center>To view a photo, click on one of the yellow dots on the map or click on a photograph name from the list below.</center></div><br />';
        var count = 1;
        for (var j=0; j<dmarkers.length; j++)  {
          if ((dmarkers[j].bank == arrayOfDiveInfo[0]) && (dmarkers[j].cruise == arrayOfDiveInfo[1]) && (dmarkers[j].dive== arrayOfDiveInfo[2]))  {
            sidebar_html += '<div class="button2"><a href="javascript:clickPhotos(' + j +')"><font color="navy">'+count+') '+dmarkers[j].title+'</font></a></div>';
            mapFGB.addOverlay(dmarkers[j]);
            count++;
          }
        }
        sidebar_html += '<br /><div class="smallText2"><center>Want to see more photos taken at this bank from a different dive survey?  Click <a href="javascript:getBank('+current_bank_id+')"><b><font color="red">here</font></b></a>.</center></div>';
        document.getElementById("sidebar").innerHTML = sidebar_html;
        mapFGB.closeInfoWindow();      
      }

      // handles removing dive photos for a bank from map
      function removeDiveByBank(bank_id)  {
        for (var j=0; j<dmarkers.length; j++)  {
          if (dmarkers[j].bank.indexOf(bank_id) != -1)  {
            mapFGB.removeOverlay(dmarkers[j]);
          }
        }
        mapFGB.closeInfoWindow();
        initialize_sidebar();
      }

      // handles removing dive photos based on dive track from map
      function removeDivePhotos()  {
        for (var j=0;j<dmarkers.length;j++)  {
          mapFGB.removeOverlay(dmarkers[j]);
        }
        mapFGB.closeInfoWindow();
        initialize_sidebar();
      }

      // handles adding dive photos based on dive track instead of by bank 
      function getDivePhotos(diveInfo)  {
        for (var j=0; j<dmarkers.length; j++)  {
          mapFGB.removeOverlay(dmarkers[j]);
        }
        var arrayOfDiveInfo = diveInfo.split(":");
        var sidebar_html = "";
        sidebar_html += '<br /><div class="smallText2"><center>To view a photo, click on one of the yellow dots on the map or click on a photograph name from the list below.</center></div><br />';
        var count = 1;
        for (var j=0; j<dmarkers.length; j++)  {
          if ((dmarkers[j].bank == arrayOfDiveInfo[0]) && (dmarkers[j].cruise == arrayOfDiveInfo[1]) && (dmarkers[j].dive== arrayOfDiveInfo[2]))  {
            sidebar_html += '<div class="button2"><a href="javascript:clickPhotos(' + j +')"><font color="navy">'+count+') '+dmarkers[j].title+'</font></a></div>';
            mapFGB.addOverlay(dmarkers[j]);
            count++;
          }
        }
        sidebar_html += '<br /><div class="smallText2"><center>Click <a href="javascript:removeDivePhotos()"><b><font color="red">here</font></b></a> to remove photo locations.</center></div>';
        document.getElementById("sidebar").innerHTML = sidebar_html;
        mapFGB.closeInfoWindow();      
      }

      // handles bringing up infowindow for a bank if selected from photo sidebar
      function getBank(bank_id)  {
        if (bankID > -1)  {
          GEvent.trigger(bmarkers[bankID],"click");
          mapFGB.setCenter(bmarkers[bankID].getLatLng(), 12);
          mapFGB.addOverlay(bmarkers[bankID]);
        }
        else  {
          mapFGB.closeInfoWindow();
        }
      }

      // handles turning on and off bathyemtry
      function addBathyToMap()  {
        var selectedBathy = document.getElementById("regional_bathy");
        chkselectedBathy = selectedBathy.checked;
        if (chkselectedBathy)  {
          if (!addedHabitatLegend)  {
            bathyLegendControl.setVisible(true);
            bathyLegendControl1.setVisible(false);
          }
          else {
            bathyLegendControl1.setVisible(true);
            bathyLegendControl.setVisible(false);
          }
          addedBathyLegend = true;
          if (!addedBathy)  {
            var bathyParams = new esri.arcgis.gmaps.ImageParameters();
            bathyParams.layerIds = [4];
            bathyServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", bathyParams, 1.0, null);
            GEvent.addListener(bathyServer, "load", function(bathyOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(bathyOverlay);
            });
            GEvent.addListener(bathyServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
            addedBathy = true;
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            bathyServer.show();
            GEvent.addListener(bathyServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          bathyLegendControl.setVisible(false);
          bathyLegendControl1.setVisible(false);
          addedBathyLegend = false;
          bathyServer.hide();
        }
      }

	// handles turning on and off images for banks via checkboxes
      function overlayImagesCheckbox()  {
        for (var k=0; k<banksBathyOverlay.length; k++)  {
          mapFGB.removeOverlay(banksBathyOverlay[k]);
        }
        for (var k=0; k<banksReliefOverlay.length; k++)  {
          mapFGB.removeOverlay(banksReliefOverlay[k]);
        }
        for (var k=0; k<banksBathyReliefOverlay.length; k++)  {
          mapFGB.removeOverlay(banksBathyReliefOverlay[k]);
        }
        var banksBathySelected = document.getElementById("bathymetry");
        chkselectedBanksBathy = banksBathySelected.checked;
        var banksShadedReliefSelected = document.getElementById("shd");
        chkselectedBanksShadedRelief = banksShadedReliefSelected.checked;
        if ((chkselectedBanksBathy) && (chkselectedBanksShadedRelief))  {
          for (var k=0; k<banksBathyReliefOverlay.length; k++)  {
            mapFGB.addOverlay(banksBathyReliefOverlay[k]);
          }
        }
        if ((chkselectedBanksBathy) && (!chkselectedBanksShadedRelief))  {
          for (var k=0; k<banksBathyOverlay.length; k++)  {
            mapFGB.addOverlay(banksBathyOverlay[k]);
          }
        }
        if ((!chkselectedBanksBathy) && (chkselectedBanksShadedRelief))  {
          for (var k=0; k<banksReliefOverlay.length; k++)  {
            mapFGB.addOverlay(banksReliefOverlay[k]);
          }
        }
      }

      // handles turning off and on NMS boundaries
      function addNMSToMap()  {
        var selectedNMSLines = document.getElementById("NMS");
        chkselectedNMSLines = selectedNMSLines.checked;
        if (chkselectedNMSLines)  {
          document.getElementById("loadStatus").style.display = "block";
          nmsServer.show();
          GEvent.addListener(nmsServer, "update", function()  {
            document.getElementById("loadStatus").style.display = "none";
          });
        }
        else  {
          nmsServer.hide();
        }
      }

      // handles adding and removing NEXRAD image to map
      function addNEXRADToMap()  {
        var nexradChecked = document.getElementById("nexrad_mosaic");
        if (nexradChecked.checked)  {
          // load the radar mosaic
          var north = 50.406626367301044;
          var south = 21.652538062803;
          var east = -66.517937876818;
          var west = -127.62037552387542;
          var pointSW = new GLatLng(south,west);
          var pointNE = new GLatLng(north,east);
          radarOverlay = new GGroundOverlay("http://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif", new GLatLngBounds(pointSW,pointNE));
          mapFGB.addOverlay(radarOverlay);
        }
        else  {
          mapFGB.removeOverlay(radarOverlay);
        }
      }

      // handles turning on and off dive tracks
      function addDiveTracksToMap()  {
        var selectedDiveTracks = document.getElementById("dive_tracks");
        chkselectedDiveTracks = selectedDiveTracks.checked;
        if (chkselectedDiveTracks)  {
          if (!addedDives)  {
            var divesParams = new esri.arcgis.gmaps.ImageParameters();
            divesParams.layerIds = [3];
            diveServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", divesParams, 1.0, null);
            GEvent.addListener(diveServer, "load", function(diveOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(diveOverlay);
            });
            GEvent.addListener(diveServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
            addedDives = true;
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            diveServer.show();
            GEvent.addListener(diveServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          var sidebar_html = "";
          sidebar_html += '<br /><div class="smallText2"><center>Remotely Operated Vehicles (ROVs) are unmanned underwater robots that are connected to a vessel by a tether. This tether, also known as an umbilical, is composed of cables that provide a power source, controls, and video feeds to the ROV. ROVs enable researchers to explore areas where it is dangerous or difficult for people to explore, like deepwater habitats. ROVs have a video camera mounted on their frame to allow the operator and scientists to see what the ROV is seeing at that location. In addition, each ROV can be outfitted with different capabilities depending on the tasks being complete. For example, the ROV used for many of dives conducted at the Flower Garden Banks National Marine Sanctuary are outfitted with a high resolution digital still camera and a manipulator arm that enables the ROV to &apos;grab&apos; samples.<p />Click <a href="javascript:getROVPhoto()"><font color="red"><b>here</b></font> </a> to see a picture of the ROV.</center></div>';
          document.getElementById("sidebar").innerHTML = sidebar_html;
        }
        else {
          diveServer.hide();
          removeDivePhotos();
        }
      }

      // handles turning on and off activity zones
      function addActivityZonesToMap()  {
        var selectedZones = document.getElementById("activity_zones");
        chkselectedZones = selectedZones.checked;
        if (chkselectedZones)  {
          if (!addedFDALegend)  {
            activityLegendControl.setVisible(true);
            activityLegendControl1.setVisible(false);
          }
          else {
            activityLegendControl1.setVisible(true);
            activityLegendControl.setVisible(false);
          }
          addedActivityLegend = true;          
          if (!addedZones)  {
            var zonesParams = new esri.arcgis.gmaps.ImageParameters();
            zonesParams.layerIds = [8];
            zonesServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", zonesParams, 0.75, null);
            GEvent.addListener(zonesServer, "load", function(zonesOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(zonesOverlay);
            });
            addedZones = true;
            GEvent.addListener(zonesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            zonesServer.show();
            GEvent.addListener(zonesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          activityLegendControl.setVisible(false);
          activityLegendControl1.setVisible(false);
          addedActivityLegend = false;
          zonesServer.hide();
        }
      }

      // handles turning on and off HAPC
      function addHAPCToMap()  {
        var selectedHAPC = document.getElementById("HAPC");
        chkselectedHAPC = selectedHAPC.checked;
        if (chkselectedHAPC)  {
          hapcLegendControl.setVisible(true);
          if (!addedHAPC)  {
            var hapcParams = new esri.arcgis.gmaps.ImageParameters();
            hapcParams.layerIds = [15];
            hapcServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", hapcParams, 0.5, null);
            GEvent.addListener(hapcServer, "load", function(hapcOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(hapcOverlay);
            });
            addedHAPC = true;
            GEvent.addListener(hapcServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            hapcServer.show();
            GEvent.addListener(hapcServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          hapcLegendControl.setVisible(false);
          hapcServer.hide();
        }
      }

      // handles turning on and off habitat characterization
      function addHabitatCharacterizationToMap()  {
        var selectedHabitat = document.getElementById("habitat");
        chkselectedHabitat = selectedHabitat.checked;
        if (chkselectedHabitat)  {
          if (addedBathyLegend)  {
            bathyLegendControl.setVisible(false);
            bathyLegendControl1.setVisible(true);
          }
          habitatLegendControl.setVisible(true);
          addedHabitatLegend = true;
          if (!addedHabitat)  {
            var habitatParams = new esri.arcgis.gmaps.ImageParameters();
            habitatParams.layerIds = [9,10,11,12,13,14];
            habitatServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", habitatParams, 1.0, null);
            GEvent.addListener(habitatServer, "load", function(habitatOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(habitatOverlay);
            });
            addedHabitat = true;
            GEvent.addListener(habitatServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            habitatServer.show();
            GEvent.addListener(habitatServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          habitatLegendControl.setVisible(false);
          addedHabitatLegend = false;
          if (addedBathyLegend)  {
            bathyLegendControl.setVisible(true);
            bathyLegendControl1.setVisible(false);
          }
          habitatServer.hide();
        }
      }

      // handles turning on and off mooring buoys
      function addMooringsToMap()  {
        var selectedMoorings = document.getElementById("moorings");
        chkselectedMoorings = selectedMoorings.checked;
        if (chkselectedMoorings)  {
          if (!addedMoorings)  {
            var mooringsParams = new esri.arcgis.gmaps.ImageParameters();
            mooringsParams.layerIds = [0];
            mooringsServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", mooringsParams, 1.0, null);
            GEvent.addListener(mooringsServer, "load", function(mooringsOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(mooringsOverlay);
            });
            addedMoorings = true;
            GEvent.addListener(mooringsServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            mooringsServer.show();
            GEvent.addListener(mooringsServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          mooringsServer.hide();
        }
      }

      // handles turning on and off NDBC buoys
      function addBuoysToMap()  {
        var selectedBuoys = document.getElementById("buoys");
        chkselectedBuoys = selectedBuoys.checked;
        if (chkselectedBuoys)  {
          if (!addedNDBC)  {
            var buoysParams = new esri.arcgis.gmaps.ImageParameters();
            buoysParams.layerIds = [2];
            ndbcServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", buoysParams, 0.75, null);
            GEvent.addListener(ndbcServer, "load", function(ndbcOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(ndbcOverlay);
            });
            addedNDBC = true;
            GEvent.addListener(ndbcServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            ndbcServer.show();
            GEvent.addListener(ndbcServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          ndbcServer.hide();
          clearResults();
        }
      }

      // handles turning on and off FDA advisories
      function addFDAToMap()  {
        var selectedFDA = document.getElementById("fda");
        chkselectedFDA = selectedFDA.checked;
        if (chkselectedFDA)  {
          if (addedActivityLegend)  {
            activityLegendControl.setVisible(false);
            activityLegendControl1.setVisible(true);
          }
          fdaLegendControl.setVisible(true);
          addedFDALegend = true;
          if (!addedFDA)  {
            var fdaParams = new esri.arcgis.gmaps.ImageParameters();
            fdaParams.layerIds = [17, 18];
            fdaServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", fdaParams, 1.0, null);
            GEvent.addListener(fdaServer, "load", function(fdaOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(fdaOverlay);
            });
            addedFDA = true;
            GEvent.addListener(fdaServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            fdaServer.show();
            GEvent.addListener(fdaServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          fdaLegendControl.setVisible(false);
          addedFDALegend = false;
          if (addedActivityLegend)  {
            activityLegendControl.setVisible(true);
            activityLegendControl1.setVisible(false);
          }
          fdaServer.hide();
        }
      }

      // handles turning on and off lease blocks
      function addLeaseBlocksToMap()  {
        var selectedLeases = document.getElementById("lease_blocks");
        chkselectedLeases = selectedLeases.checked;
        if (chkselectedLeases)  {
          if (!addedLeases)  {
            var leasesParams = new esri.arcgis.gmaps.ImageParameters();
            leasesParams.layerIds = [16];
            leasesServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", leasesParams, 1.0, null);
            GEvent.addListener(leasesServer, "load", function(leasesOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(leasesOverlay);
            });
            addedLeases = true;
            GEvent.addListener(leasesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            leasesServer.show();
            GEvent.addListener(leasesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          leasesServer.hide();
        }
      }

      // handles turning on and off oil and gas platforms
      function addPlatformsToMap()  {
        var selectedPlatforms = document.getElementById("platforms");
        chkselectedPlatforms = selectedPlatforms.checked;
        if (chkselectedPlatforms)  {
          if (!addedPlatforms)  {
            var platformsParams = new esri.arcgis.gmaps.ImageParameters();
            platformsParams.layerIds = [1];
            platformsServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", platformsParams, 1.0, null);
            GEvent.addListener(platformsServer, "load", function(platformsOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(platformsOverlay);
            });
            addedPlatforms = true;
            GEvent.addListener(platformsServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            platformsServer.show();
            GEvent.addListener(platformsServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          platformsServer.hide();
        }
      }

      // handles turning on and off pipelines
      function addPipelinesToMap()  {
        var selectedPipelines = document.getElementById("pipelines");
        chkselectedPipelines = selectedPipelines.checked;
        if (chkselectedPipelines)  {
          if (!addedPipelines)  {
            var pipelinesParams = new esri.arcgis.gmaps.ImageParameters();
            pipelinesParams.layerIds = [5];
            pipelinesServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", pipelinesParams, 1.0, null);
            GEvent.addListener(pipelinesServer, "load", function(pipelinesOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(pipelinesOverlay);
            });
            addedPipelines = true;
            GEvent.addListener(pipelinesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            pipelinesServer.show();
            GEvent.addListener(pipelinesServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          pipelinesServer.hide();
        }
      }

      // handles turning on and off shipping fairways
      function addShippingFairwaysToMap()  {
        var selectedFairways = document.getElementById("fairways");
        chkselectedFairways = selectedFairways.checked;
        if (chkselectedFairways)  {
          if (!addedFairways)  {
            var fairwaysParams = new esri.arcgis.gmaps.ImageParameters();
            fairwaysParams.layerIds = [6];
            fairwaysServer = new esri.arcgis.gmaps.DynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/NMSP/FGB/MapServer", fairwaysParams, 1.0, null);
            GEvent.addListener(fairwaysServer, "load", function(fairwaysOverlay)  {
              document.getElementById("loadStatus").style.display = "block";
              mapFGB.addOverlay(fairwaysOverlay);
            });
            addedFairways = true;
            GEvent.addListener(fairwaysServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
          else {
            document.getElementById("loadStatus").style.display = "block";
            fairwaysServer.show();
            GEvent.addListener(fairwaysServer, "update", function()  {
              document.getElementById("loadStatus").style.display = "none";
            });
          }
        }
        else {
          fairwaysServer.hide();
        }
      }

      // handles adding ship observations from Manta
      function addShipObsToMap()  {
        var selectedShipObs = document.getElementById("ship_obs");
        chkselectedShipObs = selectedShipObs.checked;
        if (chkselectedShipObs)  {
          var sidebar_html = "";
          ship_ID = "436900778";
          for (var j=0;j<smarkers.length;j++)  {
            mapFGB.removeOverlay(smarkers[j]);
          }
          for (var j=0;j<tracks.length;j++)  {
            mapFGB.removeOverlay(tracks[j]);
          }
          for (var j=0; j<tracks.length; j++)  {
            if (tracks[j].shipID == ship_ID)  {
              mapFGB.addOverlay(tracks[j]);
            }
          }
          count = 0;
          for (var j=0;j<smarkers.length;j++)  {
            if (smarkers[j].shipID == ship_ID)  {
              count++;
            }
          }
          //sidebar_html = '<div class="headerFrame">Total Number of Observations: '+count+'</div>';
          for (var j=0;j<smarkers.length;j++)  {
            if (smarkers[j].shipID == ship_ID)  {
              mapFGB.addOverlay(smarkers[j]);
          //    sidebar_html += '<div class="button2"><a href="javascript:clickObs(' + j +')">'+smarkers[j].dateTime+'</a></div>';
            }
          }
          //document.getElementById("sidebar_left").innerHTML = sidebar_html;
        }
        else  {
          mapFGB.getInfoWindow().hide();
          //document.getElementById("sidebar_left").innerHTML = '';
          for (var j=0;j<smarkers.length;j++)  {
            mapFGB.removeOverlay(smarkers[j]);
          }
          for (var j=0;j<tracks.length;j++)  {
            mapFGB.removeOverlay(tracks[j]);
          }
        }
      }

      // handles clicks from sidebar of ship observations
      function clickObs(k) {
        GEvent.trigger(smarkers[k],"click");
      }

      // handles clicks from sidebar of dive photos
      function clickPhotos(k) {
        GEvent.trigger(dmarkers[k],"click");
      }
 
      // function to open up additional general documents
      function displayReport(reportID)  {
        reportURL = "http://www.ncddc.noaa.gov/website";
        if (reportID == 2)  {
          reportURL += "/google_maps/FGB/reports/CoralCommunityZone.pdf";
        }
        if (reportID == 0)  {
          reportURL += "/google_maps/FGB/reports/CoralReefZone.pdf";
        }
        if (reportID == 1)  {
          reportURL += "/google_maps/FGB/reports/CorallineAlgaeZone.pdf";
        }
        if (reportID == 3)  {
          reportURL += "/google_maps/FGB/reports/DeepCoralZone.pdf";
        }
        if (reportID == 4)  {
          reportURL += "/google_maps/FGB/reports/SoftBottomZone.pdf";
        }
        if (reportID == 5)  {
          reportURL += "/google_maps/FGB/reports/CiguateraDescription.pdf";
        }
        if (reportID == 6)  {
          reportURL += "/google_maps/FGB/reports/HAPC2.pdf";
        }
        if (reportID == 7)  {
          reportURL += "/google_maps/FGB/credits.htm";
        }
        var Win2 = open(reportURL,"ReportWindow","height=700,width=500,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        Win2.focus();
      }

      // function to open up additional posters for species
      function getPoster(posterID)  {
        posterURL = "http://www.ncddc.noaa.gov/website";
        if (posterID == 0)  {
          posterURL += "/google_maps/FGB/posters/Octocorals.pdf";
        }
        if (posterID == 1)  {
          posterURL += "/google_maps/FGB/posters/Sponges.pdf";
        }
        if (posterID == 2)  {
          posterURL += "/google_maps/FGB/posters/Invertebrates.pdf";
        }
        if (posterID == 3)  {
          posterURL += "/google_maps/FGB/posters/Deepfishes.pdf";
        }
        if (posterID == 4)  {
          posterURL += "/google_maps/FGB/posters/Invertebrates.pdf";
        }
        if (posterID == 5)  {
          posterURL += "/google_maps/FGB/posters/Antipatharians.pdf";
        }
        var Win3 = open(posterURL,"PosterWindow","height=700,width=500,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        Win3.focus();
      }
    
      // sets up status bar
      function updateStatusBar() {
	 var bounds = mapFGB.getBounds();
	 var SW = bounds.getSouthWest();
	 var NE = bounds.getNorthEast();
	 var oCoords = document.getElementById("coords");
	 oCoords.innerHTML = '<b>SW:</b> ' + SW.y.toFixed(6) + ', ' + SW.x.toFixed(6);
	 oCoords.innerHTML += '<br> ';
	 oCoords.innerHTML += '<b>NE:</b> ' + NE.y.toFixed(6) + ', ' + NE.x.toFixed(6);
      }

      // populates status bar with values
      function mouseMove(mousePt) {
	 mouseLatLng = mousePt;
	 var zoom = mapFGB.getZoom();
	 var oStatusDiv = document.getElementById("mouseTrack")	
	 var mousePx = normalProj.fromLatLngToPixel(mousePt, zoom);
	 oStatusDiv.innerHTML = '<b>Mouse LatLng:</b> ' + mousePt.y.toFixed(6) + ', ' + mousePt.x.toFixed(6) ;
	 oStatusDiv.innerHTML += '<br> ';
	 oStatusDiv.innerHTML += '<b>Zoom Level:</b> ' + zoom;
	 oStatusDiv.innerHTML += '<br>';
      }

      // handle movements and send updates to status bar
      function moveEnd() {
        GEvent.addListener(mapFGB, "moveend", function()  {
          document.getElementById("loadStatus").style.display = "block";
        });
        updateStatusBar();
      }

      // updates status bar
      function zoomEnd(oldZ,zoom) {
        var center = mapFGB.getCenter();
        updateStatusBar();
        var zoomLevel = mapFGB.getZoom();
      }

      // function to handle any identifies of buoys or dive tracks
      function identify(overlay, latLng) {
        var selectedPlatforms = document.getElementById("platforms");
        chkselectedPlatforms = selectedPlatforms.checked;
        var selectedBuoys = document.getElementById("buoys");
        chkselectedBuoys = selectedBuoys.checked;
        var selectedDives = document.getElementById("dive_tracks");
        chkselectedDives = selectedDives.checked;
        if ((chkselectedPlatforms) || (chkselectedBuoys) || (chkselectedDives))  {
        //if ((chkselectedBuoys) || (chkselectedDives))  {
          if (overlay) return;
          clearResults();

        // set the identify parameters
          var identifyParameters = new esri.arcgis.gmaps.IdentifyParameters();
          identifyParameters.geometry = latLng; // location where the user clicked on the map
          identifyParameters.tolerance = 3;
          identifyParameters.layerIds = [ 1, 2, 3 ];
          //identifyParameters.layerIds = [ 2, 3 ];
          identifyParameters.layerOption = "all";
          identifyParameters.bounds = mapFGB.getBounds();
          var mapSize = mapFGB.getSize();
          identifyParameters.width = mapSize.width;
          identifyParameters.height = mapSize.height;

        // execute the identify operation
          identifyTask.execute(identifyParameters, function(response, error) { // function to be called when the result is available
          // display error message (if any) and return
            if (hasErrorOccurred(error)) return;

          // note that the location where the user clicked on the map (latLng) is visible in this function through closure
            addResultToMap(response, latLng);
          });
        }
      }

      // function to handle the click responses of identifies of buoys or dive tracks
      function addResultToMap(response, point) {
        // check to determine if the layer is drawn on the map or not ... if not, don't create a tab entry
        var selectedPlatforms = document.getElementById("platforms");
        chkselectedPlatforms = selectedPlatforms.checked;
        var selectedBuoys = document.getElementById("buoys");
        chkselectedBuoys = selectedBuoys.checked;
        var selectedDives = document.getElementById("dive_tracks");
        chkselectedDives = selectedDives.checked;

        // aggregate the result per map service layer
        var idResults = response.identifyResults;
        //layers = { "2": [], "3": [] };
        layers = { "1": [], "2": [], "3": [] };
        for (var i = 0; i < idResults.length; i++) {
          var result = idResults[i];
          layers[result.layerId].push(result);
        }

        // create and show the info-window with tabs, one for each map service layer
        var tabs = [];
        var total = 0;
        for (var layerId in layers) {
            var results = layers[layerId];
            var count = results.length;
            var label= "";
            var content = "";
            switch(layerId) {
              case "1":
                if (count == 0) break;
                if (!chkselectedPlatforms) break;
                label = "Platforms";
                content = "<table class='identify' colspan='2' border='1'>";
                for (var j=0;j<count;j++)  {
                  total++;
                  var attributes = results[j].feature.attributes;
                  var complex_id = attributes["COMPLEX_ID_NUM"];
                  var name = attributes["STR_NAME"];
                  var install_date = attributes["INSTALL"];
                  var removal_date = attributes["REMOVAL"];
                  content += '<tr><td><b>Complex ID</b></td><td>'+complex_id+'</td></tr>';
                  content += '<tr><td><b>Name</b></td><td><'+name+'</td></tr>';
                  content += '<tr><td><b>Install Date</b></td><td>'+install_date+'</td></tr>';
                  content += '<tr><td><b>Removal Date</b></td><td>'+removal_date+'</td></tr>';
                }
                content += "</table>";
                break;
              case "2":
                if (count == 0) break;
                if (!chkselectedBuoys) break;
                label = "NDBC Buoys";
                content = "<table class='identify' colspan='2' border='1'>";
                for (var j=0;j<count;j++)  {
                  total++;
                  var attributes = results[j].feature.attributes;
                  var station_id = attributes["STATION_ID"];
                  if (station_id == "42047")  url_tab = "http://tabs.gerg.tamu.edu/tglo/ven.php?buoy=V";
                  if (station_id == "42046")  url_tab = "http://tabs.gerg.tamu.edu/tglo/ven.php?buoy=N";
                  var owner = attributes["OWNER"];
                  var ttype = attributes["TTYPE"];
                  var name = attributes["NAME"];
                  var lat = attributes["LAT"];
                  var lon = attributes["LON"];
                  var longitude = lon * -1;
                  var position = lat + " N, ";
                  position += longitude + " W";
                  var url = attributes["URL"];
                  if (name.length != 0)  {
                    content += '<tr><td><b>Station ID</b></td><td>'+station_id+' - '+name+'</td></tr>';
                  }
                  else  {
                    content += '<tr><td><b>Station ID</b></td><td>'+station_id+'</td></tr>';
                  }
                  content += '<tr><td><b>Position</b></td><td>'+position+'</td></tr>';
                  content += '<tr><td><b>Owner</b></td><td>'+owner+'</td></tr>';
                  content += '<tr><td><b>Type</b></td><td>'+ttype+'</td></tr>';
                  content += '<tr><td><b>NDBC Buoy Page</b></td><td><a href="javascript:getBuoyPage(\''+url+'\')">Click to access buoy data</a></td></tr>';
                  if ((station_id == "42046") || (station_id == "42047"))  content += '<tr><td><b>TABS Buoy Page</b></td><td><a href="javascript:getBuoyPage(\''+url_tab+'\')">Click to access buoy data</a></td></tr>';
                }
                content += "</table>";
                break;
              case "3":
                if (count == 0) break;
                if (!chkselectedDives) break;
                label = "ROV Dives";
                content = "<table class='identify' colspan='4' border='1'>";
                content += '<tr><td><b>Cruise</b></td><td><b>Dive</b></td><td><b>Bank</b></td><td><b>Dive Photos</b></td></tr>';
                for (var j=0;j<count;j++)  {
                  total++;
                  var attributes = results[j].feature.attributes;
                  var cruise_id = attributes["CRUISE"];
                  var dive_id = attributes["DIVE"];
                  var bank_id = attributes["BANK"];
                  var diveInfo = "";
                  diveInfo = bank_id + ":";
                  diveInfo += cruise_id + ":";
                  diveInfo += dive_id;
                  content += '<tr><td>'+cruise_id+'</td>';
                  content += '<td>'+dive_id+'</td>';
                  content += '<td>'+bank_id+'</td>';
                  content += '<td><a href="javascript:getDivePhotos(\''+diveInfo+'\')">Click to access dive photos</a></td></tr>';
                }
                content += "</table>";
                break;
            }
            if (content.length != 0)  {
              tabs.push(new GInfoWindowTab(label, content));
            }
          }
          if (total != 0)  {
            if (total <= 10)  {
              mapFGB.openInfoWindowTabsHtml(point, tabs);
            }
            else {
              alert("Too many results ... zoom to a smaller area and try again");
            }
          }
      }

      function clearResults() {
        mapFGB.closeInfoWindow();
      }

      function hasErrorOccurred(error) {
        if (error) {
          alert("Error " + error.code + ": " + (error.message || (error.details && error.details.join(" ")) || "Unknown error" ));
          return true;
        }
        return false;
      }

      function getBuoyPage(buoy)  {
        var Win1 = open(buoy,"BuoyWindow","height=800,width=800,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        Win1.focus();
      }

      function getROVPhoto()  {
        rovPhotoHTML = "http://www.ncddc.noaa.gov/website/google_maps/FGB/rovPhoto.htm";
        var Win2 = open(rovPhotoHTML,"ROVWindow","height=350,width=450,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
        Win2.focus();
      }
