// --------------------------------------------------------------------------------
// gm_Application.js
// --------------------------------------------------------------------------------
///<reference path="~/ow_util.js">

// define the OneWeb GoogleMaps namespace
OneWeb.GoogleMaps = { };

// maps array to hold any maps to create
OneWeb.GoogleMaps.maps = [];

// Map object
OneWeb.GoogleMaps.Map = function (id, coords, zoom, type, overlays, controls, info) {
	this.id = id;
	this.coords = coords;
	this.zoom = zoom;
	this.type = type;
	this.overlays = overlays;
	this.controls = controls;
	this.info = info;
};

OneWeb.GoogleMaps.Map.prototype.initialize = function () {
	var div = document.getElementById(this.id);
	if (div != null) {
		var map = new google.maps.Map2(div);
		var pt = new google.maps.LatLng(this.coords[0], this.coords[1]);
		map.setCenter(pt, this.zoom);
		map.setMapType(this.type);
		
		// overlays
		if (this.overlays.length>0) {
			for (var i=0;i<this.overlays.length;i++) {
				map.addOverlay(new google.maps.GeoXml(this.overlays[i]));
			}
		}
		
		// controls
		if (this.controls.largePanZoom) map.addControl(new google.maps.LargeMapControl());
		if (this.controls.scale) map.addControl(new google.maps.ScaleControl());
		if (this.controls.type) map.addControl(new google.maps.MapTypeControl());
		if (this.controls.overview) map.addControl(new google.maps.OverviewMapControl());
		if (this.controls.marker) map.addOverlay(new google.maps.Marker(pt));
		
		// info window
		if (this.info.length != 0) map.openInfoWindowHtml(pt, this.info);
	}
};

google.setOnLoadCallback(
	function () {
		// check browser compatibility and call the load event
		if (google.maps.BrowserIsCompatible() && !(typeof ClickTaleIsPlayback=="function" && ClickTaleIsPlayback() )) {
			for (var i = 0; i < OneWeb.GoogleMaps.maps.length; i++) {
				OneWeb.GoogleMaps.maps[i].initialize();
			}
		}
	}
);

OneWeb.Util.appendUnloadEvent(
function() {
	// call the Google Maps API unload event
	if (typeof google.maps != "undefined")
		google.maps.Unload();
}
);
