/* functions for showing a Google-map */

var map = null;
var geocoder = null;

function loadMap(){

	if (GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("mapBox"));
		geocoder = new GClientGeocoder();
		showMap(address);
	}
	
	/*
	var box = $("mapBox");
	box.getElement("span").getParent().setStyle("bottom", "auto");
	new Element("div", {"class": "blgL"}).injectInside(box);
	new Element("div", {"class": "rcLT"}).injectInside(box);
	new Element("div", {"class": "rcRT"}).injectInside(box);
	new Element("div", {"class": "rcLB"}).injectInside(box);
	new Element("div", {"class": "rcRB"}).injectInside(box);
	new Element("div", {"class": "blgR"}).injectInside(box);
	new Element("p", {"class": "txt w1Cols"}).injectInside(box).setText("Großansicht? - Klick auf die Karte!");
	*/
}

function showMap(address){

	if (geocoder){
		geocoder.setBaseCountryCode("de");
		geocoder.getLatLng(address, function(point){
			if (!point)
				$("mapBox").addClassName("mapError");
			else {			
				map.setCenter(point, 12);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				
				var a = new Element('a', { 											
											'style': 'cursor: pointer; height: ' + Element.getHeight($('mapBox')) + 'px; width: ' + Element.getWidth($('mapBox')) + 'px; position: absolute; z-index: 99999;'											
										 });
				new Insertion.Top("mapBox", a);
								
				/*
				// add overlay-link:
				new Element("a", {
					"rel": "mapbox",
					"href": "http://maps.google.de/maps?f=q&hl=de&q=" + encodeURI(address),
					styles: {
						"position": "absolute",
						"width": "100%",
						"height": $("mapBox").offsetHeight,
						"background": "#FFF"
					}
				}).injectInside($("mapBox")).setOpacity(0.01);
				// add lightbox-functionality:
				var mb = new Lightbox({
					relString: "mapbox",
					initialWidth: 720,
					initialHeight: 480
				});
				*/
			}
		});
	}
}

window.onload = loadMap;
/*
window.addEvent("load", loadMap).addEvent("unload", GUnload);
*/
