
    if (GBrowserIsCompatible()) {
      // this variable will collect the html which will eventualkly be placed in the sidebar
      var sidebar_html = "";
    
      // arrays to hold copies of the markers and html used by the sidebar
      // because the function closure trick doesnt work there
      var gmarkers = [];
      var htmls = [];
      var i = 0;	  
	 	  	
	var centroidIcon = new GIcon();
	centroidIcon.image = "images/centroid_4px.png";
	centroidIcon.shadow = "images/centroid_4px.png";
	centroidIcon.iconSize = new GSize(4, 4);
	centroidIcon.shadowSize = new GSize(4, 4);
	centroidIcon.iconAnchor = new GPoint(2, 2);
	centroidIcon.infoWindowAnchor = new GPoint(0, 4);
	centroidIcon.imageMap = [6,0,0,6,0,0]; 
	centroidIcon.transparent = "images/centroid_8px_trans.png";
	
	

      function plotVisibleMarkers() {
         var bounds = map.getBounds();
         var Rad2Deg = 180/Math.PI; 
   
         /*var minlat = Rad2Deg*bounds.getSouthWest().y; 
         var minlng = Rad2Deg*bounds.getSouthWest().x; 
         var maxlat = Rad2Deg*bounds.getNorthEast().y;
         var maxlng = Rad2Deg*bounds.getNorthEast().x;*/
		 
		 var minlat = bounds.getSouthWest().y; 
         var minlng = bounds.getSouthWest().x; 
         var maxlat = bounds.getNorthEast().y;
         var maxlng = bounds.getNorthEast().x;
		 var BBOX = maxlng+","+maxlat+","+minlng+","+minlat;
		 
		 var request = GXmlHttp.create();
		request.open("GET", "GE_Spokane_Parcels.aspx?BBOX=" + BBOX, true);
			
			 request.onreadystatechange = function() {				 
			   if (request.readyState == 4) {
				 var xmlDoc = request.responseXML;
				 // obtain the array of markers and loop through it
				 var markers = xmlDoc.documentElement.getElementsByTagName("marker");
				 
				//alert(oldMarkerLats);
				//alert(newMarkerLats);
				 for (var i = 0; i < markers.length; i++) 
				 {
					   // obtain the attribues of each marker
					   var lat = parseFloat(markers[i].getAttribute("lat"));
					   var lng = parseFloat(markers[i].getAttribute("lng"));
					   var point = new GLatLng(lat,lng);
					   var label = markers[i].getAttribute("label");
					   var html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
					   // create the marker
					   // check to see if the marker exists from the previous set
					  
					   checkMarkerExists(lat);
					   if (markerExists == false)
					   {
						   newMarkerLats.push(lat);
						   //alert("doesn't exist");
						   var marker = createMarker(point,label,html);
						   map.addOverlay(marker);
					   }
					   else if (markerExists == true)
					   {
						   	//alert("exists");
							//newMarkerLats.push(oldLat);
					   }
				 }
					
				 //oldMarkerLats = new Array();
				 //continue to add oldMarkerLats array - cumulative for session
				 for (var i = 0; i < newMarkerLats.length; i++) 
				 {
					 oldMarkerLats.push(newMarkerLats[i]);
				 }					 
				 newMarkerLats = new Array();
				
				 document.getElementById("feedbackPane").innerHTML = centroidsDoneMsg;
				 // put the assembled sidebar_html contents into the sidebar div if it exists
				 //document.getElementById("sidebar").innerHTML = '';
				 //document.getElementById("sidebar").innerHTML = sidebar_html;
			   }
			 }
			 request.send(null);
			 
			
       }

       function onMapMoved() 
	   { 
	    
		//Parcels layer has an upper zoom threshold.  Cannot display until below 15.
		if (map.getZoom() >= 15)
			{
			document.legend.Parcels.disabled = false;
			//layerToggle("Parcels");
			}
		else 
			{
			document.legend.Parcels.disabled = true;
			document.legend.Parcels.checked = false;
			map.removeOverlay(tileParcelsOverlay);
			}
		
		//Munis layer has a lower zoom threshold.  Cannot display below 14.
		if (map.getZoom() >= 14)
			{
			document.legend.Munis.disabled = true;
			document.legend.Munis.checked = false;
			map.removeOverlay(tileMunisOverlay);
			}
		else 
			{
			document.legend.Munis.disabled = false;
			//layerToggle("Munis");			
			}
			
		var zoomMsg = "<font size='2' face='Verdana, Arial, Helvetica, sans-serif' color='blue'>The zoom factor is: " + map.getZoom() + "</font>";
	   	document.getElementById("feedbackPane").innerHTML = zoomMsg;
		curMapBounds = map.getBounds();
		//alert(lastMapBounds.getNorthEast().lat());
		//alert(curMapBounds.getNorthEast().lat());
		
		if (infoOpened == false)
			{
			if (map.getZoom() >= 17)
				{	
				//alert(oldMarkerLats.length);
				//check to see if current area has had cntroid information retrieved before
				var retrievedBefore = "";
				for (var i = 0; i < boundsArray.length; i++) 
					{
						if (boundsArray[i].containsBounds(curMapBounds))
						{
							retrievedBefore = true;
						}
					}
				//alert(retrievedBefore);
				
				//checking for change in map bounds so points only load when map is actually moved or new window is not fully contained by last bounds, not when map types are switched
				if ((retrievedBefore != true) || (lastCentroidMapBounds == "") || ((curMapBounds.equals(lastCentroidMapBounds) == false) && (lastCentroidMapBounds.containsBounds(curMapBounds) == false)))
					{
					//pause for a few seconds to let the JavaScript breath and have time to process new map tile information first
					setTimeout("getNewMarkers();",1000);				
					}
				lastCentroidMapBounds = map.getBounds();
				boundsArray.push(lastCentroidMapBounds);
				}				
			lastMapBounds = map.getBounds();
			}
       	} 
		
		function getNewMarkers()
		{
		document.getElementById("feedbackPane").innerHTML = centroidsLoadMsg;		
		i = 0;
		gmarkers = [];
		htmls = [];
		sidebar_html = "";
		//map.clearOverlays(); 			  			
		plotVisibleMarkers();
		}
		
		function checkMarkerExists(newLat)
		{
			markerExists = false;
			//only do comparison check if in an area that overlaps the previous area
			var intersectBounds = lastMapBounds.intersects(curMapBounds);
			if (intersectBounds == true)
			{
				for (var j = 0; j < oldMarkerLats.length; j++) 
				{				
					if (oldMarkerLats[j] == newLat)
					{
						markerExists = true;
						oldLat = newLat;
						break;
					}
					
				}
			}			
			
		}

       function onInfoWindowOpen() { 
          infoOpened = false; 
		  //turn off the infowindow shadows so the layer stack does not intefere with underlying markers
		  //map.getInfoWindow().shadow.style.display="none"; 
       } 

       function onInfoWindowClose() { 
          infoOpened = false; 
		  //onMapMoved();
       } 
	   
      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        //var marker = new GMarker(point);
		var marker = new GMarker(point, centroidIcon, false);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
		/*GEvent.addListener(marker,"mouseover", function() {
          marker.openInfoWindowHtml(html);
        });*/
        // save the info we need to use later for the sidebar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the sidebar html
        //sidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }


     }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
   



