Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 33185)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 33186)
@@ -18,4 +18,6 @@
 var _scrollThroughDefault = true; // TODO: default starts at true
 
+var LOW_OPACITY = 0.1; // make surrounding docs' opacity 10%
+
 function initializeMapScripts() 
 {	
@@ -34,7 +36,13 @@
 			{
 				_docList[jsonNodes[i].nodeID] = jsonNodes[i];
-				_docList.ids.push(jsonNodes[i].nodeID);				
-				createMarkers(jsonNodes[i], true);
-			}
+				_docList.ids.push(jsonNodes[i].nodeID);
+				var options = {
+					"mainDoc": true
+				};
+				console.log("#### " + jsonNodes[i].nodeID + " is a main doc: ");
+				console.log(jsonNodes[i]);
+				createMarkers(jsonNodes[i], options);
+			}
+			
 			updateMap();
 		}
@@ -262,4 +270,13 @@
 	{
 		//console.log("*** responseText (first 250) = " + responseText.substring(0,256));
+		
+		// The first time, docList.ids contains ONLY the main/visible doc's ID and its subsections' IDs.
+		// Any one of these will do to determine
+		if(_docList.ids.length > 0) {
+			var mainDocID = _docList.ids[0];
+			var endIndex = mainDocID.indexOf('.');
+			if(endIndex == -1) { endIndex = mainDocID.length; }
+			mainDocID = mainDocID.substring(0, endIndex);
+		}
 		
 		if(responseText.search("id=\"jsonNodes") != -1)
@@ -279,5 +296,12 @@
 					
 					var found = false;
-					for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
+					for(var j = 0; j < _docList.ids.length; j++) {
+						if(doc.nodeID == _docList.ids[j]) {
+							found = true;							
+							console.log("Found nearby ID " + doc.nodeID + " was already drawn:");
+							console.log(jsonNodes[i]);
+							break;
+						}
+					}
 					
 					if(!found)
@@ -286,6 +310,16 @@
 						_docList.ids.push(doc.nodeID);
 
-						createMarkers(doc, false);
+						// Some "nearby docs" are actually subsections of the main document, which are retrieved
+						// as a nearby doc by performSearchForMarkers() BEFORE the subsection is ever expanded.
+						// We need to distinguish between subsections of the main doc -- which should be displayed
+						// in their specified opacity -- and other docs and their subsections which should be displayed
+						// faded out.
+						if(typeof(mainDocID) !== 'undefined' && doc.nodeID.includes(mainDocID)) {
+							createMarkers(doc, {"mainDoc": true});
+						} else {
+							createMarkers(doc, {"mainDoc": false});
+						}						
 					}
+					
 				}
 			}
@@ -548,11 +582,11 @@
 }
 
-function createMarkers(doc, mainMarker) {	
+function createMarkers(doc, options) {
 	if(doc.mapoverlay) {
 		//console.log("Have shapes: " + doc.mapoverlay.toString());
-		createShapes(doc, mainMarker);
+		createShapes(doc, options);
 	} else { // backwards compatible to deal with Lat and Lng meta stored for doc
 		pos = new google.maps.LatLng(doc.lat,doc.lng);
-		createMarker(doc, pos, mainMarker);
+		createMarker(doc, pos, options);
 	}
 }
@@ -604,7 +638,8 @@
 // This function will create Google Shapes/Overlays and markers out of a given doc JSONNode's doc.mapOverlay
 // (doc.mapOverlay shapes are stored as an array of JSON) and store the shapes/overlays in the doc.shapes array.
-// Param mainMarker: if set to true, marker is red. If false, marker is blue
-function createShapes(doc, mainMarker)
+function createShapes(doc, options)
 {	
+	var isMainDoc = options["mainDoc"];
+
 	// for doc.shapes: don't store JSON anymore, convert them to google Shapes overlays and store them instead
 	doc.shapes = [];
@@ -624,6 +659,6 @@
 		if(shape.type === google.maps.drawing.OverlayType.MARKER) {
 			var marker = shape;
-			// mainMarkers should be red
-			if(!mainMarker) {
+			// markers of the main document should be red, else they'll be blue
+			if(!isMainDoc) {
 				marker["icon"] = "interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png";
 			}
@@ -638,4 +673,8 @@
 		} else {			
 			//console.log("Creating non-marker shape.");
+			
+			if(!isMainDoc) {
+				ShapesUtil.setOpacity(shape, LOW_OPACITY);
+			} // else the shape will be drawn at its configured opacity
 		}
 		
@@ -643,5 +682,5 @@
 		shape.draggable = false;
 		
-		console.log("#### calling addInfoMarker");
+		
 		// doc[i]'s label = doc.shapes[i].description
 		addInfoMarker(doc, shape);
@@ -669,9 +708,10 @@
 // This method is only for backwards compatibility: for those collections with docs that only have Lat and Lng meta
 // and no GPS.mapOverlay (and hence Coordinate) meta.
-// Param mainMarker: if set to true, marker is red. If false, marker is blue
-function createMarker(doc, pos, mainMarker)
-{
+function createMarker(doc, pos, options)
+{	
+	var isMainMarker = options["mainDoc"];
+	
 	var marker;
-	if(mainMarker)
+	if(isMainMarker)
 	{
 		marker = new google.maps.Marker
@@ -750,6 +790,9 @@
 				_docList[doc.nodeID] = doc;
 				_docList.ids.push(doc.nodeID);
-
-				createMarkers(doc, true);
+	
+				var options = {
+					"mainDoc": true // TODO: should this be true or false???
+				};
+				createMarkers(doc, options);
 			}
 			
