    var map;
    var gdir;
	var ort;
	var zielAdresse;
	var adresse;

	window.onunload = GUnload;

function findAdress(address, showadress) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
				alert('Firmenadresse ' + address + ' nicht gefunden');
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(showadress);
			  GEvent.addListener(marker, "mouseover", function() {
		        marker.openInfoWindowHtml(adresse);
	          });
            }
          }
        );
      }
}


$(document).ready(function(){
      if (GBrowserIsCompatible()) {
		window.setTimeout('roflschleife()', 1000);
    }
});

function roflschleife() {
	glatl= 51.71882;
	glatw= 8.757155;
	zoomstufe = 14;
	var elm = document.getElementById("google_map");
	if ($(elm).width() > 400) {
		window.setTimeout('roflschleife()', 1000);
		return;
	}
	map = new GMap2(document.getElementById("google_map"));
	map.enableScrollWheelZoom();
	gdir = new GDirections(map, document.getElementById("maps_ergebnis"));
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);
	map.addControl(new GSmallMapControl());
	geocoder = new GClientGeocoder();
	map.setCenter(new GLatLng(glatl, glatw), zoomstufe); // Zentriere die Map auf den entsprechenden Ort
	adresse = anfahrt.titel;
	adresse += "<br/>" + anfahrt.strasse;
	adresse += "<br/>" + anfahrt.ort;
	findAdress(anfahrt.ort + " " + anfahrt.strasse, adresse);
	zielAdresse = anfahrt.ort + " " + anfahrt.strasse;
}

function setDirectionsLat(latlng) {
	gdir.loadFromWaypoints(new Array(latlng, new GLatLng(adresse[1], adresse[2])));
}

function setDirections(fromAddress, fromStreet) {
	gdir.load("from: " + fromAddress + " " + fromStreet + " to: " + zielAdresse,
			{ "locale": "de_DE" });
}

function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS || gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("Die gesuchte Adresse wurde nicht gefunden.");
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR || gdir.getStatus().code == G_GEO_BAD_KEY || gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("Der Geo-Server wurde nicht erreicht.");
   else alert("Es ist ein fehler aufgetreten.");
}

function onGDirectionsLoad(){
	//hier hide / show on direction find
}

