
Ext.ns('Ext.ux');
Ext.ux.Anfahrt = Ext.extend(Ext.util.Observable, {
	/* Config */
	anfahrt_map : null,
	mgr : null,
	gdir : null,
	geocoder : null,
	addressMarker : null,
	elMap : null,
	elDirections : null,
	Lat : null,
	Lng : null,

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

	initialize : function(Lat, Lng) {
		this.elDirections.update("");
		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.anfahrt_map
					.addControl(new GMapTypeControl(), new GControlPosition(
									G_ANCHOR_TOP_RIGHT, new GSize(10, 40)));
			this.anfahrt_map.addControl(new GLargeMapControl3D(),
					new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 40)));

			this.icon = new GIcon(G_DEFAULT_ICON);
			this.icon.image = "/img/icons/nadel.png";
			this.marker = new GMarker(new GLatLng(Lat, Lng), {
						icon : this.icon
					});
			this.anfahrt_map.addOverlay(this.marker);

			this.gdir = new GDirections(this.anfahrt_map, this.elDirections.dom);
			GEvent.addListener(this.gdir, "load", function() {
					});
			GEvent.addListener(this.gdir, "error", function() {
				alert("Zu dieser Adresse konnte kein korrespondierender geografischer Ort gefunden werden. Das kann daran liegen, dass die Adresse neu ist oder inkorrekt.");
			});
		}
	},

	setDirections : function(fromAddress, toAddress, locale) {
		if (window.Header) {
			Header.showMap();
		}
		

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

});
