// Clusterer.js - marker clustering routines for Google Maps apps
//
// Using these routines is very easy.
//
// 1) Load the routines into your code:
//
//        <script src="http://www.acme.com/javascript/Clusterer.js" type="text/javascript"></script>
//
// 2) Create a Clusterer object, passing it your map object:
//
//        var clusterer = new Clusterer( map );
//
// 3) Wherever you now do map.addOverlay( marker ), instead call
//    clusterer.AddMarker( marker, title ).  The title is just a
//    short descriptive string to use in the cluster info-boxes.
//
// 4) If you are doing any map.removeOverlay( marker ) calls, change those
//    to clusterer.RemoveMarker( marker ).
//
// That's it!  Everything else happens automatically.
//
//
// The current version of this code is always available at:
// http://www.acme.com/javascript/
//
//
// Copyright � 2005,2006 by Jef Poskanzer <jef@mail.acme.com>.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// For commentary on this license please see http://www.acme.com/license.html

// Constructor.
function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}



function showProgress ()
{
 placeHolder.innerHTML='<div class="tooltip"><font face="Tahoma" size="5">'+"Please Wait..Loading"+'</font></div>';
 var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(200 , 200 )); 
 //pause(500);
 pos.apply(placeHolder);
 placeHolder.style.visibility="visible";
// window.status="Please Wait..Loading";
}


function hideProgress()
{
 placeHolder.innerHTML="";
 placeHolder.style.visibility="hidden";
}
Clusterer = function ( map )
    {
    this.map = map;
    this.markers = [];
    this.clusters = [];
    this.timeout = null;
    this.currentZoomLevel = map.getZoom();
    this.maxVisibleMarkers = Clusterer.defaultMaxVisibleMarkers;
    this.gridSize = Clusterer.defaultGridSize;
    this.minMarkersPerCluster = Clusterer.defaultMinMarkersPerCluster;
    this.maxLinesPerInfoBox = Clusterer.defaultMaxLinesPerInfoBox;
    this.icon = Clusterer.defaultIcon;
    this.amreZoom=false;
    GEvent.addListener( map, 'zoomend', Clusterer.MakeCaller( Clusterer.Display, this ) );
    GEvent.addListener( map, 'moveend', Clusterer.MakeCaller( Clusterer.Display, this ) );
    GEvent.addListener( map, 'infowindowclose', Clusterer.MakeCaller( Clusterer.PopDown, this ) );
    };


Clusterer.defaultMaxVisibleMarkers = 60;
Clusterer.defaultGridSize = 5;
Clusterer.defaultMinMarkersPerCluster = 5;
Clusterer.defaultMaxLinesPerInfoBox = 10;

Clusterer.defaultIcon = new GIcon();
Clusterer.defaultIcon.image = "station25_2.png";//'http://www.acme.com/resources/images/markers/blue_large.PNG';
Clusterer.defaultIcon.shadow = "mm_20_shadow.png";// 'http://www.acme.com/resources/images/markers/shadow_large.PNG';
Clusterer.defaultIcon.iconSize = new GSize( 30, 51 );
Clusterer.defaultIcon.shadowSize = new GSize( 56, 51 );
Clusterer.defaultIcon.iconAnchor = new GPoint( 13, 34 );
Clusterer.defaultIcon.infoWindowAnchor = new GPoint( 13, 3 );
Clusterer.defaultIcon.infoShadowAnchor = new GPoint( 27, 37 );


// Call this to change the cluster icon.
Clusterer.prototype.SetIcon = function ( icon )
    {
    this.icon = icon;
    };


// Call this to add a marker.
Clusterer.prototype.AddMarker = function ( marker, title )
    {
    if ( marker.setMap != null )
	marker.setMap( this.map );

    marker.title = title;
    marker.onMap = false;
    this.markers.push( marker );
    this.DisplayLater();
    };


// Call this to remove a marker.
Clusterer.prototype.RemoveMarker = function ( marker )
 {
  var i,j,k;
  i= this.markers.length-1;
  do
	{
  if ( this.markers[i] == marker )
	    {
	    if ( marker.onMap )
		this.map.removeOverlay( marker );
	  j= this.clusters.length-1;
    do
		{
		var cluster = this.clusters[j];
		if ( cluster != null )
		    {
        k= cluster.markers.length;
		   do
        {
        if ( cluster.markers[k] == marker )
			    {
			    cluster.markers[k] = null;
			    --cluster.markerCount;
			    break;
			    }
		    if ( cluster.markerCount == 0 )
			{
			this.ClearCluster( cluster );
			this.clusters[j] = null;
			}
		    else if ( cluster == this.poppedUpCluster )
			 Clusterer.PopDown( this );
        --k;
        }
        while(k>-1);
		    }//end of if not null
		--j;
    }
    while(j>=-1);
	    this.markers[i] = null;
	    break;
	    }
    --i;
    }
    while(i>-1);
    this.DisplayLater();
    };


Clusterer.prototype.DisplayLater = function ()
    {
    if ( this.timeout != null )
	clearTimeout( this.timeout );
    this.timeout = setTimeout( Clusterer.MakeCaller( Clusterer.Display, this ), 50 );
    };

Clusterer.Display = function ( clusterer )
{
  showProgress();
  var i, j, marker, cluster;
  clearTimeout( clusterer.timeout );

  var newZoomLevel = clusterer.map.getZoom();
  if ( newZoomLevel != clusterer.currentZoomLevel ) 
  {
  i= clusterer.clusters.length-1;
  do
	{
  if ( clusterer.clusters[i] != null )
		{
		clusterer.ClearCluster( clusterer.clusters[i] );
		clusterer.clusters[i] = null;
		} 
  --i;
  }
 while (i>-1);
 clusterer.clusters.length=0;
 clusterer.currentZoomLevel = newZoomLevel;
 }

var bounds = clusterer.map.getBounds();

// Expand the bounds a little, so things look smoother when scrolling
// by small amounts.
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var dx = ne.lng() - sw.lng();
var dy = ne.lat() - sw.lat();
dx *= 0.10;
dy *= 0.10;
bounds = new GLatLngBounds(
new GLatLng( sw.lat() - dy, sw.lng() - dx ),
new GLatLng( ne.lat() + dy, ne.lng() + dx ) );
// Partition the markers into visible and non-visible lists.
var visibleMarkers = [];
var nonvisibleMarkers = [];

i = clusterer.markers.length-1;
do
{
marker = clusterer.markers[i];
if ( marker != null )
    if ( bounds.contains( marker.getPoint() ) )
  visibleMarkers.push( marker );
    else
  nonvisibleMarkers.push( marker );
--i;
}   
while (i>-1);
// Take down the non-visible markers.
i= nonvisibleMarkers.length-1;
do
{
marker = nonvisibleMarkers[i];
if ( marker.onMap )
    {
    clusterer.map.removeOverlay( marker );
    marker.onMap = false;
    }
--i;
}
while (i>-1);
// Take down the non-visible clusters.
i = clusterer.clusters.length-1;
do
{
cluster = clusterer.clusters[i];
if ( cluster != null && ! bounds.contains( cluster.marker.getPoint() ) && cluster.onMap )
    {
    clusterer.map.removeOverlay( cluster.marker );
    cluster.onMap = false;
    }
--i;
}
while (i>-1);
// Clustering!  This is some complicated stuff.  We have three goals
// here.  One, limit the number of markers & clusters displayed, so the
// maps code doesn't slow to a crawl.  Two, when possible keep existing
// clusters instead of replacing them with new ones, so that the app pans
// better.  And three, of course, be CPU and memory efficient.
if ( visibleMarkers.length > clusterer.maxVisibleMarkers )
{
// Add to the list of clusters by splitting up the current bounds
// into a grid.
var latRange = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();
var latInc = latRange / clusterer.gridSize;
var lngInc = latInc / Math.cos( ( bounds.getNorthEast().lat() + bounds.getSouthWest().lat() ) / 2.0 * Math.PI / 180.0 );
for ( var lat = bounds.getSouthWest().lat(); lat <= bounds.getNorthEast().lat(); lat += latInc )
    for ( var lng = bounds.getSouthWest().lng(); lng <= bounds.getNorthEast().lng(); lng += lngInc )
  {
  cluster = new Object();
  cluster.clusterer = clusterer;
  cluster.bounds = new GLatLngBounds( new GLatLng( lat, lng ), new GLatLng( lat + latInc, lng + lngInc ) );
  cluster.markers = [];
  cluster.markerCount = 0;
  cluster.onMap = false;
  cluster.marker = null;
  clusterer.clusters.push( cluster );
  }
// Put all the unclustered visible markers into a cluster - the first
// one it fits in, which favors pre-existing clusters.
i=visibleMarkers.length-1;
do
 {
    marker = visibleMarkers[i];
    if ( marker != null && ! marker.inCluster )
     {
      for ( j = 0; j < clusterer.clusters.length; ++j )
       {
        cluster = clusterer.clusters[j];
          if ( cluster != null && cluster.bounds.contains( marker.getPoint() ) )
           {
            cluster.markers.push( marker );
            ++cluster.markerCount;
            marker.inCluster = true;
           }
       }
     }//end of if
 --i;
 }
 while(i>-1);
// Get rid of any clusters containing only a few markers.
for ( i = 0; i < clusterer.clusters.length; ++i )
    if ( clusterer.clusters[i] != null && clusterer.clusters[i].markerCount < clusterer.minMarkersPerCluster )
     {
       clusterer.ClearCluster( clusterer.clusters[i] );
       clusterer.clusters[i] = null;
     }
    // Shrink the clusters list.
   for ( i = clusterer.clusters.length - 1; i >= 0; --i )
    if ( clusterer.clusters[i] != null )
     break;
      else
     --clusterer.clusters.length;

// Ok, we have our clusters.  Go through the markers in each
// cluster and remove them from the map if they are currently up.
i = clusterer.clusters.length-1;
do
{
  cluster = clusterer.clusters[i];
    if ( cluster != null )
     {
      j=cluster.markers.length-1;
      do
        {
          marker = cluster.markers[j];
          if ( marker != null && marker.onMap )
           {
             clusterer.map.removeOverlay( marker );
             marker.onMap = false;
           }
        --j;
        }
        while(j>-1);
     }//End of if
--i;
}
while(i>-1);
// Now make cluster-markers for any clusters that need one.
i = clusterer.clusters.length-1;
do
 {
    cluster = clusterer.clusters[i];
    if ( cluster != null && cluster.marker == null )
     {
      // Figure out the average coordinates of the markers in this
      // cluster.
      var xTotal = 0.0, yTotal = 0.0;
      j=cluster.markers.length-1;
      do
       {
        marker = cluster.markers[j];
         if ( marker != null )
          {
            xTotal += ( + marker.getPoint().lng() );
            yTotal += ( + marker.getPoint().lat() );
          }
       --j;
       } //end of j loop
       while(j>-1);
     var location = new GLatLng( yTotal / cluster.markerCount, xTotal / cluster.markerCount );
     marker = new GMarker( location, clusterer.icon );
     cluster.marker = marker;
     //  Added by SAJ to show number of items that are in the cluster
     GEvent.addListener(marker,"mouseover", Clusterer.MakeCaller( Clusterer.showClusterTooltip, cluster));
     GEvent.addListener(marker,"mouseout", function() {
     tooltip.style.visibility="hidden"
      }); 
     GEvent.addListener(marker,"dblclick", Clusterer.MakeCaller( Clusterer.zoomCluster, cluster)); 

    }// End of if
  --i;
 } //end i for loop
 while (i>-1);
} //End of the if
// Display the visible markers not already up and not in clusters.
i = visibleMarkers.length-1;
do
{
	marker = visibleMarkers[i];
	if ( marker != null && ! marker.onMap && ! marker.inCluster )
	  {
	    clusterer.map.addOverlay( marker );
	    if ( marker.addedToMap != null )
		  marker.addedToMap();
	    if ( marker.title != null )
		  Clusterer.SetTooltip( marker, marker.title );
	    marker.onMap = true;
	  }
--i;
}
while(i>-1);
// Display the visible clusters not already up.
i = clusterer.clusters.length-1;
do
{
	cluster = clusterer.clusters[i];
	if ( cluster != null && ! cluster.onMap && bounds.contains( cluster.marker.getPoint() ) )
	    {
	    clusterer.map.addOverlay( cluster.marker );
	    cluster.onMap = true;
	    }
--i;
}
while(i>-1);
hideProgress();

};

Clusterer.zoomCluster = function (cluster) {
		// Figure out the average coordinates of the markers in this
		// cluster.
    //Turn off the tooltip
    showProgress();
    tooltip.style.visibility="hidden";
    var j;
    var minX = 181.0, minY = 91.0, maxX=-181.0, maxY=-91;
		j =  cluster.markers.length-1;
    var lon,lat;
    do
		{
		    marker = cluster.markers[j];
		    if ( marker != null )
		    	{
			     lon=marker.getPoint().lng();
           lat=marker.getPoint().lat()
           if  (lon<minX) {
            minX=lon ;        
           }
           if  (lon>maxX) {
            maxX=lon ;        
           }          
           if  (lat<minY) {
            minY=lat ;        
           }
           if  (lat>maxY) {
            maxY=lat ;        
          }
			}
     --j;
     }
     while(j>-1);
//Now zoom our map window
var pt1=new GLatLng(minY,minX); 
var pt2=new GLatLng(maxY,maxX);
var new_bounds=new GLatLngBounds(pt1,pt2);
var required_Zoom=clusterer.map.getBoundsZoomLevel(new_bounds);
var dx=Math.abs((maxX-minX)/2);
var dy=Math.abs((maxY-minY)/2);
var xc= minX+dx;
var yc=dy+minY;
//alert(yc+','+xc);
var point = new GLatLng(yc,xc);
this.amreZoom=true;
clusterer.map.setCenter(point,required_Zoom);
this.amreZoom=false;
hideProgress();
};
Clusterer.showClusterTooltip = function (cluster) {
//       var thetip='<div class="tooltip"><font face="Tahoma" size="1">'+"Stations ="+cluster.markers.length+'<br>Double Click To Zoom</br></font></div>';
      	var StationTxt=document.getElementById("site").innerHTML;
        var ZoomMeTxt =document.getElementById("ztext").innerHTML; 
        var thetip='<div class="tooltip"><font face="Tahoma" size="1">'+StationTxt+"="+cluster.markers.length+'<br>'+ZoomMeTxt+'</br></font></div>';

        tooltip.innerHTML =thetip ;
        var marker = cluster.marker;
	      var point=clusterer.map.getCurrentMapType().getProjection().fromLatLngToPixel(clusterer.map.fromDivPixelToLatLng(new GPoint(0,0),true),clusterer.map.getZoom());
	      var offset=clusterer.map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),clusterer.map.getZoom());
        var anchor=marker.getIcon().iconAnchor;
	      var width=marker.getIcon().iconSize.width;
	      var height=tooltip.clientHeight;
	      var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
        pos.apply(tooltip);
	      tooltip.style.visibility="visible";
      };
Clusterer.PopUp = function ( cluster )
    {
    if (this.amreZoom==false)
    {
    var clusterer = cluster.clusterer;
    var html = '<table width="300">';
    var n = 0;
    for ( var i = 0; i < cluster.markers.length; ++i )
	{
	var marker = cluster.markers[i];
	if ( marker != null )
	    {
	    ++n;
	    html += '<tr><td>';
	    if ( marker.getIcon().smallImage != null )
		html += '<img src="' + marker.getIcon().smallImage + '">';
	    else
		html += '<img src="' + marker.getIcon().image + '" width="' + ( marker.getIcon().iconSize.width / 2 ) + '" height="' + ( marker.getIcon().iconSize.height / 2 ) + '">';
	    html += '</td><td>' + marker.title + '</td></tr>';
	    if ( n == clusterer.maxLinesPerInfoBox - 1 && cluster.markerCount > clusterer.maxLinesPerInfoBox  )
		{
		html += '<tr><td colspan="2">...and ' + ( cluster.markerCount - n ) + ' more</td></tr>';
		break;
		}
	    }
	}
    html += '</table>';
    clusterer.map.closeInfoWindow();
    cluster.marker.openInfoWindowHtml( html );
    clusterer.poppedUpCluster = cluster;
    }
    };


Clusterer.RePop = function ( clusterer )
    {
    if ( clusterer.poppedUpCluster != null )
	    Clusterer.PopUp( clusterer.poppedUpCluster );
    };


Clusterer.PopDown = function ( clusterer )
    {
    clusterer.poppedUpCluster = null;
    };


Clusterer.prototype.ClearCluster = function ( cluster )
{
var i, marker;
i=cluster.markers.length-1;
do
{
 	if ( cluster.markers[i] != null )
	    {
	    cluster.markers[i].inCluster = false;
	    cluster.markers[i] = null;
	    }
--i;
}   
while (i>-1);
cluster.markers.length = 0;
cluster.markerCount = 0;
//if ( cluster == this.poppedUpCluster )
//this.map.closeInfoWindow();
if ( cluster.onMap )
	{
   this.map.removeOverlay( cluster.marker );
   cluster.onMap = false;
 }

};


// This returns a function closure that calls the given routine with the
// specified arg.
Clusterer.Make3Caller = function (func, arg1, arg2, arg3)
 {
 return function () { func( arg1, arg2, arg3 ); };
 };
 
Clusterer.Make2Caller = function (func, arg1, arg2)
 {
 return function () { func( arg1, arg2 ); };
 };
 
Clusterer.MakeCaller = function ( func, arg )
    {
    return function () { func( arg ); };
    };


Clusterer.SetTooltip = function ( marker, title )
    {
    var topElement = null;
    if ( marker.transparentIcon != null )
	topElement = marker.transparentIcon;
    else if ( marker.imageMap != null )
	topElement = marker.imageMap;
    else if ( marker.iconImage != null )
	topElement = marker.iconImage;
    else if ( marker.images != null && marker.images[0] != null )
	topElement = marker.images[0];
    if ( topElement != null )
	topElement.title = Clusterer.DeHtmlize( title );
    };


Clusterer.EntityToIso8859 = function ( inStr )
    {
    var outStr = '';
    for ( var i = 0; i < inStr.length; ++i )
	{
	var c = inStr.charAt( i );
	if ( c != '&' )
	    outStr += c;
	else
	    {
	    var semi = inStr.indexOf( ';', i );
	    if ( semi == -1 )
		outStr += c;
	    else
		{
		var entity = inStr.substring( i + 1, semi );
		if ( entity == 'iexcl' ) outStr += '\xa1';
		else if ( entity == 'copy' ) outStr += '\xa9';
		else if ( entity == 'laquo' ) outStr += '\xab';
		else if ( entity == 'reg' ) outStr += '\xae';
		else if ( entity == 'deg' ) outStr += '\xb0';
		else if ( entity == 'raquo' ) outStr += '\xbb';
		else if ( entity == 'iquest' ) outStr += '\xbf';
		else if ( entity == 'Agrave' ) outStr += '\xc0';
		else if ( entity == 'Aacute' ) outStr += '\xc1';
		else if ( entity == 'Acirc' ) outStr += '\xc2';
		else if ( entity == 'Atilde' ) outStr += '\xc3';
		else if ( entity == 'Auml' ) outStr += '\xc4';
		else if ( entity == 'Aring' ) outStr += '\xc5';
		else if ( entity == 'AElig' ) outStr += '\xc6';
		else if ( entity == 'Ccedil' ) outStr += '\xc7';
		else if ( entity == 'Egrave' ) outStr += '\xc8';
		else if ( entity == 'Eacute' ) outStr += '\xc9';
		else if ( entity == 'Ecirc' ) outStr += '\xca';
		else if ( entity == 'Euml' ) outStr += '\xcb';
		else if ( entity == 'Igrave' ) outStr += '\xcc';
		else if ( entity == 'Iacute' ) outStr += '\xcd';
		else if ( entity == 'Icirc' ) outStr += '\xce';
		else if ( entity == 'Iuml' ) outStr += '\xcf';
		else if ( entity == 'Ntilde' ) outStr += '\xd1';
		else if ( entity == 'Ograve' ) outStr += '\xd2';
		else if ( entity == 'Oacute' ) outStr += '\xd3';
		else if ( entity == 'Ocirc' ) outStr += '\xd4';
		else if ( entity == 'Otilde' ) outStr += '\xd5';
		else if ( entity == 'Ouml' ) outStr += '\xd6';
		else if ( entity == 'Oslash' ) outStr += '\xd8';
		else if ( entity == 'Ugrave' ) outStr += '\xd9';
		else if ( entity == 'Uacute' ) outStr += '\xda';
		else if ( entity == 'Ucirc' ) outStr += '\xdb';
		else if ( entity == 'Uuml' ) outStr += '\xdc';
		else if ( entity == 'Yacute' ) outStr += '\xdd';
		else if ( entity == 'szlig' ) outStr += '\xdf';
		else if ( entity == 'agrave' ) outStr += '\xe0';
		else if ( entity == 'aacute' ) outStr += '\xe1';
		else if ( entity == 'acirc' ) outStr += '\xe2';
		else if ( entity == 'atilde' ) outStr += '\xe3';
		else if ( entity == 'auml' ) outStr += '\xe4';
		else if ( entity == 'aring' ) outStr += '\xe5';
		else if ( entity == 'aelig' ) outStr += '\xe6';
		else if ( entity == 'ccedil' ) outStr += '\xe7';
		else if ( entity == 'egrave' ) outStr += '\xe8';
		else if ( entity == 'eacute' ) outStr += '\xe9';
		else if ( entity == 'ecirc' ) outStr += '\xea';
		else if ( entity == 'euml' ) outStr += '\xeb';
		else if ( entity == 'igrave' ) outStr += '\xec';
		else if ( entity == 'iacute' ) outStr += '\xed';
		else if ( entity == 'icirc' ) outStr += '\xee';
		else if ( entity == 'iuml' ) outStr += '\xef';
		else if ( entity == 'ntilde' ) outStr += '\xf1';
		else if ( entity == 'ograve' ) outStr += '\xf2';
		else if ( entity == 'oacute' ) outStr += '\xf3';
		else if ( entity == 'ocirc' ) outStr += '\xf4';
		else if ( entity == 'otilde' ) outStr += '\xf5';
		else if ( entity == 'ouml' ) outStr += '\xf6';
		else if ( entity == 'oslash' ) outStr += '\xf8';
		else if ( entity == 'ugrave' ) outStr += '\xf9';
		else if ( entity == 'uacute' ) outStr += '\xfa';
		else if ( entity == 'ucirc' ) outStr += '\xfb';
		else if ( entity == 'uuml' ) outStr += '\xfc';
		else if ( entity == 'yacute' ) outStr += '\xfd';
		else if ( entity == 'yuml' ) outStr += '\xff';
		else if ( entity == 'nbsp' ) outStr += ' ';
		else if ( entity == 'lt' ) outStr += '<';
		else if ( entity == 'gt' ) outStr += '>';
		else if ( entity == 'amp' ) outStr += '&';
		else outStr += '&' + entity + ';';
		i += entity.length + 1;
		}
	    }
	}
    return outStr;
    };


Clusterer.DeEntityize = function ( inStr )
    {
    var outStr = '';
    for ( var i = 0; i < inStr.length; ++i )
	{
	var c = inStr.charAt( i );
	if ( c != '&' )
	    outStr += c;
	else
	    {
	    var semi = inStr.indexOf( ';', i );
	    if ( semi != -1 )
		i = semi;
	    }
	}
    return outStr;
    };


Clusterer.DeElementize = function ( inStr )
    {
    var outStr = '';
    for ( var i = 0; i < inStr.length; ++i )
	{
	var c = inStr.charAt( i );
	if ( c != '<' )
	    outStr += c;
	else
	    {
	    var gt = inStr.indexOf( '>', i );
	    if ( gt != -1 )
		i = gt;
	    }
	}
    return outStr;
    };


Clusterer.DeHtmlize = function ( str )
    {
    return Clusterer.DeEntityize( Clusterer.EntityToIso8859( Clusterer.DeElementize( str ) ) );
    };


// Augment GMarker so it handles markers that have been created but
// not yet addOverlayed.

GMarker.prototype.setMap = function ( map )
    {
    this.map = map;
    };

GMarker.prototype.addedToMap = function ()
    {
    this.map = null;
    };

GMarker.prototype.origOpenInfoWindow = GMarker.prototype.openInfoWindow;
GMarker.prototype.openInfoWindow = function ( node, opts )
    {
    if ( this.map != null )
	return this.map.openInfoWindow( this.getPoint(), node, opts );
    else
	return this.origOpenInfoWindow( node, opts );
    };

GMarker.prototype.origOpenInfoWindowHtml = GMarker.prototype.openInfoWindowHtml;
GMarker.prototype.openInfoWindowHtml = function ( html, opts )
    {
    if ( this.map != null )
	return this.map.openInfoWindowHtml( this.getPoint(), html, opts );
    else
	return this.origOpenInfoWindowHtml( html, opts );
    };

GMarker.prototype.origOpenInfoWindowTabs = GMarker.prototype.openInfoWindowTabs;
GMarker.prototype.openInfoWindowTabs = function ( tabNodes, opts )
    {
    if ( this.map != null )
	return this.map.openInfoWindowTabs( this.getPoint(), tabNodes, opts );
    else
	return this.origOpenInfoWindowTabs( tabNodes, opts );
    };

GMarker.prototype.origOpenInfoWindowTabsHtml = GMarker.prototype.openInfoWindowTabsHtml;
GMarker.prototype.openInfoWindowTabsHtml = function ( tabHtmls, opts )
    {
    if ( this.map != null )
	return this.map.openInfoWindowTabsHtml( this.getPoint(), tabHtmls, opts );
    else
	return this.origOpenInfoWindowTabsHtml( tabHtmls, opts );
    };

GMarker.prototype.origShowMapBlowup = GMarker.prototype.showMapBlowup;
GMarker.prototype.showMapBlowup = function ( opts )
    {
    if ( this.map != null )
	return this.map.showMapBlowup( this.getPoint(), opts );
    else
	return this.origShowMapBlowup( opts );
    };
