Ext.onReady(function() {
			// VisitorStates.init();
			// VisitorStates.load(); //<? echo
			// $javascript->object($session->read('Visitor')); ?>
			// new Ext.ux.Mainmenu('mainmenu', {});

			// Header = new Ext.ux.Header('headercontent', {map:map});
			// new Ext.ux.Global();
			// Listsite = new Ext.ux.Listsite();
		});

Ext.ux.Anfahrt = Ext.extend(Ext.util.Observable, {
	/* Config */
	anfahrt_map : null,
	mgr : null,
	gdir : null,
	geocoder : null,
	addressMarker : null,
	elMap : null,
	elDirections : null,

	constructor : function(elMap, elDirections, Lat, Lng) {
		// config = config ||
		// {};
		// Ext.apply(this, config);
		Ext.ux.Anfahrt.superclass.constructor.call(this); // (this, config)
		this.elMap = Ext.get(elMap);
		this.elDirections = Ext.get(elDirections);
		this.initialize(Lat, Lng);
	},

	initialize : function(Lat, Lng) {
		if (GBrowserIsCompatible()) {
			this.anfahrt_map = new GMap2(this.elMap.dom);
			this.anfahrt_map.setCenter( new GLatLng(Lat,Lng), 13);
			this.anfahrt_map.addControl(new GSmallMapControl());
		
			this.icon = new GIcon(G_DEFAULT_ICON);
			this.icon.iconSize = new GSize(81, 59);
			this.icon.iconAnchor = new GPoint(0, 59);
 
			this.icon.image = "/img/icons/nadel.png";
			this.marker = new GMarker(new GLatLng(Lat,Lng), {icon:this.icon});
			this.anfahrt_map.addOverlay(this.marker);
			
			
			var mapControl = new GHierarchicalMapTypeControl();
			this.anfahrt_map.addControl(mapControl);
			
					
			this.gdir = new GDirections(this.anfahrt_map, this.elDirections.dom);
			GEvent.addListener(this.gdir, "load", function() {
						// Use this function to access information about the
						// latest load()
						// results.

						// e.g.
						// document.getElementById("getStatus").innerHTML =
						// gdir.getStatus().code;
						// and yada yada yada...
					});
			GEvent.addListener(this.gdir, "error", function() {
				if (this.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
					alert("Zu dieser Adresse konnte kein korrespondierender geografischer Ort gefunden werden. Das kann daran liegen, dass die Adresse neu ist oder inkorrekt.\n Error code: "
							+ this.getStatus().code);
				else if (this.getStatus().code == G_GEO_SERVER_ERROR)
					alert("Der geocoding Prozess konnte nicht durchgeführt werden, der Grund für diesen Fehler ist unbekannt.\n Error code: "
							+ this.getStatus().code);

				else if (this.getStatus().code == G_GEO_MISSING_QUERY)
					alert("Der HTTP q Parameter hat entweder gefehlt oder keinen Wert. Für geocoder Anfragen heisst das, das eine leere Adresse als Eingabe spezifiziert ist. Für Routen-Anfragen bedeutet es, dass keine Anfrage im Input spezifiziert ist.\n Error code: "
							+ this.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 (this.getStatus().code == G_GEO_BAD_KEY)
					alert("Der KEY ist ungültig oder passt nicht zu der aktuellen Domain. \n Error code: "
							+ this.getStatus().code);

				else if (this.getStatus().code == G_GEO_BAD_REQUEST)
					alert("Die Routen-Anfrage konnte nicht ausgewertet werden.\n Error code: "
							+ this.getStatus().code);

				else
					alert("Unbekannter Fehler.");

			});
			// this.setDirections("San Francisco", "Mountain View", "de");
		}
	},

	setDirections : function(fromAddress, toAddress, locale) { // console.log(toAddress);
		// fromAddress = "deutschland Wandsbeker Chaussee 34 hamburg";
		// toAddress = "deutschland hamburg framheinstrasse 3";

		this.gdir.load("from: " + fromAddress + " to: " + toAddress, {
					"locale" : locale
				});
		this.marker.hide();				
	}

});
