var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {	   
	if (GBrowserIsCompatible()) {
		var message = ["This","is","the","secret","message"];
		var map = new GMap2(document.getElementById("google_map"));
		gdir = new GDirections(map, document.getElementById("google_map_directions"));	
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
						
		
		map.setMapType(G_NORMAL_MAP);
		map.setCenter(new GLatLng(49.51350,9.69000), 17);
		map.removeMapType(G_HYBRID_MAP);
		map.removeMapType(G_SATELLITE_MAP);
		map.removeMapType(G_PHYSICAL_MAP);
		map.addControl(new GSmallMapControl()); 


		var KIcon = new GIcon(G_DEFAULT_ICON);
		KIcon.image = "http://kistner.bonfig-team.de/content/img/_googlemap/locator.png";
		KIcon.shadow = "http://kistner.bonfig-team.de/content/img/_googlemap/locator_shadow.png";
		KIcon.iconSize  = new GSize(40, 41);
		KIcon.shadowSize  = new GSize(40, 41);
		KIcon.iconAnchor = new GPoint(20, 21);
		KIcon.infoWindowAnchor  = new GPoint(20, 20);


		function createMarker(point, text, beschreibung, link) {
			markerOptions = { icon:KIcon };
			var marker = new GMarker(point, markerOptions);
			GEvent.addListener(marker,"click", function() {
				var myHtml = '<div style="width:300px; height: auto;"><p style="padding: 0; margin: 0;"><br /><b style="color: #339900;">' + text + '</b><br />' + beschreibung + '<br /><br />' + link + '<br /><br /></p></div>';
				marker.openInfoWindowHtml(myHtml);
			});
			return marker;
		}
		var point = new GPoint(9.69000,49.51350);
		map.addOverlay(createMarker(point, 'Kistner Metrologie Service GmbH', 'Tottenheimer Stra&szlig;e 5<br />97944 Boxberg-Untersch&uuml;pf', ''));				
	}
}
function setDirections(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " ,Deutschland to: " + toAddress,
	{ "locale": "de_DE" });
}


function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("Für die angegebene Start-Adresse (Ort) konnten keine passenden Koordinaten ermittelt werden.\n\nBitte verfeinern Sie Ihre Angabe zum Beispiel durch Angabe der PLZ.");
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("Ein unbekannter Fehler ist aufgetreten.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	
   else alert("An unknown error occurred.");
   
}

function onGDirectionsLoad(){ 
}	
