var map;
var geocoder;
	var directionsPanel;


function mapsLoaded()
{
	if (!gmapLocation) return;
	map = new google.maps.Map2(document.getElementById("stadtplan"));
	geocoder = new google.maps.ClientGeocoder();
	showLocation(gmapLocation);
	/*
	directionsPanel = document.getElementById("routeResults");

	directions = new GDirections(map, directionsPanel);
	directions.load("from: Fichtestr. 29a, 39112 Magdeburg, Deutschland to: Fehlingstr. 71b, 23570 Lübeck, Deutschland");
	*/}function loadMaps() {  google.load("maps", "2", {"callback" : mapsLoaded});}


function showLocation(location)
{
	address = location.street + ", " + location.zipcode + ", " + location.city + ", " + location.country;
	
	
	if (gmapControlSize == 'small')
		map.addControl(new google.maps.SmallMapControl());
	else 
		map.addControl(new google.maps.LargeMapControl());

	if (!google.maps.BrowserIsCompatible()) return;

	geocoder.getLatLng(
	address,
	function(point)
	{
		if (!point) {
			document.getElementById('noStadtplanEntryFound').innerHTML = "<div>Für diese Location ist kein Stadtplaneintrag vorhanden oder die Adresse konnte nicht zugeordnet werden.</div>";
			document.getElementById('stadtplan').style.display = "none";
		}
		else
		{
			markLocation(point, location);
		}
	}
	)
}

function markLocation(point, location)
{
	
	if (gmapCenter)
		map.setCenter(new google.maps.LatLng(gmapCenter.lat, gmapCenter.long), gmapCenter.zoomLevel);
	else 
		map.setCenter(new google.maps.LatLng(point.lat(), point.lng()), 13);
		
	var marker = new google.maps.Marker(new google.maps.LatLng(point.lat(), point.lng()));
	marker.text = "<b>"+location.name+"</b><br />"+location.street+"<br />"+location.zipcode + " " +location.city;
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(this.text);}
	);
}
