// Adds group google map to div element on site

// Point List in form EXP @ Lat,LNG @ DESC @ ICON | - the '@' is a split marker.  The '|' is a point marker

function loadGroupMap(pointList,divId,mapScale,mapCenter,mapType,infoWindowWidth,infoWindowBaseURL,imageBaseDir) {
	
		// CODE NOTE [A] mapType not working yet -  hardwired
	
		if (GBrowserIsCompatible()) {
				
				
			// Initialise map and controls
			var mapGM = new GMap2(document.getElementById(divId));
			mapGM.addControl(new GSmallMapControl());
			
			// Extract point data from pointList into an array
			var points = pointList.split("|");
			
			// Calculate map center co-ords
				var mapCenter_Lat_Lng = [];
				
				if (mapCenter == "D") {
				
					var mapCenter_Lat_sum = 0;
					var mapCenter_Lng_sum = 0;
					var pointCount = 0;
					
						// loop through map points to sum extracted lat,lng's
						for( var i = 0; i < points.length; i++) {
						
							if (points[i] == "") break;
							
							// Split point elements - EXP @ Lat,LNG @ DESC HTML @ ICON
							var currentPoint = points[i].split("@");
							var currentCenter = currentPoint[1].split(",");
							
							mapCenter_Lat_sum += parseFloat(currentCenter[0]);
							mapCenter_Lng_sum += parseFloat(currentCenter[1]);
							
							pointCount++;
							
						}
						
						// average points for map center
						mapCenter_Lat_Lng[0] = mapCenter_Lat_sum/pointCount;
						mapCenter_Lat_Lng[1] = mapCenter_Lng_sum/pointCount;
						
				}
				else
				// Entered map center co-ords
				{
			
				mapCenter_Lat_Lng = mapCenter.split(",");
				
				}
			
			// Cast map center co-ords to strings
				mapCenter_Lat_Lng[0] = String(mapCenter_Lat_Lng[0]);
				mapCenter_Lat_Lng[1] = String(mapCenter_Lat_Lng[1]);
			
			// Create map center point
				var mapCenterLatLng = new GLatLng(mapCenter_Lat_Lng[0],mapCenter_Lat_Lng[1]);
			
			// Set map center, scale and type
				// CODE NOTE [A] mapType not working yet -  hardwired
				mapGM.setCenter(mapCenterLatLng,mapScale,G_PHYSICAL_MAP); 
			
			// Loop through information markers and place on map
				var currentMarker = [];
			
				for( var i = 0; i < points.length; i++) {
				
				// Split point elements - EXP @ Lat,LNG @ DESC @ ICON
				if (points[i] == "") break;
				var currentPoint = points[i].split("@");
				
				var current_EXP = currentPoint[0];	
				
				var current_Lat_Lng = currentPoint[1].split(",");	
				var currentLatLng = new GLatLng(current_Lat_Lng[0],current_Lat_Lng[1]);
				
				var current_DESC = currentPoint[2];
				
				// Generate ICON
				
				
					var currentIcon = new GIcon(G_DEFAULT_ICON);
					var currentImagePath = imageBaseDir + currentPoint[3]; 
					
					currentIcon.image = currentImagePath;
					currentIcon.iconSize = new GSize(20, 20);
					currentIcon.shadowSize = new GSize(30, 20);
					currentIcon.iconAnchor = new GPoint(10, 20);
					currentIcon.infoWindowAnchor = new GPoint(10, 3);
				

				 // Set up our GMarkerOptions object
				var markerOptions = { icon:currentIcon };
			
				// Create marker
				currentMarker[i] = new GMarker(currentLatLng, markerOptions);
				
				// Bind content to info window
			//	if(infoWindowWidth == '') infoWindowWidth = '200px' ;
				
				var currentContent =  "<div style ='font:12px arial; width: " + infoWindowWidth +";'>" + current_DESC;
				
				if ( current_EXP != "NOLINK" ) {
					currentContent += "<a href='" + infoWindowBaseURL + "?EXP="+ current_EXP +"'>More details ...</a>" + "</div>";
					};
					
				
				currentMarker[i].bindInfoWindowHtml(currentContent);
				
				// Add marker to map
				mapGM.addOverlay(currentMarker[i]);
			
				// Add click to open information window
				GEvent.addListener(currentMarker[i],"click",function() {
					currentMarker[i].openInfoWindow;
				});
	
			}
			
					
		}
		
}