// Javascript
//	Maps6.js
//		This version of htm & js has take the 3d code of 10-1-09 and retro-fitted it for using GMaps
//

//	Bug:  with Chrome - toggling "fullsize" causes the minimizer-arrow on the GOverviewMap to get lost.
//	In this version we address the race conditions between 
//		mb_container
//		google maps
//		dynatree



// Global variables
var objMap; objMap = {};
var kmlpath = 'http://www.stjohnhistoricalsociety.org/KML/';
//var kmlpath = 'KML/';
var jsonpath = 'http://www.stjohnhistoricalsociety.org/JSON/';
var jsonpath = 'JSON/';
var htmlpath = 'Data/';

var hHeader = 160;
var hFooter = 60;
var hWrappers = 20;

// 
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
var urlVariables = $.getUrlVars();

function maximizeMapContainer() {
	$('#mapContainer').mb_fullscreen(); 
/*	
	setTimeout(function(){
		gmapResize();
	}, 1*1000);
*/
}

function resizeMapContainer(w,h) {
	$('#mapContainer').mb_resizeTo(h, w);
/*	
	setTimeout(function(){
		gmapResize();
	}, 1*1000);
*/	
}

function gmapResize() {
	if (objMap && objMap.GMap2) {
		console.info("gmap.checkResize()");
		objMap.GMap2.checkResize();
	}
}
// This function picks up the click and tells GGeoXml to open the corresponding info window
function placemarkClick(placeMark) {
	GEvent.trigger(placeMark, "click");
}
function tourClick(placeMark) {
	// Not supported
	logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "tourClick");	
}

function addMapType_Satellite (dtnode) {
	var mapType = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "addMapType_Satellite", dtnode);	
		objMap.GMap2.addMapType(G_SATELLITE_MAP);
		mapType = G_SATELLITE_MAP;
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "addMapType_Satellite", exception);	
	} finally {
		dtnode.data.mapType = mapType;
		return mapType;
	}
}

function addMapType_Earth (dtnode) {
	var mapType = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "addMapType_Earth", dtnode);	
		objMap.GMap2.addMapType(G_SATELLITE_3D_MAP);
//		var mapui = objMap.GMap2.getDefaultUI();
//		mapui.maptypes.physical = false;
//		objMap.GMap2.setUI(mapui);
		mapType = G_SATELLITE_3D_MAP;
	  
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "addMapType_Earth", exception);	
	} finally {
		dtnode.data.mapType = mapType;
		return mapType;
	}
}


// MapCruncher tile mapping function:  (x,y,zoom) --> tile url
function TileToQuadKey ( x, y, zoom){ 
	var quad = ""; 
	for (var i = zoom; i > 0; i--){
		var mask = 1 << (i - 1); 
		var cell = 0; 
		if ((x & mask) !== 0) {
			cell++; 
		}
		if ((y & mask) !== 0) {
			cell += 2; 
		}
		quad += cell; 
	} 
	return quad; 
}


function addMapType_Topo (dtnode) {
	var mapType = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "addMapType_Topo", dtnode);	
		
		// Create the TileLayer
		var tilelayers = [new GTileLayer(new GCopyrightCollection("Map Data: Topo"), 12, 18)];
		tilelayers[0].getTileUrl = function  (a,b) {
			var tileURL = "Maps/Topo/Layer_NewLayer/" + TileToQuadKey(a.x,a.y,b) + ".png";  
			return tileURL; 
		};
	
		tilelayers[0].getCopyright = function(a,b) {
			return {prefix:"Map: ", copyrightTexts:["Robert Garrison"]};
		};
		tilelayers[0].isPng = function() {return true;}; 
			
		// Create the MapType, copying most things from G_SATELLITE_MAP ==
		var mapType = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Topo", {errorMessage: "data not available"});
			
		// Add the maptype to the map and map-controls
		objMap.GMap2.addMapType(mapType);
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "addMapType_Topo", exception);	
	} finally {
		dtnode.data.mapType = mapType;
		return mapType;
	}
}

function addMapType_Oxholm1800 (dtnode) {
	var mapType = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "addMapType_Oxholm1800", dtnode);	
		
		// Create the TileLayer
		var tilelayers = [new GTileLayer(new GCopyrightCollection("Map Data: Oxholm 1800"), 12, 18)];
		tilelayers[0].getTileUrl = function  (a,b) {
			var tileURL = "Maps/Oxholm1800-mc/Layer_NewLayer/" + TileToQuadKey(a.x,a.y,b) + ".png";  
			return tileURL; 
		};
	
		tilelayers[0].getCopyright = function(a,b) {
			return {prefix:"Map: ", copyrightTexts:["Oxholm 1800"]};
		};
		tilelayers[0].isPng = function() {return true;}; 
			
		// Create the MapType, copying most things from G_SATELLITE_MAP ==
		var mapType = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Oxholm 1800", {errorMessage: "data not available"});
			
		// Add the maptype to the map and map-controls
		objMap.GMap2.addMapType(mapType);
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "addMapType_Oxholm1800", exception);	
	} finally {
		dtnode.data.mapType = mapType;
		return mapType;
	}
}

function addMapType_Placenames (dtnode) {
	var mapType = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s)", "Maps.js", "addMapType_Placenames", dtnode);	
		
		var tilelayers = [new GTileLayer(new GCopyrightCollection("Map Image: William Stelzer"), 12, 19)];
		tilelayers[0].getTileUrl = function  (a,b) {
			var tileURL = "Maps/STJ 1947 - abridged/Layer_NewLayer/" + TileToQuadKey(a.x,a.y,b) + ".png";  
//			var tileURL = "Maps/STJ 1947 Map/Layer_NewLayer/" + TileToQuadKey(a.x,a.y,b) + ".png";  
			return tileURL; 
		};
	
		tilelayers[0].getCopyright = function(a,b) {
			return {prefix:"Map: ", copyrightTexts:["William Stelzer"]};
		};
		tilelayers[0].isPng = function() {return true;}; 
			
		// Create the MapType, copying most things from G_SATELLITE_MAP
		var mapType = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Place-names 1840s-1940s", {errorMessage: "data not available"});
			
		// Add the maptype to the map and map-controls
		objMap.GMap2.addMapType(mapType);
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "addMapType_Placenames", exception);	
	} finally {
		dtnode.data.mapType = mapType;
		return mapType;
	}
}



function asyncLoadHtml(dtnode, urlHtml) {
	try {
		dtnode.data.overlayHtml = null;
		logMsg("Module (%s), Procedure (%s), dtnode (%s) url (%s)", "Maps.js", "loadHtml", dtnode.data.title, urlHtml);	
		$.get(urlHtml, function (Html, status) {
			if (Html) {
				dtnode.data.overlayHtml = $(Html);	// Parse the Html text and store DOM Nodes in a JQuery object

/*
		<div class="Estate Sieben">
			<a class="myPlayer"  
				href="http://blip.tv/file/get/KimAronson-TwentySeconds58192.flv" 
				style="background-image:url(/img/demos/58192.jpg)">  
				<img src="/img/player/btn/play_large.png" alt="Demo video 1"/>  
			</a>  
			<br class="clear" />
		</div>

	let's test this out !
				var jo = dtnode.data.overlayHtml;
				
				// ??? Why does this fail? 
				t_div = $("div", jo);				
				logMsg('Count of $("div", jo) is %s', t_div.length);		
				
				// ??? Why does this fail? 
				t_Lovango = $(".Lovango", jo);
				logMsg('Count of $(".Lovango", jo) is %s', t_Lovango.length);
				
				t_a = $("a", jo);
				logMsg('Count of $("a", jo) is %s', t_a.length);
				
				t_myPlayer = $(".myPlayer", jo);
				logMsg('Count of $(".myPlayer", jo) is %s', t_myPlayer.length);
				
				t_img = $("img", jo);
				logMsg('Count of $("img", jo) is %s', t_img.length);
				
				t_br = $("br", jo);
				logMsg('Count of $("br", jo) is %s', t_br.length);
*/
				
			}
		});
		
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "loadHtml", exception);	
	}
}

function asyncLoadJson(dtnode, urlJson) { 
	try {
		dtnode.data.overlayJson = null;
		logMsg("Module (%s), Procedure (%s), dtnode (%s) url (%s)", "Maps.js", "loadJson", dtnode.data.title, urlJson);	
		$.get(urlJson, function (json, status) {
			if (json) {
				//dtnode.data.overlayJson = JSON.parse(json);	  // parse the json data
				dtnode.data.overlayJson = eval('(' + json + ')');
			}
		});
		}
	catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "loadJson", exception);	
	}
}

function loadKml(dtnode, urlKml) {
	ret_geoXml = null;
	try {
		logMsg("Module (%s), Procedure (%s), dtnode (%s) url (%s)", "Maps.js", "loadKml", dtnode.data.title, urlKml);	
		geoXml = new GGeoXml(urlKml);
		if (true) {	// How to test for success?
			logMsg("GGeoXml loaded (%o)", geoXml);
		} else {
			logMsg("Error:	Module (%s), Procedure (%s), GGeoXml failed to load url (%s)", "Maps.js", "loadKml", urlKml);
			throw new Error("Bailing..");
		}
		objMap.GMap2.addOverlay(geoXml);
		dtnode.data.overlayKml = geoXml;
		ret_geoXml = geoXml;
		}
	catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "loadKml", exception);	
	} finally {
		dtnode.data.overlayKml = ret_geoXml;
		return ret_geoXml;
	}
}

// When the container is ready...
function mapLoad() {
	try {
		logMsg("Module (%s), Procedure (%s)", "Maps.js", "Loading the map");	


		if (GBrowserIsCompatible()) {
			
			objMap.GMap2 = new GMap2(document.getElementById("map3d"), {mapTypes:[]});
//			objMap.GMap2.setCenter(new GLatLng(18.34024, -64.736938), (12));
			objMap.GMap2.addControl(new GLargeMapControl());
			objMap.GMap2.addControl(new GScaleControl());  
			objMap.GMap2.addControl(new GOverviewMapControl());		// Race-condition with minimizer arrow control. try delaying
			objMap.GMap2.enableScrollWheelZoom();
			objMap.GMap2.enableDoubleClickZoom();
			objMap.GMap2.enableContinuousZoom();
		} else {
			logMsg("Module (%s), Procedure (%s):  Browser not supported by GMaps", "Maps.js", "Loading the map");
			return;
		}
		
		// Intercept Placemark events being added to the viewport, and add Placemarks to the sidebar
		// 	Note:  If placemark is not visible, then it won't appear in the sidebar!!!
		  GEvent.addListener(objMap.GMap2, "addoverlay", function(overlay) {
			// If this is a named overlay (e.g. not the GGeoXml itself, or the infowindow)
			if (overlay.name) {
			  // check to see if we already know about this one
			  if (overlay.Known) {
				// do nothing
			  } else {
				try { 
					logMsg("Module (%s), Procedure (%s), Placemark (%s)", "Maps.js", "adding a Placemark to the Tree", overlay.name);	
					var dtnodes = $("#OverlayTree").dynatree("getSelectedNodes");	
					
					// Search list of Placemarks for "beforeNode"
					var beforeNode;
					dtnodes[0].visit( function(dtnode){
						if (dtnode.data.title > overlay.name) {
							if (!beforeNode) {
								beforeNode = dtnode;
							}
							return false;	// Doesn't seem to stop the recursive loop
						}
					 });
					
					// Call the DynaTreeNode.addChild() member function and pass options for the new "Placemark" node
					var childNode = dtnodes[0].addChild({
						title: overlay.name,
						tooltip: "tootip = " + overlay.name,
						isFolder: false,
						hideCheckbox: true, 

						// Custom data
						placemark: overlay
					}, beforeNode );	
					overlay.Known = true;
					dtnodes[0].expand(true);
					
					// Expand overlay content
					var tabs = [];
					tabs.push (new GInfoWindowTab("Main", "<h1>" + overlay.name + "</h1>" + overlay.description));
/*					
html = 				
'<object width="240" height="193"><param name="movie" value="http://www.youtube.com/v/TxHKSHvMRWE&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/TxHKSHvMRWE&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="240" height="193"></embed></object>';
*/
					var htmlData = objMap.rootNode.data.currentChild.data.overlayHtml;	// This html text has already been parsed into a JQuery object
					var selector = "." + overlay.name;									// Match .classname with overlay name
					var html = $(selector, htmlData);	// Select named division  -- why doesn't this work?  Work-around: Added another magic <div> wrapper
					var html2 = '<script>try { logMsg("trying..."); flowplayer("a.myPlayer", "flowplayer/flowplayer-3.1.4.swf"); logMsg("Player should be activated"); } catch(exception) { } </script>'	;				
					if (html.length) {
						tabs.push (new GInfoWindowTab("Stories", "<h1>" + overlay.name + "</h1>" + $(html).html() + html2));	// code to install and activate Flowplayer
						logMsg("Adding an InfoWindowTab for (%s)", overlay.name);
					}
					overlay.bindInfoWindowTabs(tabs);
/*
// The problem with having mouse-hover use the infoWindow is that the infoWindow should be reserved for Click operations.
// We want to have a "tooltip" to display the Title
//
					GEvent.addListener(overlay, "mouseover", function() {
						overlay.openInfoWindowHtml( overlay.name );
					});


					GEvent.addListener(overlay, "mouseout", function() {
						overlay.closeInfoWindow();
					});
*/

				} catch (exception) {
					logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "onSelect", exception);	
				}
				
			  }
			}
		  }); 
		 // End Intercept...
		
		$("#OverlayTree").dynatree({
			checkbox: true,
			// Override class name for checkbox icon:
			classNames: {checkbox: "ui-dynatree-radio"}, 
			selectMode: 1,
			
			// Custom data: current selected child 
			currentChild: null,
			
			//Handlers
			// I really just want to apply these click handlers to the placemarks, not to the entire tree
			// but if defined overthere, then nothing happens
			onClick: function(dtnode) {
				if ( 'placemark' in dtnode.data ) {
					placemarkClick(dtnode.data.placemark);
					logMsg("Map3d: placemarkClick: %s", dtnode.data.title);
					return false;
				} else if ( 'tour' in dtnode.data ) {
					tourClick(dtnode.data.tour);
					logMsg("Map3d: tourClick: %s", dtnode.data.title);
					return false;
				}
			},
	
			onDblClick: function(dtnode) {
				if ( 'placemark' in dtnode.data ) {
					logMsg("Map3d: onDblClick: %s", dtnode.data.title);
					objMap.GMap2.zoomIn(dtnode.data.placemark.getLatLng(), true, true);
					return false;
				}
			},
			// MapType overlay
			onSelect: function(flag, dtnode) {
				try {
					logMsg("Module (%s), Procedure (%s), flag (%s), dtnode.data.title (%s)", "Maps.js", "onSelect", flag, dtnode.data.title);	
					if (flag) {
						rootNode = $("#OverlayTree").dynatree("getRoot");
						if (rootNode.data.currentChild) {
							objMap.GMap2.removeOverlay( rootNode.data.currentChild.data.overlayKml );
							rootNode.data.currentChild.removeChildren();
						}
						
						rootNode.data.currentChild = dtnode;

						// Interesting issues
						// Url variables, map switching and interception placemarks
						if (!objMap.GMap2.isLoaded()) {

							objMap.GMap2.setCenter(new GLatLng(18.44024, -64.736938), (12), dtnode.data.mapType);
							
							if (urlVariables.lat && urlVariables.long && urlVariables.zoom-level) {
								window.setTimeout( function () {
									try {
										// Could try animation steps
										objMap.GMap2.setCenter(new GLatLng(urlVariables.lat, urlVariables.long)
																, parseInt(urlVariables.zoom-level)
																, $("#OverlayTree").dynatree("getTree").selectKey(urlVariables.map-type).data.mapType);
									} catch (exception) {
										logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "onSelect:setTimeout", exception);	
									}
								}, 5 *1000);
							}
						} else {
							objMap.GMap2.setMapType(dtnode.data.mapType);
						}
						
						$("#MapIntro h1").text(dtnode.data.mapTitle);
						
						asyncLoadHtml( dtnode, htmlpath + dtnode.data.urlHtml + "?" + Math.random() );
//						asyncLoadJson( dtnode, jsonpath + dtnode.data.urlJSON + "?" + Math.random());
						rootNode.data.currentChild.data.overlayKml = loadKml( dtnode, kmlpath + dtnode.data.urlKml + "?" + Math.random());
						/*
						// The problem is we may need to first zoom out to view all the placemarks, in order to build the tree of placemarks,
						// then we can fly back down.
						// For now I can either just zoom up to level 13 or just build any incomplete tree.
						//
						if (rootNode.data.currentChild.data.overlayKml) {	// Zoom up and down to gather all the placemarks
							zoom = objMap.GMap2.getZoom();
							
							if (zoom > (17-4)) {
								center = objMap.GMap2.getCenter();
								objGMap2.savePosition();
								objMap.GMap2.setCenter(center, 13);
								// Wait to collect all placemarks
								objGMap2.returnToSavedPosition();
							}
							
						}
						*/
					} else {
						logMsg("Map3D: Unexpected node collapse event");
						// Our radio box rules:  If the set of maps types is not null, then one must be selected.
						// Thus we do not allow the user to "deselect" this map-type.
						dtnode.select();
					}
				} catch (exception) {
					logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "onSelect", exception);	
				}
	
			},
			
			onPostInit: function (isReloading, isError) {
				try {
					logMsg("Module (%s), Procedure (%s), isReloading (%s), isError (%s)", "Maps.js", "onPostInit", isReloading, isError);	
					if (!isError) {
						objMap.rootNode = this.getRoot();
						for (var i=0; i<objMap.rootNode.childList.length; i++) {
							dtnode = objMap.rootNode.childList[i];
							logMsg("dtnode (%s)", dtnode.data.title);
							dtnode.data.addMapType(dtnode);	
						}
						
						// Process query parms.
						// if "explorer=1" then create mouse-tracking display
						// if "map type and lat-long & zoom specified, then set center
						// Else use default
						if (urlVariables["map-type"]) {
							$("#OverlayTree").dynatree("getTree").selectKey(urlVariables["map-type"]);
							
						} else {
							$("#OverlayTree").dynatree("getTree").selectKey("STJPlacesNames");
						}
/*						
						if (urlVariables["map-type"] == "Oxholm1800") {
							map.setCenter(new GLatLng(parseFloat(urlVariables["lat"]), parseFloat(urlVariables["long"])), parseInt(urlVariables["zoom-level"]), Oxholm1800);
						} else if (urlVariables["map-type"] == "Topo") {
							map.setCenter(new GLatLng(parseFloat(urlVariables["lat"]), parseFloat(urlVariables["long"])), parseInt(urlVariables["zoom-level"]), TrailBandit2006);
						} else 
*/				
						
						
						// If Explorer, then reveal the lat/long of the mouse cursor
						if (urlVariables.explorer == "1") {
							// Add Mousemove event listener -> Display Latitude/Longitude of cursor
							GEvent.addListener(objMap.GMap2, "mousemove", function(point){
								var zoomLevel = objMap.GMap2.getZoom();
								var latLngStr6 = point.y.toFixed(6) + ', ' + point.x.toFixed(6);
								$("#mapCursor").text( latLngStr6 + " " + zoomLevel );
							});
							
							$("#mapCursorDiv").removeClass("NotSelected");
						}
					}
				} catch (exception) {
					logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "onPostInit", exception);	
				}
			},
			
			debugLevel: 2, // 0:quiet, 1:normal, 2:debug
	
			// Children with additional custom attributes: mapType, urlKml, domKml
			children: [
				{ title: 'Satellite', key: 'Satellite', isFolder: true,  addMapType: addMapType_Satellite, mapTitle: 'Satellite map', urlKml: null, overlayKml : null }
				, { title: 'Earth', isFolder: true, addMapType: addMapType_Earth,  mapTitle: 'Earth', urlKml: null, domKml: null, overlayKml : null  }
				, { title: 'Topographic', isFolder: true, addMapType: addMapType_Topo,  mapTitle: 'Topographic map', urlKml: null, domKml: null, overlayKml : null  }
				, { title: 'Oxholm 1800', key: 'Oxholm1800', isFolder: true, addMapType: addMapType_Oxholm1800,  mapTitle: '1800 Oxholm map', urlKml: 'STJ%201800%20Placemarks.kmz'
				, overlayKml : null  }
				, { title: 'Places 1840-1940', key: 'STJPlacesNames', isFolder: true, addMapType: addMapType_Placenames, urlHtml: 'Placemarks.htm', mapTitle: '1947 Aerial photo mosiac, assembled by William Stelzer'
				, urlKml: 'Placemarks2.kml', overlayKml : null  }
				]
		});
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "loading the map", exception);	
	}

}

// When document is ready...
$(document).ready(function () {
	try {
		logMsg("Module (%s), Procedure (%s)", "Maps.js", "Creating the map containers");	
		if (GBrowserIsCompatible()) {
			
			// Resize the static mapContainerWrapper
			var h = parseInt($("#inner-wrapper").css("height")) - parseInt($("#header").css("height")) - parseInt($("#footer").css("height"));
			$("#mapContainerWrapper").height(h -10);

			var w = parseInt( $("#inner-wrapper").css("width") ) -80;
			$("#mapContainer").width(w);
			$("#mapContainer").height(h -10);

		
			// Build the container for the Google map division and the dynaTree division
			$(".containerPlus").buildContainers({ 
				containment:"document", 
				elementsPath:"Includes/mb.containerPlus.2.3.2/elements/",
				onResize:function(o){gmapResize();}, 
				onClose:function(o){}, 
				onCollapse:function(o){gmapResize();}, 
				onIconize:function(o){gmapResize();}

				, onLoad:function(o){
					
					// Prepare the mapContainer
					// Start map loading.
					window.setTimeout ( function() {
						if ($("#mapContainer").mb_getState("iconized")) {
							$("#mapContainer").mb_iconize(); 
						}
						
						var w = parseInt($("#inner-wrapper").css("width")) -80;
						var h = parseInt($("#inner-wrapper").css("height"))
							- parseInt($("#header").css("height")) - parseInt($("#footer").css("height")) -80;
						resizeMapContainer(w,h);
						
						mapLoad();
					}, 0*1000);
				} 
				
			}); 
		}
	} catch (exception) {
		logMsg("Exception:      Module (%s), Procedure (%s), exception (%s)", "Maps.js", "creating the map containers", exception);	
	}

});

// Release memory
$(window).unload(GUnload);
							
// end of maps8s.js