<!-- ******************************************************************************** -->
<!-- $Id: gmap.js,v 1.2 2008-03-16 01:29:48 martin Exp $ -->
<!-- Javascript-file for Google Map index-generation -->
<!-- JAlbum Project Skin 'NospOfTombl' -->
<!-- Author: Martin Milinovsky -->
<!-- E-mail: jalbum@milinovsky.at -->
<!-- 10sept07	airdrummer@wheel.org -->
<!-- ******************************************************************************** -->

function EStyle(stemImage, stemSize, boxClass, boxOffset) {
	  this.stemImage = stemImage;
	  this.stemSize = stemSize;
	  this.boxClass = boxClass;
	  this.boxOffset = boxOffset;
	  this.fudge = 0;
}

var E_STYLE_1 = new EStyle(resPath+"/ewindow/stem1.png", new GSize(81,87),  "estyle1", new GPoint(-30,87-3));
var E_STYLE_2 = new EStyle(resPath+"/ewindow/stem2.png", new GSize(81,87),  "estyle2", new GPoint(-30,87-1));
var E_STYLE_3 = new EStyle(resPath+"/ewindow/stem3.png", new GSize(81,87),  "estyle3", new GPoint(-30,87-10));
var E_STYLE_4 = new EStyle(resPath+"/ewindow/stem3.png", new GSize(81,87),  "estyle4", new GPoint(-30,87-10));
var E_STYLE_5 = new EStyle(resPath+"/ewindow/stem1.png", new GSize(81,87),  "estyle5", new GPoint(-30,87-3));
var E_STYLE_6 = new EStyle(resPath+"/ewindow/stem6.png", new GSize(100,50), "estyle6", new GPoint(100-2,20));
var E_STYLE_7 = new EStyle(resPath+"/ewindow/stem7.png", new GSize(24,24),  "estyle2", new GPoint(-10,23));
var E_STYLE_8 = new EStyle(resPath+"/ewindow/stem7_light.png", new GSize(24,24),  "estyle2", new GPoint(-10,23));

function EWindow(map,estyle) {
	  // parameters
	  this.map=map;
	  this.estyle=estyle;
	  // internal variables
	  this.visible = false;
	  // browser - specific variables
	  this.ie = false;
	  var agent = navigator.userAgent.toLowerCase();
	  if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
} 

EWindow.prototype = new GOverlay();

EWindow.prototype.initialize = function(map) {
	  var div1 = document.createElement("div");
	  div1.style.position = "absolute";
	  map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
	  var div2 = document.createElement("div");
	  div2.style.position = "absolute";
	  div2.style.width = this.estyle.stemSize.width+"px";
	  map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
	  this.div1 = div1;
	  this.div2 = div2;
}

EWindow.prototype.openOnMap = function(point, html, offset) {
	  this.offset = offset||new GPoint(0,0);
	  this.point = point;
	  this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '"><nobr>' + html + '</nobr></div>';
	  if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
		var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
		this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
	  } else {
		this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
	  }
	  var z = GOverlay.getZIndex(this.point.lat());
	  this.div1.style.zIndex = z;
	  this.div2.style.zIndex = z+1;
	  this.visible = true;
	  this.show();
	  this.redraw(true);
}
	
EWindow.prototype.openOnMarker = function(marker,html) {
	  var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
	  var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
	  this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
}
	
	
EWindow.prototype.redraw = function(force) {
	  if (!this.visible) {return;}
	  var p = this.map.fromLatLngToDivPixel(this.point);
	  this.div2.style.left   = (p.x + this.offset.x) + "px";
	  this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
	  this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
	  this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
}
	
EWindow.prototype.remove = function() {
	  this.div1.parentNode.removeChild(this.div1);
	  this.div2.parentNode.removeChild(this.div2);
	  this.visible = false;
}
	
EWindow.prototype.copy = function() {
	  return new EWindow(this.map, this.estyle);
}
	
EWindow.prototype.show = function() {
	  this.div1.style.display="";
	  this.div2.style.display="";
	  this.visible = true;
}
	
EWindow.prototype.hide = function() {
	  this.div1.style.display="none";
	  this.div2.style.display="none";
	  this.visible = false;
}
	
EWindow.prototype.isHidden = function() {
	  return !this.visible;
}
	
EWindow.prototype.supportsHide = function() {
	  return true;
}
	
// Create the marker and corresponding information window
function createInfoMarker(icon, ew, point, file, text, exifDate) {
		var marker = new GMarker(point, icon);
		var img = file;
		var thumb = "thumbs/"+file;
		var slide = file.substring(0, file.indexOf('.'));
	
		var info = '<table border="0" cellpadding="0" cellspacing="0" class="gmap_infowindow">';
//		if (text != "") {
//			info = info + '<tr><td width="100%" nowrap>' + text + '</td></tr>';
//		}
		info = info + '<tr><td width="100%" nowrap>' + exifDate + '</td></tr>' +
						'<tr><td nowrap><img src="'+thumb+'"></td></tr>' +
					'</table>';
	
		// ========== Open the EWindow instead of a Google Info Window ==========
		GEvent.addListener(marker, "mouseover", function() {
		  ew.openOnMarker(marker, info);
		});
	
		// ========== Close the EWindow if theres a map click ==========
		GEvent.addListener(marker, "mouseout", function() {
			ew.hide();
		});
		
		// ========== Open the EWindow instead of a Google Info Window ==========
		GEvent.addListener(marker, "click",
		function() {
			window.location = "slides/" + slide + ".html";
		});
	
		return marker;
}
	
	var markers = null;
	var bounds = new GLatLngBounds();
	var markerskeyIndex = new Array();
	var markersHashTable = new Object();
	var trackkeyIndex = new Array();
	var trackHashTable = new Object();
	var map = null;

function load() {
	  if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(0, 0), 0);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
	
		// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = resPath+"/mymarker_red.png";
		icon.iconSize = new GSize(16, 28);
		icon.shadowSize = new GSize(16, 28);
		icon.iconAnchor = new GPoint(8, 28);
		icon.infoWindowAnchor = new GPoint(5, 1);
		
		// Create an EWindow
		var ew = new EWindow(map, E_STYLE_8);      
		map.addOverlay(ew);
		
		GDownloadUrl("gmapMarkers.xml", function(data, responseCode) {
			var xml = GXml.parse(data);
			 markers = xml.documentElement.getElementsByTagName("marker");
	
			for (var i = 0; i < markers.length; i++) {
				var file = markers[i].getAttribute("file");
				var text = markers[i].getAttribute("text");
				var exifDate = markers[i].getAttribute("date");
				var displayDate = markers[i].getAttribute("dateDisplay");
				var showAsMarker = markers[i].getAttribute("marker");
				var showAsTrackPoint = markers[i].getAttribute("trackPoint");

				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
									parseFloat(markers[i].getAttribute("lng")));

				bounds.extend(point);
			
				if (showAsMarker == "true") {
					var marker = createInfoMarker(icon, ew, point, file, text, displayDate);
					map.addOverlay(marker);
					markersHashTable[exifDate] = marker;
					markerskeyIndex.push(exifDate);
				}
				if (showAsTrackPoint == "true") {
					trackHashTable[exifDate] = point;
					trackkeyIndex.push(exifDate);
				}
			}
	
			map.setZoom(map.getBoundsZoomLevel(bounds));
			var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
			var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
			map.setCenter(new GLatLng(clat,clng));
	
			if (geoMaptype == "sat") {
				map.setMapType(G_SATELLITE_MAP);
			} else if (geoMaptype == "hyb") {
				map.setMapType(G_HYBRID_MAP);
			} else {
				map.setMapType(G_NORMAL_MAP);
			}
			
			var startmarker = (markersHashTable[ markerskeyIndex[0] ]);
			startmarker.setImage(resPath+"/mymarker_yellow.png");
			var endmarker = (markersHashTable[ markerskeyIndex[markerskeyIndex.length - 1] ]);
			endmarker.setImage(resPath+"/mymarker_green.png");
	
			if (showTrack == "images") {
				markerskeyIndex.sort();
				var i;
				var polyPoints = new Array();
				for (i in markerskeyIndex) {
					polyPoints.push((markersHashTable[ markerskeyIndex[i] ]).getPoint());
				}
				
				var polyline = new GPolyline(polyPoints, "#9900ff", 3, 1);
				map.addOverlay(polyline);
			} else if (showTrack == "gps") {
				trackkeyIndex.sort();
				var i;
				var polyPoints = new Array();
				for (i in trackkeyIndex) {
					polyPoints.push((trackHashTable[ trackkeyIndex[i] ]));
				}
				
				var polyline = new GPolyline(polyPoints, "#0099ff", 3, 1);
				map.addOverlay(polyline);
			}
		});
	  }
}	  

function loadSlideMap(fileName, geoMaptypeSlide) {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("slidemap"));
	map.setCenter(new GLatLng(0, 0), 0);
	map.addControl(new GSmallZoomControl());
	map.addControl(new GMapTypeControl());

	// Create our "tiny" marker icon
	var icon = new GIcon();
	icon.image = resPath+"/mymarker_red.png";
	icon.iconSize = new GSize(16, 28);
	icon.shadowSize = new GSize(16, 28);
	icon.iconAnchor = new GPoint(8, 28);
	icon.infoWindowAnchor = new GPoint(5, 1);
	
	// Create an EWindow
	var ew = new EWindow(map, E_STYLE_8);      
	map.addOverlay(ew);
	
	GDownloadUrl("../gmapMarkers.xml", 
	function(data, responseCode) {
		var xml = GXml.parse(data);
		var markers = xml.documentElement.getElementsByTagName("marker");
		var bounds = new GLatLngBounds();

		for (var i = 0; i < markers.length; i++) {
			var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
									parseFloat(markers[i].getAttribute("lng")));

			bounds.extend(point);
			
			var file = markers[i].getAttribute("file");
			if (file == fileName) {
				var marker = new GMarker(point, icon);
				map.addOverlay(marker);
				map.setZoom(16);
				map.setCenter(point);
				break;
			}
		}

		if (geoMaptypeSlide == "sat") {
			map.setMapType(G_SATELLITE_MAP);
		} else if (geoMaptypeSlide == "hyb") {
			map.setMapType(G_HYBRID_MAP);
		} else {
			map.setMapType(G_NORMAL_MAP);
		}
		
	});
  }
}
	
