// Form fields with this class and a rel attribute with the default value
		
var tgIVWBoxManager = Class.create({
	
	className:'tgIVWBoxManager',
	detailMap:null,
	pixel: null,
	baseUrl: null,
	path: "/cgi-bin/ivw/CP/",
	context: null,
	timestamp: 0,

	initialize: function (detailMap) {
		this.pixel                  = document.createElement("img");
		this.pixel.style.width      = "1px";
		this.pixel.style.height     = "1px";
		this.pixel.style.visibility = "hidden";
		
		if (($("klicktel") != null && typeof($("klicktel")) != "undefined") ||
		($("telegate") != null && typeof($("telegate")) != "undefined")) {
		
			$("premiumMap").appendChild(this.pixel);
		}
		this.baseUrl = "http://klicktel.ivwbox.de";		 
	},
	
	track: function () {
		var zeit = new Date();
		if (zeit.getTime() - this.timestamp > 1500) {
			this.timestamp = zeit.getTime();
			if (($("klicktel") != null && typeof($("klicktel")) != "undefined") ||
			($("telegate") != null && typeof($("telegate")) != "undefined")) {
				this.pixel.src = this.baseUrl + this.path + this.context + ";/?r=" + document.referrer + "&d=" + (Math.random() * 100000);
			}
		}
	}
});

var tgDetailMapClass = Class.create({
	
	className:'tgDetailMapClass',
	
	initialize:function() 
	{
		
	},

	init:function(entryId, longitude, latitude, title)
	{
		var map;
		if (tgBrowserIsCompatible()) {
			map               = new tgMap($("premiumMap"));
			map.ivwBoxManager = new tgIVWBoxManager(map);
						
			map.addControl(new tgMapScale(TG_ANCHOR_BOTTOM_RIGHT));
			//map.addControl(new tgMapNavigation(TG_ANCHOR_TOP_LEFT));
			
			//map.addControl(new tgZoomSlider(TG_ANCHOR_TOP_LEFT));
				
			var entryPosition = new tgLngLat(longitude, latitude);
			map.setCenter(entryPosition, 2);

			var entryMarker = new tgMapMarker (entryId, entryPosition, {
				title: title
			});
			map.addOverlay (entryMarker);
			entryMarker._area.removeAttribute("href");
		
			if($("routingForm")){
				map.ivwBoxManager.context = "MEDIA+Eintrag";
				map.addControl(new tgMapSmallNavigation(TG_ANCHOR_TOP_LEFT));
				$("routingForm").observe("submit", function(e){
					if(( 	$("routingForm").start.value != "" 
						&& 	$("routingForm").start.value != $("routingForm").start.alt) 
						&& ($("routingForm").destination.value != "" ) 
						&& 	$("routingForm").destination.value != $("routingForm").start.alt){
						var location    = "http://"+window.location.host+"/routenplaner/";
						var start       = $("routingForm").start.value;
						var destination = $("routingForm").destination.value;
						var params      = "?s0="+start+"&s4="+destination;

						tgmMain.fireEvent('onClickRouting');
						window.open(location+params, "Routenplaner");
						Event.stop(e);
					}else{
						if($("routingForm").destination.value == $("routingForm").start.alt){
							$("routingForm").destination.focus();	
						}else{
							var fillStartDialog = new Effect.Appear($("fillStartFormDialog"), {
								afterFinish: function(){
									window.setTimeout("var hideStartDialog = new Effect.Fade($('fillStartFormDialog'))", 3000);
									$("routingForm").start.focus();
								}
							});
						}
						Event.stop(e);
					}
				});
				
				$("route_swap").observe("click", function(e){
					var start                          = $("routingForm").start.value;
					var destination                    = $("routingForm").destination.value;
					$("routingForm").start.value       = destination;
					$("routingForm").destination.value = start;
				})
				
				$$("#routingForm a.dblink")[0].observe("click", function(e){
					var el = Event.element(e);
					Event.stop(e);
					el.blur();
					if($("routingForm").start.value != "" && $("routingForm").start.value != $("routingForm").start.alt) {
						dcsMultiTrack('DCSext.dblink', 'click');
						//@TODO mogr:  dcsMultiTrack auch zum clickTracker rüberziehen?					
						tgmMain.fireEvent('onClickRoutingDB');
						el.href = "http://www.bahn.de/bin/bopstarter.pl?scope=auskunft&dbkanal_004=L01_S01_D001_KPK0001_reiseauskunft_LZ03&partner=999557_396002&S="+encodeURIComponent($("routingForm").start.value)+"&SADR=1&Z="+encodeURIComponent($("routingForm").destination.value)+"&ZADR=1&timeSel=depart&start=1";
						window.open (el.href, "_blank");
						return;
					} else {
						var fillStartDialog = new Effect.Appear($("fillStartFormDialog"), {
							afterFinish: function(){
								window.setTimeout("var hideStartDialog = new Effect.Fade($('fillStartFormDialog'))", 3000);
								$("routingForm").start.focus();
							}
						});
					}
				})
				//map.ivwBoxManager.track();
			}else{
				if(document.URL.match(/branchenbuch/) ){
					map.ivwBoxManager.context = "branchenbuch";
				}else if(document.URL.match(/telefonbuch/) ){
					map.ivwBoxManager.context = "telefonbuch";
				}else{
					map.ivwBoxManager.context = "index";
				}				
			}
			
			/*
			 * Webtrends Tracking Calls (additional IVW pixel requests)
			 */
			if (!pandoraData.premiumDomain) {
				map.observe("zoomin", function(){ 
					if (typeof(_tag) != "undefined"){
						_tag.DCSext = {};
					}
					dcsMultiTrack('DCSext.maps_action', 'Zoom-In');
					map.ivwBoxManager.track();			
				});
				map.observe("zoomout", function(){
					if (typeof(_tag) != "undefined"){
						_tag.DCSext = {};
					}
					dcsMultiTrack('DCSext.maps_action', 'Zoom-Out');
					map.ivwBoxManager.track();			 
				});
				map.observe("stopdrag", function(){
					if (typeof(_tag) != "undefined"){
						_tag.DCSext = {};
					}
					dcsMultiTrack('DCSext.maps_action', 'Pan');
					map.ivwBoxManager.track();			 
				});
				map.observe("EagleZoomIn", function(){
					if (typeof(_tag) != "undefined"){
						_tag.DCSext = {};
					}
					dcsMultiTrack('DCSext.maps_action', 'Eagle View Zoom-In');
					map.ivwBoxManager.track();			 
				});
				map.observe("EagleZoomOut", function(){
					if (typeof(_tag) != "undefined"){
						_tag.DCSext = {};
					}
					dcsMultiTrack('DCSext.maps_action', 'Eagle View Zoom-Out');
					map.ivwBoxManager.track();			
				});
				if (typeof(_tag) != "undefined"){
					_tag.DCSext = {};
				}
				//dcsMultiTrack('DCSext.maps_action', 'map initialized');				
			}
		}
	}
});
