var marker = new Array();;

function showMap(data) {
	if (GBrowserIsCompatible()) { 		
		//// nur beim ersten Aufruf sichern ////
		if (html == '') {
			html = document.getElementById("premium_block").innerHTML;
		}
		
		document.getElementById("premium_block").innerHTML = "<div id=\"premium\">Veranstaltungskarte <a href=\"javascript:void(0);\" style=\"font-size:0.85em\"onclick=\"closeMap(html);\" title=\"Karte schliessen\">[schliessen]</a><div id=\"premium_content\"><div id=\"map\"></div></div></div>";
		document.getElementById("map").style.paddingTop = "10px";
		document.getElementById("map").style.height = "350px";
	
		//// Basis-Icon definieren ////
		var baseIcon = new GIcon(); 
		baseIcon.iconSize=new GSize(40,28); 
		baseIcon.shadowSize=new GSize(40,28); 
		baseIcon.iconAnchor=new GPoint(6,20); 
		baseIcon.infoWindowAnchor=new GPoint(5,1);

		//// benutzte Icons festlegen //// 
		var red = new GIcon(baseIcon, "images/rmr_orange.png", null, "images/rmr_orange_shadow.png");

		var map = new GMap2(document.getElementById("map")); 
		map.addControl(new GLargeMapControl()); //Navigation 
		map.addControl(new GMapTypeControl()); //Typ Buttons 
		map.setCenter(new GLatLng(50.088211,8.45885), 10); //Breite, Länge, Zoom 
		map.setMapType(map.getMapTypes()[2]); //Typ der Anzeige - 1,2 oder 3 

		function createMarker(point, html, icon) { 
			var marker = new GMarker(point,icon); 
			GEvent.addListener(marker, "click", function() { 
				marker.openInfoWindowHtml(html);});
			return marker; 
		} 

		var point, text, i;
		for (i = 0; i < data.length; i++) { 
			//// Marker generieren //// 
			point = new GLatLng(data[i]["pointX"], data[i]["pointY"]);
			text = data[i]["text"];
			text = text + '<br>Route: <a href="javascript:fromHere('+ point.lat() + ',' + point.lng() + ',' + i + ')" title="Routenplanung von hier nach ...">von hier</a> - <a href="javascript:toHere('+ point.lat() + ',' + point.lng() + ',' + i + ')" title="Routenplanung von ... hierher">nach hier</a>'
			marker[i] = createMarker(point, text, red);
			map.addOverlay(marker[i]);
		}
   	}
}

function toHere(pointX, pointY, idx) {
	html = '<div style="font-size:1em;width:320px"><form action="http://maps.google.com/maps" method="get" target="_blank">' +
		   '<label for="saddr">Start (Adresse | Ort | Region):</label><br>' +
		   '<input type="text" size="40" maxlength="40" name="saddr" value="" style="font-size:1em;">' +
		   '<input value="Route berechnen" type="submit" style="font-size: 0.9em">' +
		   '<input type="hidden" name="daddr" value="' + pointX + ',' + pointY + '"></form></div>';
	marker[idx].openInfoWindowHtml(html);
}

function fromHere(pointX, pointY, idx) {
	html = '<div style="font-size:1em;width:320px"><form action="http://maps.google.com/maps" method="get" target="_blank">' +
		   '<label for="daddr">Ziel (Adresse | Ort | Region):</label><br>' +
		   '<input type="text" size="40" maxlength="40" name="daddr" value="" style="font-size: 1em">' +
		   '<input value="Route berechnen" type="submit" style="font-size: 0.9em">' +
		   '<input type="hidden" name="saddr" value="' + pointX + ',' + pointY + '"></form></div>';
	marker[idx].openInfoWindowHtml(html);
}

function closeMap(html) {
	document.getElementById("premium_block").innerHTML = html;
}