
    window.onunload=GUnload;
    var calls = new Array();
    var map = null;
    var clusterer = null;
    var POINT_CUTOFF = 10000;
    window.onload=runThese;
    
    
    function runThese() {
       for (var loop = 0; loop < calls.length; loop++) {
          eval(calls[loop]);
       }
    }


    function forceIntoArray(theItem) {
      if (!(theItem instanceof Array)) {
        var temp = theItem;
        theItem = new Array();
        theItem.push(temp);
      }
      return theItem;
    }
    
    function drawGoogleMapWithText(mapType, divName, latArray, lonArray, nameArray, codeArray, imageArray) {
 
       getNewMap(mapType, divName); 

      // latArray and lonArray might be single points - if so, create an array of the same name
      // with the point as the only element in the array
      latArray = forceIntoArray(latArray);
      lonArray = forceIntoArray(lonArray);
      
      if ((map != null) && (latArray.length < POINT_CUTOFF)) {
        
 		var bounds = new GLatLngBounds();
 		
        var point;
        var marker;
        var infoWindow = null;

        var url;
        var thisName;
        var thisCode;
        var nameParts;
        var nameUrl;
        var thisImage;
        
        for (var loop = 0; loop < latArray.length; loop++) {
          point = new GLatLng(latArray[loop], lonArray[loop]);
          bounds.extend(point);
          thisName = nameArray[loop];
          thisCode = codeArray[loop];
          thisImage = imageArray[loop];

          url = "specimen.do?name=" + thisCode;

		  if (mapType == "big") {
		    nameParts = thisName.split(" ");
		    nameUrl = "description.do?rank=species&name=" + nameParts[1] + "&genus=" + nameParts[0];

		    if (thisImage.length > 0) {
  		      infoWindow = "<img src='" + thisImage + "'><br>";
                    } else {
   		      infoWindow = "";
                    }
		    infoWindow += "Species: <a href='" + nameUrl + "' target='new'>" + thisName + "</a><br>";
		    infoWindow += "Specimen: <a href='" + url  + "' target='new'>" +  thisCode + "</a>";
		    infoWindow = "<p style='vertical-align:text-bottom'>" + infoWindow + "</p>";
		  }      
          marker = createMarker(point, url, infoWindow);
          clusterer.AddMarker(marker, "Zoom in to see these ");
        }
        
        var zoom = map.getBoundsZoomLevel(bounds);
        if (zoom > 5) { 
          zoom = 5;
        }
       
        map.setCenter(bounds.getCenter(), zoom, G_PHYSICAL_MAP);
      }
   }
    
   function drawGoogleMapWithLocalityText(mapType, divName, latArray, lonArray, nameArray, codeArray) {   
       getNewMap(mapType, divName); 

      // latArray and lonArray might be single points - if so, create an array of the same name
      // with the point as the only element in the array
      latArray = forceIntoArray(latArray);
      lonArray = forceIntoArray(lonArray);
      
      if ((map != null) && (latArray.length < POINT_CUTOFF)) {
        
 		var bounds = new GLatLngBounds();
 		
        var point;
        var marker;
        var infoWindow = null;

        var url;
        var thisName;
        var thisCode;
        var nameParts;
        var nameUrl;
        var thisImage;
        
        for (var loop = 0; loop < latArray.length; loop++) {
          point = new GLatLng(latArray[loop], lonArray[loop]);
          bounds.extend(point);
          thisName = nameArray[loop];
          thisCode = codeArray[loop];
          //thisElevation = elevationArray[loop];

          url = "locality.do?name=" + thisCode;

		  if (mapType == "big") {
		    nameParts = thisName.split(" ");
		    
		    infoWindow = "Locality: <a href='" + url + "' target='new'>" + thisName + "</a><br>";
		    infoWindow += "Code: " +  thisCode + "<br>";
		    infoWindow += "Latitude: " +  latArray[loop] + "<br>";
		    infoWindow += "Longitude: " +  lonArray[loop] + "<br>";
		    //infoWindow += "Elevation: " +  thisElevation;
		  }      
          marker = createMarker(point, url, infoWindow);
          clusterer.AddMarker(marker, "Zoom in to see these ");
        }
        
        var zoom = map.getBoundsZoomLevel(bounds);
        if (zoom > 5) { 
          zoom = 5;
        }
       
        map.setCenter(bounds.getCenter(), zoom, G_PHYSICAL_MAP);
      }
   }
   
   function drawGoogleMapWithCollectionText(mapType, divName, latArray, lonArray, codeArray) {   
       getNewMap(mapType, divName); 

      // latArray and lonArray might be single points - if so, create an array of the same name
      // with the point as the only element in the array
      latArray = forceIntoArray(latArray);
      lonArray = forceIntoArray(lonArray);
      
      if ((map != null) && (latArray.length < POINT_CUTOFF)) {
        
 		var bounds = new GLatLngBounds();
 		
        var point;
        var marker;
        var infoWindow = null;

        var url;
        var thisCode;
        var nameParts;
        var nameUrl;
        var thisImage;
        
        for (var loop = 0; loop < latArray.length; loop++) {
          point = new GLatLng(latArray[loop], lonArray[loop]);
          bounds.extend(point);
          thisCode = codeArray[loop];
          //thisElevation = elevationArray[loop];
       
          url = "collection.do?name=" + thisCode;

		  if (mapType == "big") {
		    infoWindow = "Collection: <a href='" + url + "' target='new'>" + thisCode + "</a><br>";
		    infoWindow += "Latitude: " +  latArray[loop] + "<br>";
		    infoWindow += "Longitude: " +  lonArray[loop] + "<br>";
		    //infoWindow += "Elevation: " +  thisElevation;
		  }      
          marker = createMarker(point, url, infoWindow);
          clusterer.AddMarker(marker, "Zoom in to see these ");
        }
        
        var zoom = map.getBoundsZoomLevel(bounds);
        if (zoom > 5) { 
          zoom = 5;
        }
       
        map.setCenter(bounds.getCenter(), zoom, G_PHYSICAL_MAP);
      }
   }
   
    // sets two global variables
    // yucky, but so it goes
    // 
    function getNewMap(mapType, divName) {
      
      
      if (GBrowserIsCompatible()) {
      
        map = new GMap2(document.getElementById(divName));
        clusterer = new Clusterer(map);
       
        map.setCenter(new GLatLng(0,0), 0);
        if (mapType == "big") {
          map.addControl(new GMapTypeControl());
          map.addControl(new GLargeMapControl());
          map.addControl(new GScaleControl());
	  map.addMapType(G_PHYSICAL_MAP);
        } else {
          map.addControl(new GSmallZoomControl());
        }
      }     
    } 
    
    function drawGoogleMap(mapType, divName, latArray, lonArray) {
 
      getNewMap(mapType, divName);     
      
      if (map != null) {

 		map.setCenter(new GLatLng(0,0), 0);
 		var bounds = new GLatLngBounds();
 		
        var point;        
        for (var loop = 0; loop < latArray.length; loop++) {
          point = new GLatLng(latArray[loop], lonArray[loop]);
          bounds.extend(point);
         //map.addOverlay(new GMarker(point));
         newMarker = new GMarker(point);
         newMarker.setIcon("http://localhost:8080/antweb/images/mm_20_red.png");
          	//clusterer.AddMarker(new GMarker(point), "Zoom in to see these ");
          	clusterer.AddMarker(newMarker, "Zoom in to see these ");
        }
        var zoom = map.getBoundsZoomLevel(bounds);
        if (zoom > 5) { 
          zoom = 5;
        }
       
        map.setCenter(bounds.getCenter(), zoom, G_PHYSICAL_MAP);
      }
   }
   
    function drawGoogleMapSinglePoint(mapType, divName, lat, lon, nameArray, codeArray, imageArray) {
      
      getNewMap(mapType, divName);
      
      if (map != null) {
       
 		var bounds = new GLatLngBounds();
 		var point = new GLatLng(lat, lon);
        bounds.extend(point);
		map.addOverlay(new GMarker(point));
        var zoom = map.getBoundsZoomLevel(bounds);
        if (zoom > 5) { 
          zoom = 5;
        }
        map.setCenter(bounds.getCenter(), zoom, G_PHYSICAL_MAP);
      }
   }
   

   function createMarker(point, url, infoWindow) {
   	  var icon = new GIcon();
   	  icon.image = "images/mm_20_red.png";
      icon.iconSize = new GSize(12,20);
      icon.iconAnchor = new GPoint(0, 19);
	  icon.infoWindowAnchor = new GPoint(15, 1);
      //var marker = new GMarker(point,{title:html});
      var marker = new GMarker(point,icon);
      //marker.setImage("http://localhost:8080/antweb/images/mm_20_red.png");
      
      GEvent.addListener(marker, "click", function() {
          window.open(url);
      });
      
      if (infoWindow != null) {
        GEvent.addListener(marker,"mouseover", function() {
          marker.openInfoWindowHtml(infoWindow);
        });  
      }
      
      return marker;
    }

