Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 32620)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 32624)
@@ -479,5 +479,5 @@
 		<table id="nearbyDocs">\
 			<tr>\
-				<th><a href="javascript:sortByDistance();">Distance (km)</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\
+				<th><a href="javascript:sortByDistance();">Distance</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\
 			</tr>\
 			<xsl:apply-templates select="//documentNode"/>\
@@ -486,11 +486,13 @@
 	\
 	<xsl:template match="documentNode" priority="5">\
+             <xsl:if test="@nodeID !=\''+id+'\'">\
 		<tr>\
 			<td>___<gsf:metadata name="Latitude"/>______<gsf:metadata name="Longitude"/>___</td>\
-			<td><gsf:link type="document"><gsf:metadata name="Title"/></gsf:link></td>\
+			<td><gsf:link title="'+gs.text.doc.nearby_doc_tooltip+'" type="document"><gsf:metadata name="Title"/></gsf:link></td>\
 		</tr>\
+             </xsl:if>\
 	</xsl:template>';
-	
-	var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20");
+
+        var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20");
 	$.ajax(url)
 	.success(function(response)
@@ -502,5 +504,4 @@
 		var lats = new Array();
 		var lngs = new Array();
-
 		var matches = response.match(/___(-?[0-9\.]*)___/g);
 		for(var i = 0; i < matches.length; i += 2)
@@ -511,9 +512,7 @@
 			lats.push(matchLatFloat);
 			lngs.push(matchLngFloat);
-			
 			var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
-			var distanceString = "" + distance;
-			distanceString = distanceString.substring(0, 6);
-
+  		        var distanceString = "" + distance;
+		        distanceString = distanceString.substring(0, 6);
 			response = response.replace(matches[i] + matches[i+1], distanceString);
 		}
@@ -533,13 +532,13 @@
 			var docLinkEnd = response.indexOf("</td>", docLinkStart);
 			
-			var dist = response.substring(distanceStart + 4, distanceEnd);
+		        var dist = response.substring(distanceStart + 4, distanceEnd);
 			var docLink = response.substring(docLinkStart + 4, docLinkEnd);
 
-			_nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
+			_nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]}); 
 			
 			index = docLinkEnd;
 		}
 		
-		sortByDistance();
+	    sortByDistance(lat,lng);
 		
 		var toggle = $("#nearbyDocumentsToggle");
@@ -549,11 +548,25 @@
 }
 
-function sortByDistance()
-{
-	var sortedTable = '<table id="nearbyDocs"><tr><th><a href="javascript:;">Distance (km)</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th></tr>';
+var map_centering_timeout = null;
+function recenterMapF(lat, lng)
+{
+    return function() {
+	_map.setCenter(new google.maps.LatLng(lat, lng));
+    }
+}
+function recenterMap(lat, lng)
+{
+
+	_map.setCenter(new google.maps.LatLng(lat, lng));
+
+}
+function sortByDistance(base_lat,base_lng)
+{
+	var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:;">Distance</a></th><th><a href="javascript:sortAlphabetically('+base_lat+', '+base_lng+');">Document</a></th></tr>';
 	_nearbyDocs.sort(function(a, b){return (a.distance - b.distance);});
 	for(var i = 0; i < _nearbyDocs.length; i++)
-	{
-		sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="_map.setCenter(new google.maps.LatLng(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '))">' + _nearbyDocs[i].title + "</td></tr>";
+    {
+	
+	    sortedTable += "<tr><td>" + prettifyDistance(_nearbyDocs[i].distance) + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)" >' + _nearbyDocs[i].title + "</td></tr>";
 	}
 	sortedTable += "</table>";
@@ -561,8 +574,25 @@
 	$("#nearbyDocuments").html(sortedTable);
 }
-
-function sortAlphabetically()
-{
-	var sortedTable = '<table id="nearbyDocs"><tr><th><a href="javascript:sortByDistance();">Distance (km)</a></th><th><a href="javascript:;">Document</a></th></tr>';
+function prettifyDistance(distance) {
+
+    var new_distance;
+    if (distance < 1) {
+	new_distance = (distance * 1000);
+	// Round to nearest whole number - don't need to show points of metres..
+	new_distance = Math.round(new_distance);
+	new_distance += " m";
+    }
+    else {
+	new_distance = distance +" km";
+	
+    }
+    return new_distance;
+}
+
+    
+
+function sortAlphabetically(base_lat, base_lng)
+{
+	var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:sortByDistance('+base_lat+', '+base_lng+');">Distance</a></th><th><a href="javascript:;">Document</a></th></tr>';
 	_nearbyDocs.sort(function(a, b)
 	{
@@ -577,5 +607,5 @@
 	for(var i = 0; i < _nearbyDocs.length; i++)
 	{
-		sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="_map.setCenter(new google.maps.LatLng(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '))">' + _nearbyDocs[i].title + "</td></tr>";
+		sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)">' + _nearbyDocs[i].title + "</td></tr>";
 	}
 	sortedTable += "</table>";
