/**
 * MDVGadgets (mdvJavaScriptMapComponent)
 * Implementation of gadgets which are used to enhance functionality of MDVMap
 *
 * $Id: mdvGadgets.js,v 1.2 2007/02/15 12:33:15 mdvti Exp $
 *
 * Software Version History:
 *
 * 1.1	2006/08/08	TI		HEAD:		Version added. Initial Revision.
 * 1.2	2006/08/09	TI		HEAD:		First Panning Revision.
 * 1.3	2006/08/09	TI		HEAD:		Crosshair Gadget added.
 * 1.4	2006/08/10	TI		HEAD:		Double Click for Map Navigator added.
 * 1.5	2006/08/10	TI		HEAD:		Context Menu Disabled for Map Navigator.
 * 1.6	2006/08/11	TI		HEAD:		Map EFA Info added (revision needed).
 * 1.7	2006/08/13	TI		HEAD:		Fixed Real to Px Ratio.
 * 1.8	2006/08/14	TI		HEAD:		Stop Means for Pins.
 * 1.9	2006/08/17	TI		HEAD:		Refactoring.
 * 1.10 2006/08/18	TI		HEAD:		Zoom on Double Click.
 * 1.11 2006/08/22  SM		HEAD:   	MDVContextMenu Gadget added.
 * 1.12	2006/08/23	TI		HEAD:		Map Boundaries.
 * 1.13	2006/08/31	TI		HEAD:		EFAInfo for Multiple Map Instances.
 * 1.14 2006/09/06	TI		HEAD:		Continuous Panning
 * 1.15	2006/09/20	TI		HEAD:		MapControl added.
 * 1.16 2006/09/21	TI		HEAD:		Don't Refresh Icons on Single Click.
 * 1.17 2006/09/21	TI		HEAD:		Refactoring MapEFAInfo.
 * 1.18 2006/10/19	TI		HEAD:		MapControl API for Origin Coords.
 * 1.19 2006/10/27	TI		HEAD:		Bugfix Centre Map.
 * 1.20 2006/12/12	TI		HEAD:		Fix MOT in EFAInfo.
 *
 */

/**
 * MDVGadgetBase
 * @param {object} mdvMap
 */
 function MDVGadgetBase(mdvMap) {

 	if (!mdvMap)
 		return;

	// Name of gadget
 	this.name = 'GadgetBase';
 	// Reference to mdvMap object
 	this.mdvMap = mdvMap;

 	this.mdvMap.registerGadget(this);
 }

 MDVGadgetBase.prototype.stopEvent = function(e) {
 	if (!e)
 		return true;

    e.cancelBubble = true;
    e.returnValue = false;

    if (e.stopPropogation)
        e.stopPropogation();

    if (e.preventDefault)
        e.preventDefault();

 	return false;
 };

 MDVGadgetBase.prototype.activate = function() {
	return true;
 };

 MDVGadgetBase.prototype.deactivate = function() {
	return true;
 };

 MDVGadgetBase.prototype.ondblclick = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onkeypress = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmousedown = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmousemove = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmouseout = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmouseover = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmouseup = function(e) {
	return true;
 };

 MDVGadgetBase.prototype.onmousewheel = function(e) {
 	return true;
 };

 MDVGadgetBase.prototype.oncontextmenu = function(e) {
 	return true;
 };

 /**
  * MDVMapNavigator
  * @param {object} mdvMap
  */
  function MDVMapNavigator(mdvMap) {
 	if (!mdvMap)
 		return;

	// Name of gadget
 	this.name = 'MapNavigator';
 	// Reference to mdvMap object
 	this.mdvMap = mdvMap;
 	// Indicates whether dragging is active or not
 	this.mouseDown = false;

 	// Store the previous Centre Coords
 	this.centre;

 	// Mouse positions
 	this.mouseLast  = new MDVPoint(-1, -1);
 	this.mouseStart = new MDVPoint(-1, -1);

 	this.mdvMap.registerGadget(this);

	// Inherit from MDVGadgetBase
    for (var method in MDVGadgetBase.prototype) {

        if (!MDVMapNavigator.prototype[method])
            MDVMapNavigator.prototype[method] = MDVGadgetBase.prototype[method];

    }

 	this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED, this, this.setDefaultCursor);
  }

  MDVMapNavigator.prototype.setDefaultCursor = function() {
	if (this.mdvMap.config.get('cursorIdle')) {
		if (document.all)
			this.mdvMap.mapper.style.cursor = 'url(\'' + this.mdvMap.config.get('cursorIdle') + '\')';
		else
		 	this.mdvMap.mapper.style.cursor = '-moz-grab';
	}
  };

  MDVMapNavigator.prototype.oncontextmenu = function(e) {
  	return false;
  };

  MDVMapNavigator.prototype.ondblclick = function(e) {
    var mX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
    var mY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

    var offsetL = 0;
    var offsetT = 0;

    var obj = this.mdvMap.viewport;

    while(obj) {
    	offsetL += obj.offsetLeft;
    	offsetT += obj.offsetTop;

    	obj = obj.offsetParent;
    }

    mX = mX - (offsetL);
    mY = mY - (offsetT);

	var point = new MDVPoint(mX, mY);

	var newC = this.mdvMap.getCoordinates(point);
	this.mdvMap.setCentre(newC);

	// First we need to convert the real to px coordinates, after that we can set the new zoom level.
	if (this.mdvMap.config.get('zoomOnDoubleClick') && this.mdvMap.config.get('zoomOnDoubleClick') == 'true') {

		var curZoomLevel = parseInt(this.mdvMap.config.getZoomLevelIndex());
		if (curZoomLevel < 5) {
	  		this.mdvMap.setZoomLevel(5);
		}
		else { // original-fn
			var newZoomLevel = this.mdvMap.config.getZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())+1);
			if (newZoomLevel != null)
				this.mdvMap.setZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())+1);
		}
	}

	this.mdvMap.update();

	return false;

	//this.mdvMap.events.triggerEvent(MDVEvent_DEBUG, 'x: ' + newC.x + ' y: ' + newC.y);
  };

  MDVMapNavigator.prototype.onmousewheel = function(e) {
	e = e ? e : window.event;
  	var wheelDelta = e.wheelDelta ? e.wheelDelta : e.detail*-1;

  	if (wheelDelta > 0) {
  		var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex()+1);
  		if (zoomLevel != null) {
	  		this.mdvMap.setZoomLevel(this.mdvMap.config.getZoomLevelIndex()+1);
	  		this.mdvMap.update();
  		}
  	}
  	else {
  		var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex()-1);
  		if (zoomLevel != null) {
	  		this.mdvMap.setZoomLevel(this.mdvMap.config.getZoomLevelIndex()-1);
	  		this.mdvMap.update();
  		}
   	}

   	this.stopEvent(e);
   	return false;
  };

  MDVMapNavigator.prototype.onmousedown = function(e) {
	e = e ? e : window.event;

	if ((e.button == 0 && !window.event) || (e.button == 1 && window.event))
	{
	    var mX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
	    var mY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

	    this.mouseLast.x  = mX;
	    this.mouseLast.y  = mY;

	    this.mouseStart.x = this.mouseLast.x;
	    this.mouseStart.y = this.mouseLast.y;

	    if (!this.mouseDown) {
			if (this.mdvMap.config.get('cursorMove')) {
				if (document.all)
					this.mdvMap.mapper.style.cursor = 'url(\'' + this.mdvMap.config.get('cursorMove') + '\')';
				else
					this.mdvMap.mapper.style.cursor = '-moz-grabbing';
	    	}
			else
				this.mdvMap.mapper.style.cursor = 'auto';
	    }

		this.centre = new MDVCoordinates(this.mdvMap.getCentre().mapName,
			this.mdvMap.getCentre().x,
			this.mdvMap.getCentre().y);

	    this.mouseDown 	  = true;

	    return this.stopEvent(e);
	} else {
		return true;
	}
  };

  MDVMapNavigator.prototype.onmouseup = function(e) {
	e = e ? e : window.event;
  	if (this.mouseDown) {
		if (this.mdvMap.config.get('cursorIdle')) {
			if (document.all)
				this.mdvMap.mapper.style.cursor = 'url(\'' + this.mdvMap.config.get('cursorIdle') + '\')';
			else
				this.mdvMap.mapper.style.cursor = '-moz-grab';
		}
		else {
			this.mdvMap.mapper.style.cursor = 'auto';
		}

		var centre = this.mdvMap.getCentre();
	  	if (this.centre && (this.centre.x != centre.x || this.centre.y != centre.y)) {
			this.mdvMap.events.triggerEvent(MDVEvent_MAP_INITIALISED, 'MDVMap tiles have been initialised', this.mdvMap);
	  	}
  	}

  	this.mouseDown = false;

	fnMap_AppendHistory(this.mdvMap); //roccas append history
	
  	return false;
  };

  MDVMapNavigator.prototype.onmouseout = function(e) {
  	// Next line has been deactivated due to problems while clicking on tile borders
 	//this.onmouseup(e);
	return true;
  };

 MDVMapNavigator.prototype.onmousemove = function(e) {
	e = e ? e : window.event;

	var mouseX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
	var mouseY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

    var offsetL = 0;
    var offsetT = 0;

    var obj = this.mdvMap.viewport;

    while(obj) {
    	offsetL += obj.offsetLeft;
    	offsetT += obj.offsetTop;

    	obj = obj.offsetParent;
    }

    mouseX = mouseX - (offsetL);
    mouseY = mouseY - (offsetT);

	var centrePoint  = new MDVPoint(mouseX, mouseY);
	var centreCoords = this.mdvMap.getCoordinates(centrePoint);

	this.mdvMap.events.triggerEvent(MDVEvent_MOUSE_MOVED, 'MDVMap noticed a mouse movement.', centreCoords);

	if (this.mouseDown) {
		if (this.mdvMap.config.get('cursorMove')) {
			if (document.all)
				this.mdvMap.mapper.style.cursor = 'url(\'' + this.mdvMap.config.get('cursorMove') + '\')';
			else
				this.mdvMap.mapper.style.cursor = '-moz-grabbing';
		}
		else
			this.mdvMap.mapper.style.cursor = 'auto';

		var mX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
		var mY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

	    var tl = new MDVPoint(parseInt(this.mdvMap.mapper.style.left), parseInt(this.mdvMap.mapper.style.top));

		var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.currentZoomLevelIndex);
		var pxWidthAll          = parseInt(zoomLevel.get('tileSizeX')) * parseInt(zoomLevel.get('numberOfTilesX'));
		var realToPxRatioWidth  = parseInt(zoomLevel.get('realWidth')) / pxWidthAll;
		var pxHeightAll         = parseInt(zoomLevel.get('tileSizeY')) * parseInt(zoomLevel.get('numberOfTilesY'));
		var realToPxRatioHeight = parseInt(zoomLevel.get('realHeight')) / pxHeightAll;

		var realOffset = new MDVPoint(((mX - this.mouseLast.x) * realToPxRatioWidth),
			(mY - this.mouseLast.y) * realToPxRatioHeight);

		var newCentre = new MDVCoordinates(this.mdvMap.config.get('mapName'), this.mdvMap.real.x - realOffset.x, this.mdvMap.real.y - realOffset.y);

		this.mdvMap.setCentre(newCentre);

		// Check if coordinates were applied to the map. It might be the case that the boundaries were reached.
		if (this.mdvMap.getCentre().x == newCentre.x) {
		    this.mdvMap.mapper.style.left = (tl.x + (mX - this.mouseLast.x)) + 'px';
		}
		if (this.mdvMap.getCentre().y == newCentre.y) {
		    this.mdvMap.mapper.style.top  = (tl.y + (mY - this.mouseLast.y)) + 'px';
		}

		this.mouseLast.x = mX;
		this.mouseLast.y = mY;

		this.mdvMap._checkWrap();
		return false;
	}
	return true;
};

/**
 * MDVMapCrosshair
 * @param {Object} mdvMap
 */
 function MDVMapCrosshair(mdvMap) {
 	if (!mdvMap)
 		return;

	// Name of gadget
 	this.name = 'MapCrosshair';
 	// Reference to mdvMap object
 	this.mdvMap = mdvMap;

 	this.mdvMap.registerGadget(this);

	// Inherit from MDVGadgetBase
    for (var method in MDVGadgetBase.prototype) {

        if (!MDVMapCrosshair.prototype[method])
            MDVMapCrosshair.prototype[method] = MDVGadgetBase.prototype[method];

    }

    this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED, this, this.execute);
 }

 MDVMapCrosshair.prototype.execute = function() {
 	if (this.mdvMap.config.get('crosshair')) {
 		var crosshair = this.mdvMap.config.get('crosshair');

 		var vpMapper = this.mdvMap.mapper;

 		if (!document.getElementById('crosshairLayer')) {
			var div = document.createElement('div');
				div.id = 'crosshairLayer';
	 			div.style.position = 'absolute';
	 			div.style.top  = (this.mdvMap.viewportHeight) / 2 - parseInt(vpMapper.style.top);
	 			div.style.left = (this.mdvMap.viewportWidth) / 2 - parseInt(vpMapper.style.left);
	 			div.style.zIndex = 10;

	 		var img = new Image();
	 			img.src = crosshair;

	 			div.appendChild(img);

	 		this.mdvMap.mapper.appendChild(div);
 		} else {
 			var div = document.getElementById('crosshairLayer');
			if (div) {
	 			div.style.position = 'absolute';
	 			div.style.top  = (this.mdvMap.viewportHeight) / 2 - parseInt(vpMapper.style.top) + 'px';
	 			div.style.left = (this.mdvMap.viewportWidth) / 2 - parseInt(vpMapper.style.left) + 'px';
	 			div.style.zIndex = 10;
			}
 		}

 	}
 };

 /**
  * MDVMapEFAInfo
  * @param {object} mdvMap
  */
  function MDVMapEFAInfo(mdvMap) {
  	// Reference to MDVMap
  	this.mdvMap = mdvMap;

  	// Gadget name
  	this.name = 'MapEFAInfo';

  	// Stop Layer
  	this.stops = null;

  	// POI Layer
  	this.poi = null;

  	// Recent Centre Coords
  	this.centre = null;

  	this.lastCentre = null;
	this.lastZoomLevelIdx = null;

  	// Pre-fetch stop images
  	this.stopImg = new Image();
  	this.stopImg.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot1Img = new Image();
  	this.mot1Img.src = '/ib/site/elements/efa/ajaxmap/syUBahn.gif';

  	this.mot2Img = new Image();
  	this.mot2Img.src = '/ib/site/elements/efa/ajaxmap/sySBahn.gif';

  	this.mot3Img = new Image();
  	this.mot3Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot4Img = new Image();
  	this.mot4Img.src = '/ib/site/elements/efa/ajaxmap/syTram.gif';

  	this.mot5Img = new Image();
  	this.mot5Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot6Img = new Image();
  	this.mot6Img.src = '/ib/site/elements/efa/ajaxmap/syRBahn.gif';

  	this.mot7Img = new Image();
  	this.mot7Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot8Img = new Image();
  	this.mot8Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot9Img = new Image();
  	this.mot9Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot10Img = new Image();
  	this.mot10Img.src = '/ib/site/elements/efa/ajaxmap/mot10.gif';

  	this.mot11Img = new Image();
  	this.mot11Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.mot12Img = new Image();
  	this.mot12Img.src = '/ib/site/elements/efa/ajaxmap/Haltestelle.gif';

  	this.poiImg   = new Image();
  	this.poiImg.src = '/ib/site/elements/efa/ajaxmap/pin.gif';

	// Inherit from MDVGadgetBase
    for (var method in MDVGadgetBase.prototype) {

        if (!MDVMapEFAInfo.prototype[method])
            MDVMapEFAInfo.prototype[method] = MDVGadgetBase.prototype[method];

    }

 	// Register Gadget at MDVMap
 	this.mdvMap.registerGadget(this);

 	this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED, this, this.execute);
 	this.mdvMap.events.registerEvent(MDVEvent_AJAX_CALLBACK, this, this.processPins);
  }

  MDVMapEFAInfo.prototype.createLayers = function() {
  	if (!this.poi) {
  		this.poi = this.mdvMap.createLayer('efa_poi');
  		this.poi.setZIndex(1);
  		this.mdvMap.addLayer(this.poi);
  	}

  	if (!this.stops) {
  		this.stops = this.mdvMap.createLayer('efa_stops');
  		this.stops.setZIndex(2);
  		this.mdvMap.addLayer(this.stops);
  	}
  };

  MDVMapEFAInfo.prototype.execute = function() {
  	// Create Layer
 	this.createLayers();

	var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex());
	var showStops = zoomLevel.get('showSTOP') == "true" ? true : false;
	var showPOI   = zoomLevel.get('showPOI') == "true" ? true : false;

  	if (showStops || showPOI) {
  		this.fetchPins();
  	} else {
  		this.stops.removeAll();
  		this.poi.removeAll();
  	}
  };

  MDVMapEFAInfo.prototype.processPins = function(id, gadName, request) {
	var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex());
	var showStops = zoomLevel.get('showSTOP') == "true" ? true : false;
	var showPOI   = zoomLevel.get('showPOI') == "true" ? true : false;

  	var pins  		= request.responseXML.getElementsByTagName('itdPinElem');
  	var mapRequest 	= request.responseXML.getElementsByTagName('itdMapRequest');

 	this.stops.removeAll();
 	this.poi.removeAll();
	

	if (mapRequest && mapRequest.length > 0) {
		var reqCoord = new MDVCoordinates(mapRequest[0].getAttribute('mapName'), mapRequest[0].getAttribute('xCenterReal'), mapRequest[0].getAttribute('yCenterReal'));

		if (!reqCoord.equals(this.mdvMap.getCentre())) {
			return false;
		}

	}

 	var updateStops = false;
 	var updatePOI 	= false;
	
	if (pins.length <= 0 || mapRequest.length <= 0) {
		this.mdvMap.events.triggerEvent(MDVEvent_ERROR, 'MDVMap wasn\'t able to get pins from map request.');
		return false;
	}

	for(var i=pins.length-1; i>=0; i--) {
		var pinName = pins[i].getAttribute('desc');
		var	pinId	= pins[i].getAttribute('id');
		var	pinType	= pins[i].getAttribute('type');
		var	pinOmc	= pins[i].getAttribute('omc');

		var tmpImg  = new Image();

/*
		var sMeans	= pins[i].getElementsByTagName('genAttrElem');
		if (sMeans.length > 0) {
			var nodeValue = '';

			for (var m=0; m < sMeans.length; m++) {
				var tmpNode = sMeans[m];

				if (tmpNode.nodeType != 1 || !tmpNode.firstChild)
					continue;

				while (tmpNode) {
					if (tmpNode.firstChild && tmpNode.firstChild.firstChild && tmpNode.firstChild.firstChild.nodeValue == 'STOP_MAJOR_MEANS' && tmpNode.firstChild.nextSibling && tmpNode.firstChild.nextSibling.firstChild) {
						nodeValue = tmpNode.firstChild.nextSibling.firstChild.nodeValue;
						break;
					}
					tmpNode = tmpNode.nextSibling;
				}
			}
*/
		var nodeValue = pins[i].getAttribute('mot');
		if(typeof(nodeValue) != "undefined" && nodeValue != null) {
			// Choose correspondig MOT
			switch (parseInt(nodeValue)) {
				case 1:
					tmpImg.src = this.mot1Img.src;
				break;

				case 2:
					tmpImg.src = this.mot2Img.src;
				break;

				case 3:
					tmpImg.src = this.mot3Img.src;
				break;

				case 4:
					tmpImg.src = this.mot4Img.src;
				break;

				case 5:
					tmpImg.src = this.mot5Img.src;
				break;

				case 6:
					tmpImg.src = this.mot6Img.src;
				break;

				case 7:
					tmpImg.src = this.mot7Img.src;
				break;

				case 8:
					tmpImg.src = this.mot8Img.src;
				break;

				case 9:
					tmpImg.src = this.mot9Img.src;
				break;

				case 10:
					tmpImg.src = this.mot10Img.src;
				break;

				case 11:
					tmpImg.src = this.mot11Img.src;
				break;

				case 12:
					tmpImg.src = this.mot12Img.src;
				break;

				default:
					tmpImg.src = this.stopImg.src;
				break;
			}
		} else {
			if (pinType.toUpperCase() == 'POI')
				tmpImg.src = this.poiImg.src;
			else
				tmpImg.src = this.stopImg.src;
		}

		var coords = new MDVCoordinates(mapRequest[0].getAttribute('mapName'),
			parseInt(pins[i].firstChild.getAttribute('x')),
			parseInt(pins[i].firstChild.getAttribute('y')));

		var mapPin = this.mdvMap.createMarker(coords, 0.5, tmpImg.src);
		mapPin.objectId = { type: pinType, desc: pinName, id: pinId, omc: pinOmc, marker: mapPin };
		switch (pinType) {
			case 'stop':
				var mapPinTitle = this.mdvMap.createToolTip(pinName);
				mapPin.setToolTip(mapPinTitle, false);
				mapPinTitle.objectId = pinId;
				// roccas hook for dm
				mapPinTitle.dynamicData = { method: roccas_DMToolTipRequest, parameters: { stopId: pinId } };
			break;
			case 'poi':
				var content = "<div style=\"padding:3px 5px 5px 5px\">" + pinName + "</div>";
				content += "<div class=\"button_context\" style=\"padding:10px 5px 3px 5px;\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>";
				content += "Klicken Sie, um diesen<br>wichtigen Punkt auszuw&auml;hlen.</td></tr></table></div>";
				var mapPinTitle = this.mdvMap.createToolTip(content);
				mapPin.setToolTip(mapPinTitle, false);
			break;
		}

		switch (pinType) {
			case 'poi':
				// Add marker but don't perform update (false)
				if (showPOI) {
					this.poi.addMarker(mapPin, false);
				 	updatePOI 	= true;
				}
				break;
			default:
				// Add marker but don't perform update (false)
				if (showStops) {
					this.stops.addMarker(mapPin, false);
				 	updateStops = true;
				}
				break;
		}
	}

	// Check whether we need to update the marker layers
	if (updateStops)
		this.stops.update();
	if (updatePOI)
		this.poi.update();

	this.centre = new MDVCoordinates(this.mdvMap.getCentre().mapName, this.mdvMap.getCentre().x, this.mdvMap.getCentre().y);

	return true;
  };

  MDVMapEFAInfo.prototype.fetchPins = function() {
	// Get Pins for current position & zoom level.
  	if (this.mdvMap.config.get('efaURL')) {

  		var host   = this.mdvMap.config.get('efaURL');
  		var centre = this.mdvMap.getCentre();
  		var zoomLevel = this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex());

  		var zoomLevelIdx = this.mdvMap.config.getZoomLevelIndex();
		if (this.lastCentre && (this.lastCentre.x == centre.x && this.lastCentre.y == centre.y && this.lastZoomLevelIdx == zoomLevelIdx)) {
			this.centre = new MDVCoordinates(this.mdvMap.getCentre().mapName, this.mdvMap.getCentre().x, this.mdvMap.getCentre().y);
			this.lastZoomLevelIdx = zoomLevelIdx;
			//return;
		}
		this.lastCentre = new MDVCoordinates(this.mdvMap.getCentre().mapName, this.mdvMap.getCentre().x, this.mdvMap.getCentre().y);
		this.lastZoomLevelIdx = zoomLevelIdx;


  		var showStops = zoomLevel.get('showSTOP') == "true" ? 1 : 0;
  		var showPOI   = zoomLevel.get('showPOI') == "true" ? 1 : 0;

		var _params = new Array({ xCenterReal: Math.floor(centre.x + 0.5), yCenterReal: Math.floor(centre.y + 0.5), mapName: centre.mapName,
			pinTypePOI: showPOI, pinTypeStop: showStops, createImage: '0', realHeight: this.mdvMap.viewportRealHeight,
			realWidth: this.mdvMap.viewportRealWidth, screenWidth: this.mdvMap.viewportWidth,	screenHeight: this.mdvMap.viewportHeight,
			command: 'mapData', hideBannerInfo: '1', itdLPxx_mdvMapName: 'mdvMap_' + this.mdvMap.getName(),
			zoomLevel: this.mdvMap.config.getZoomLevelIndex()});

		    _params = $H(_params[0]);
		    _params = _params.toQueryString();
		var _ajax = new Ajax.Request(host, {
			method: 'post', parameters: _params, onComplete: MDVMapEFAInfo_onAjaxComplete
		});
  	}
  };

  MDVMapEFAInfo.prototype.onmouseup = function(e) {
  	var centre = this.mdvMap.getCentre();

  	if (this.centre && (this.centre.x != centre.x || this.centre.y != centre.y)) {
		//this.stops.removeAll();
		//this.poi.removeAll();
  	}

 	return true;
  }

 function MDVMapEFAInfo_onAjaxComplete(request) {
 	if (request && request.responseXML)
 	{
	 	var itdLPs = request.responseXML.getElementsByTagName("itdLayoutParam");
	 	for (var i = 0; i < itdLPs.length; i++) {
			if (itdLPs[i].getAttribute('name') == 'mdvMapName') {
				if (document.mdvMaps[itdLPs[i].getAttribute('value')])
					document.mdvMaps[itdLPs[i].getAttribute('value')].events.triggerEvent(MDVEvent_AJAX_CALLBACK, 'MapEFAInfo', request);
					return;
			}
		}
	}
 }

  /**
    * MDVMapContextMenu
    * @param {object} mdvMap
    * context menu functionality: show and hide the menu
    */
   function MDVMapContextMenu(mdvMap, contMenu) {
   	if (!mdvMap)
   		return;

  	// Name of gadget
   	this.name = 'MapContextMenu';
   	// Reference to mdvMap object
   	this.mdvMap = mdvMap;

   	this.mdvMap.registerGadget(this);
   	this.mdvMap.events.registerEvent(MDVEvent_ZOOM_CHANGED, this, this.zoomLevelChange);

   	this.contextMenu = contMenu; // the context menu
   	// ueber alle menue-eintraege drueberlaufen und onmouseup auf menue schliessen setzen
   	/*for(var i = 0; i < this.contextMenu.div.childNodes.length; i++){
   		if (this.contextMenu.div.childNodes[i]) {
   			this.contextMenu.div.childNodes[i].onmouseup = this.hideContextMenu;
   		}
   	}*/

   	for(var i = 0; i < this.contextMenu.div.childNodes.length; i++) {
		if (this.contextMenu.div.childNodes[i]) {
			this.contextMenu.div.childNodes[i].mdvMap = this.mdvMap;
		}
	}
    var _clickOnContextMenu = false; // clicked on context menu?

    document.body.contextMenu = this;

   	// hide context menu if clicked outside the map
   	this.contextMenu.div.onmousedown = function() { _clickOnContextMenu = true; };
   	document.body.onmousedown = function (e) {
   		e = e ? e : window.event;

 			if (!_clickOnContextMenu)
 				this.contextMenu.contextMenu.div.style.display = 'none';
      _clickOnContextMenu = false;
   	};

   	// surpress standard context menu for context menu
   	this.contextMenu.div.oncontextmenu = function() { return false; };

  	// Inherit from MDVGadgetBase
    for (var method in MDVGadgetBase.prototype) {

    if (!MDVMapContextMenu.prototype[method])
      MDVMapContextMenu.prototype[method] = MDVGadgetBase.prototype[method];
    }
   }

   // show context menu
   MDVMapContextMenu.prototype.oncontextmenu = function(e) {
   	e = e ? e : window.event;

   		var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
 		var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
 		var x = e.clientX + scrollLeft;
 		var y = e.clientY + scrollTop;

	    var mX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
	    var mY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

	    var offsetL = 0;
	    var offsetT = 0;

	    var obj = this.mdvMap.viewport;

	    while(obj) {
	    	offsetL += obj.offsetLeft;
	    	offsetT += obj.offsetTop;

	    	obj = obj.offsetParent;
	    }

	    mX = mX - offsetL - 3;
	    mY = mY - offsetT - 3;


 		this.contextMenu.div.style.display= 'none';


// roccas custom context menu
		var mousePoint = new MDVPoint(mX, mY);
		var mouseCoord = this.mdvMap.getCoordinates(mousePoint);
		var params = { createImage: 0, pinTypeStop: 0, pinTypePOI: 0, pinTypeCrossing:1, 
			xCenterReal: mouseCoord.x, yCenterReal: mouseCoord.y,
			mapName: 'NAV4', screenWidth: 50, screenHeight:50, zoomLevel:7};
		params = $H(params).toQueryString();
		var _ajax = new Ajax.Request('/efa9/efa94/roccas/XML_MAP_REQUEST', { method: 'post', asynchronous: false, parameters: params});
		var name = _ajax.transport.responseXML.getElementsByTagName('odvNameElem');
		for (var i=0; i < name.length; i++) {
			if(typeof(name[i].firstChild) != 'undefined' && name[i].firstChild != null) {
				mouseCoord.pointName = name[i].firstChild.nodeValue;
			}
		}
		var place = _ajax.transport.responseXML.getElementsByTagName('odvPlaceElem');
		mouseCoord.pointOMC = 0;
		for (var i=0; i < place.length; i++) {
			if(typeof(place[i].firstChild) != 'undefined' && place[i].firstChild != null) {
				mouseCoord.pointOMC = place[i].getAttribute('omc');
			}
		}
		if(typeof(mouseCoord.pointName) == 'undefined' || mouseCoord.pointName == null || mouseCoord.pointName == '') {
			return false;
		}
// end roccas custom context menu


 		this.contextMenu.div.style.left = x + 'px';
 		this.contextMenu.div.style.top = y + 'px';
 		this.contextMenu.div.style.display= 'block';

 		this.mdvMap.events.triggerEvent(MDVEvent_CONTEXT_MENU, true, mouseCoord);

   	return false;
   };


   // hide context menu
   MDVMapContextMenu.prototype.hideContextMenu = function() {
   	this.contextMenu.div.style.display = 'none';
 		this.mdvMap.events.triggerEvent(MDVEvent_CONTEXT_MENU, false, null);
   }

   // hide context menu
   MDVMapContextMenu.prototype.onmousedown = function(e) {
  	e = e ? e : window.event;

    // if another than right button (2) is pressed the context menu is closed.
 		if(e == null || e.button != 2) {
 			this.hideContextMenu();
 		}
 		this.stopEvent(e);
 		return false;
   };


 	 // hide menu if zoom level is changed
	 MDVMapContextMenu.prototype.zoomLevelChange = function(id, message, zoomLevelIndex) {
	   	this.onmousedown(null);
   };

 	/**
    * MDVMapMenu
    * @param {text} id
    * @param {Array} menuItems
    * creates a menu
    */
    function MDVMapMenu(menuItems) {
    	this.menuItems = menuItems;	// items of the menu

		var menuoutput = document.createElement("div");
		menuoutput.className = "output";
		document.body.appendChild(menuoutput);

		var menu = document.createElement("div");
		menu.className = "mapContextMenu";
		menuoutput.appendChild(menu);

		// set cursor
		menu.style.cursor = 'default';

		for(var i=0; i< this.menuItems.length; i++){
			// item
			if(this.menuItems[i].func){
				var item = document.createElement("div");
				item.className = "mapContextMenuItem";
				item.onmouseover = function() { this.className='mapContextMenuItem_active'; menu.style.cursor='pointer'; };
				item.onmouseout = function() { this.className= 'mapContextMenuItem'; menu.style.cursor='default';};
				item.onclick = this.menuItems[i].func;
				item.onmouseup = hideMenu; // uebergangsloesung
				//var itemDescription = document.createTextNode(" " + this.menuItems[i].description + " ");
				//item.appendChild(itemDescription);
				var content = "<div style=\"float:right\"><img src=\"/ib/site/elements/efa/buttons/bnSend_a.gif\" width=\"11\" height=\"11\" alt=\"\" style=\"vertical-align:bottom;\"></div>";
				content += this.menuItems[i].description;
				content += "<div style=\"clear:both\"></div>";
				item.innerHTML = content;
				menu.appendChild(item);
			}
			// separating element
			else {
				var item = document.createElement("hr");
				menu.appendChild(item);
			}
		}

		function hideMenu() {
			menu.style.display = 'none';
		}

		this.div = menu;
	}

  /**
		* MDVMapMenuItem
		* @param {text} description
		* @param {Object} func (optional)
		* creates items of a menu
		*/
   	function MDVMapMenuItem(description, func) {
    	this.description = description;
    	if(func){
    		this.func = func;
    	}
    }

  /**
  * MDVMapControl
  * @param {object} mdvMap
  */
  function MDVMapControl(mdvMap) {
 	if (!mdvMap)
 		return;

	// Name of gadget
 	this.name = 'MapControl';
 	// Reference to mdvMap object
 	this.mdvMap = mdvMap;

	// Store origin values
	this.origin = null;
  	this.zoomLevel = null;

 	// Images
 	this.images = new Array();
 	this.images['top_normal'] = new Image();
 	this.images['top_hover'] = new Image();
 	this.images['left_normal'] = new Image();
 	this.images['left_hover'] = new Image();
 	this.images['centre_normal'] = new Image();
 	this.images['centre_hover'] = new Image();
 	this.images['right_normal'] = new Image();
 	this.images['right_hover'] = new Image();
 	this.images['bottom_normal'] = new Image();
 	this.images['bottom_hover'] = new Image();
 	this.images['zoomIn_normal'] = new Image();
 	this.images['zoomIn_hover'] = new Image();
 	this.images['zoomOut_normal'] = new Image();
 	this.images['zoomOut_hover'] = new Image();
 	this.images['zoomLevel_normal'] = new Image();
 	this.images['zoomLevel_hover'] = new Image();
 	this.images['zoomLevel_active'] = new Image();
 	this.images['transparent'] = new Image();
 	this.images['spacer'] = new Image();

 	// Map Control Bounding Box
 	this.mapControl = null;

 	// Container for Arrows
 	this.arrowContainer = null;
 	// container for Zoom Levels
 	this.zoomContainer = null;

 	this.mdvMap.registerGadget(this);

	// Inherit from MDVGadgetBase
    for (var method in MDVGadgetBase.prototype) {

        if (!MDVMapControl.prototype[method])
            MDVMapControl.prototype[method] = MDVGadgetBase.prototype[method];

    }

    this.mdvMap.events.registerEvent(MDVEvent_INITIALISED, this, this.execute);
    this.mdvMap.events.registerEvent(MDVEvent_ZOOM_CHANGED, this, this.update);
  }

  MDVMapControl.prototype.preloadImgs = function () {

  	var imgPath = '/ib/site/elements/efa/ajaxmap/MDVMapControl/';

 	this.images['top_normal'].src 			= imgPath + 'topNormal.gif';
 	this.images['top_normal'].alt			= "Go north";
 	this.images['top_normal'].title			= this.images['top_normal'].alt;

 	this.images['top_hover'].src 			= imgPath + 'topHover.gif';
 	this.images['top_hover'].alt 			= this.images['top_normal'].alt;
 	this.images['top_hover'].title 			= this.images['top_normal'].alt;

 	this.images['left_normal'].src 			= imgPath + 'leftNormal.gif';
 	this.images['left_normal'].alt			= "Go west";
  	this.images['left_normal'].title		= this.images['left_normal'].alt;

 	this.images['left_hover'].src 			= imgPath + 'leftHover.gif';
 	this.images['left_hover'].alt			= this.images['left_normal'].alt;
 	this.images['left_hover'].title			= this.images['left_normal'].alt;

 	this.images['centre_normal'].src 		= imgPath + 'centreNormal.gif';
 	this.images['centre_normal'].alt		= "Last result";
 	this.images['centre_normal'].title		= this.images['centre_normal'].alt;

 	this.images['centre_hover'].src 		= imgPath + 'centreHover.gif';
 	this.images['centre_hover'].alt			= this.images['centre_normal'].alt;
 	this.images['centre_hover'].title		= this.images['centre_normal'].alt;

 	this.images['right_normal'].src 		= imgPath + 'rightNormal.gif';
 	this.images['right_normal'].alt			= "Go east";
 	this.images['right_normal'].title		= this.images['right_normal'].alt;

 	this.images['right_hover'].src 			= imgPath + 'rightHover.gif';
	this.images['right_hover'].alt			= this.images['right_normal'].alt;
	this.images['right_hover'].title		= this.images['right_normal'].alt;

 	this.images['bottom_normal'].src 		= imgPath + 'bottomNormal.gif';
 	this.images['bottom_normal'].alt 		= "Go south";
 	this.images['bottom_normal'].title		= this.images['bottom_normal'].alt;

 	this.images['bottom_hover'].src 		= imgPath + 'bottomHover.gif';
 	this.images['bottom_hover'].alt			= this.images['bottom_normal'].alt;
 	this.images['bottom_hover'].title		= this.images['bottom_normal'].alt;

 	this.images['zoomIn_normal'].src 		= imgPath + 'zoomInNormal.gif';
  	this.images['zoomIn_normal'].alt		= "Zoom in";
  	this.images['zoomIn_normal'].title		= this.images['zoomIn_normal'].alt;

 	this.images['zoomIn_hover'].src 		= imgPath + 'zoomInHover.gif';
 	this.images['zoomIn_hover'].alt			= this.images['zoomIn_normal'].alt;
 	this.images['zoomIn_hover'].title		= this.images['zoomIn_normal'].alt;

 	this.images['zoomOut_normal'].src 		= imgPath + 'zoomOutNormal.gif';
  	this.images['zoomOut_normal'].alt		= "Zoom out";
  	this.images['zoomOut_normal'].title		= this.images['zoomOut_normal'].alt;

 	this.images['zoomOut_hover'].src 		= imgPath + 'zoomOutHover.gif';
  	this.images['zoomOut_hover'].alt		= this.images['zoomOut_normal'].alt;
  	this.images['zoomOut_hover'].title		= this.images['zoomOut_normal'].alt;

	for(var i=0; i<this.mdvMap.config.getZoomLevels().length; i++) {
		this.images['zoomLevel_normal' + i] = new Image();
		this.images['zoomLevel_hover' + i] = new Image();
		this.images['zoomLevel_active' + i] = new Image();
		this.images['zoomLevel_normal' + i].src 	= imgPath + 'bnZoom_' + i + '_a.gif';
		this.images['zoomLevel_active' + i].src 	= imgPath + 'bnZoom_' + i + '_s.gif';
		this.images['zoomLevel_hover' + i].src 	= imgPath + 'bnZoom_' + i + '_o.gif';
	}
	
  	this.images['transparent'].src 			= imgPath + 'transparent.gif';

  	this.images['spacer'].src 				= imgPath + 'spacer.gif';
  };

  MDVMapControl.prototype.createDiv = function () {
  	var newDiv = document.createElement('div');
  	return newDiv;
  };

  MDVMapControl.prototype.execute = function () {
  	// Fetch Images
  	this.preloadImgs();

  	// Store Origin Coords and ZoomLevel
	this.origin = new MDVCoordinates(this.mdvMap.config.get('mapName'),
  	parseInt(this.mdvMap.config.get('xCenterReal')),
  	parseInt(this.mdvMap.config.get('yCenterReal')));

  	this.zoomLevel = this.mdvMap.config.get('defaultScale');

  	// Bounding Box
/*
  	this.mapControl = this.createDiv();
  	this.mapControl.className = 'MDVMapControl';

  	this.mdvMap.viewport.appendChild(this.mapControl);
*/
	this.mapControl = document.getElementById("mapControl_" + this.mdvMap.name.substring(7) + "_Zoom"); // roccas Navigation

  	// Container for Arrows
  	this.arrowContainer = this.createDiv();
  	// Container for Zoom Levels
  	this.zoomContainer = this.createDiv();
  	this.zoomContainer.className = 'MDVMapControl_ZoomLevels';

  	// List of all Zoom Levels
  	this.zoomLevels = new Array();

  	this.mapControl.appendChild(this.arrowContainer);
  	this.mapControl.appendChild(this.zoomContainer);

  	// Populate
  	this.populateContainers();

  	// Update
  	this.update();
  };

  MDVMapControl.prototype.setZoomLevel = function(zoomLevel) {
  	if (this.mdvMap.config.getZoomLevel(zoomLevel)) {
	  	this.zoomLevel = zoomLevel;
	  	return true;
  	}
  	return false;
  };

  MDVMapControl.prototype.setOriginCoords = function(coord) {
  	if (coord && coord.x && coord.y && coord.mapName) {
  		this.origin = coord;
  		return true;
  	}
  	return false;
  };

  MDVMapControl.prototype.populateContainers = function () {
  	if (!this.arrowContainer || !this.zoomContainer)
  		return false;
/*
  	// Populate Arrow Container
  	var firstRow 	= this.createDiv();
  	var secondRow 	= this.createDiv();
  	var thirdRow	= this.createDiv();

  	this.arrowContainer.appendChild(firstRow);
  	this.arrowContainer.appendChild(secondRow);
  	this.arrowContainer.appendChild(thirdRow);

	// Top Left to Top Right
	var arrow_1_1 = this.createDiv();
		arrow_1_1.className = 'MDVMapControl_Arrow';
		arrowImg_1_1 = this.createImage();
		arrowImg_1_1.src = this.images['transparent'].src;
		arrow_1_1.appendChild(arrowImg_1_1);
	var arrow_2_1 = this.createDiv();
		arrow_2_1.className = 'MDVMapControl_Arrow';
		arrowImg_2_1 = this.createImage();
		arrowImg_2_1.hover = this.images['top_hover'];
		arrowImg_2_1.normal = this.images['top_normal'];
		arrowImg_2_1.alt = this.images['top_normal'].alt;
		arrowImg_2_1.title = this.images['top_normal'].title;
		arrowImg_2_1.onclick = this.goNorth;
		arrowImg_2_1.src = this.images['top_normal'].src;
		arrow_2_1.appendChild(arrowImg_2_1);
	var arrow_3_1 = this.createDiv();
		arrow_3_1.className = 'MDVMapControl_Arrow';
		arrowImg_3_1 = this.createImage();
		arrowImg_3_1.src = this.images['transparent'].src;
		arrow_3_1.appendChild(arrowImg_3_1);

	firstRow.appendChild(arrow_1_1);
	firstRow.appendChild(arrow_2_1);
	firstRow.appendChild(arrow_3_1);

	// Middle Left to Middle Right
	var arrow_1_2 = this.createDiv();
		arrow_1_2.className = 'MDVMapControl_Arrow';
		arrowImg_1_2 = this.createImage();
		arrowImg_1_2.hover = this.images['left_hover'];
		arrowImg_1_2.normal = this.images['left_normal'];
		arrowImg_1_2.alt = this.images['left_normal'].alt;
		arrowImg_1_2.title = this.images['left_normal'].title;
		arrowImg_1_2.onclick = this.goEast;
		arrowImg_1_2.src = this.images['left_normal'].src;
		arrow_1_2.appendChild(arrowImg_1_2);
	var arrow_2_2 = this.createDiv();
		arrow_2_2.className = 'MDVMapControl_Arrow';
		arrowImg_2_2 = this.createImage();
		arrowImg_2_2.hover = this.images['centre_hover'];
		arrowImg_2_2.normal = this.images['centre_normal'];
		arrowImg_2_2.alt = this.images['centre_normal'].alt;
		arrowImg_2_2.title = this.images['centre_normal'].title;
		arrowImg_2_2.onclick = this.goBack;
		arrowImg_2_2.mapControl = this;
		arrowImg_2_2.src = this.images['centre_normal'].src;
		arrow_2_2.appendChild(arrowImg_2_2);
	var arrow_3_2 = this.createDiv();
		arrow_3_2.className = 'MDVMapControl_Arrow';
		arrowImg_3_2 = this.createImage();
		arrowImg_3_2.hover = this.images['right_hover'];
		arrowImg_3_2.normal = this.images['right_normal'];
		arrowImg_3_2.alt = this.images['right_normal'].alt;
		arrowImg_3_2.title = this.images['right_normal'].title;
		arrowImg_3_2.onclick = this.goWest;
		arrowImg_3_2.src = this.images['right_normal'].src;
		arrow_3_2.appendChild(arrowImg_3_2);

  	secondRow.appendChild(arrow_1_2);
  	secondRow.appendChild(arrow_2_2);
  	secondRow.appendChild(arrow_3_2);

  	// Lower Left to Lower Right
  	var arrow_1_3 = this.createDiv();
  		arrow_1_3.className = 'MDVMapControl_Arrow';
  		arrowImg_1_3 = this.createImage();
  		arrowImg_1_3.src = this.images['transparent'].src;
  		arrow_1_3.appendChild(arrowImg_1_3);
  	var arrow_2_3 = this.createDiv();
  		arrow_2_3.className = 'MDVMapControl_Arrow';
  		arrowImg_2_3 = this.createImage();
  		arrowImg_2_3.hover = this.images['bottom_hover'];
  		arrowImg_2_3.normal = this.images['bottom_normal'];
  		arrowImg_2_3.alt = this.images['bottom_normal'].alt;
  		arrowImg_2_3.title = this.images['bottom_normal'].title;
  		arrowImg_2_3.onclick = this.goSouth;
  		arrowImg_2_3.src = this.images['bottom_normal'].src;
  		arrow_2_3.appendChild(arrowImg_2_3);
  	var arrow_3_3 = this.createDiv();
  		arrow_3_3.className = 'MDVMapControl_Arrow';
  		arrowImg_3_3 = this.createImage();
  		arrowImg_3_3.src = this.images['transparent'].src;
  		arrow_3_3.appendChild(arrowImg_3_3);

  	thirdRow.appendChild(arrow_1_3);
  	thirdRow.appendChild(arrow_2_3);
  	thirdRow.appendChild(arrow_3_3);

  	// Spacer
  	var arrow_spacer = this.createDiv();
  		arrow_spacer.className = 'MDVMapControl_Arrow';
  		arrowImg_spacer = this.createImage();
  		arrowImg_spacer.style.height = "20px";
  		arrowImg_spacer.src = this.images['spacer'].src;
  		arrow_spacer.appendChild(arrowImg_spacer);
  		this.zoomContainer.appendChild(arrow_spacer);

  	// Populate Zoom Level Container
  	var zoomIn = this.createDiv();
  		zoomInImg = this.createImage();
  		zoomInImg.hover = this.images['zoomIn_hover'];
  		zoomInImg.normal = this.images['zoomIn_normal'];
  		zoomInImg.alt = this.images['zoomIn_normal'].alt;
  		zoomInImg.title = this.images['zoomIn_normal'].title;
  		zoomInImg.src = this.images['zoomIn_normal'].src;
  		zoomInImg.onclick = this.zoomIn;
  		zoomIn.appendChild(zoomInImg);
  		this.zoomContainer.appendChild(zoomIn);

  	// Spacer
  	var arrow_spacer = this.createDiv();
  		arrow_spacer.className = 'MDVMapControl_Arrow';
  		arrowImg_spacer = this.createImage();
  		arrowImg_spacer.height = 10;
  		arrowImg_spacer.src = this.images['spacer'].src;
  		arrow_spacer.appendChild(arrowImg_spacer);
  		this.zoomContainer.appendChild(arrow_spacer);
*/

  	// Iterate for every Zoom Level
  	var zoomLevels = 0;
  	var zoomLevelArr = this.mdvMap.config.getZoomLevels();
  	if (zoomLevelArr)
  		zoomLevels = zoomLevelArr.length;

  	for (var z = 0; z < zoomLevels; z++) {
  		var level = zoomLevelArr[z];
  		if (level) {
//	  		var tmpZL = this.createDiv();
//	  			tmpZL.className = 'MDVMapControl_ZoomLevel';
	  			tmpZLImg = this.createImage();
	  			tmpZLImg.level = level.level;
	  			tmpZLImg.hover = this.images['zoomLevel_hover' + z];
	  			tmpZLImg.normal = this.images['zoomLevel_normal' + z];
	  			tmpZLImg.src = this.images['zoomLevel_normal' + z].src;
	  			tmpZLImg.alt = "Massstab 1:" + level.getScale();
	  			tmpZLImg.title = tmpZLImg.alt;
	  			tmpZLImg.onclick = MDVMapControl_onclick;
//	  			tmpZL.appendChild(tmpZLImg);
	  			this.zoomContainer.appendChild(tmpZLImg);
	  			this.zoomLevels.push(tmpZLImg);
  		}
  	}

/*
  	var zoomOut = this.createDiv();
  		zoomOutImg = this.createImage();
  		zoomOutImg.hover = this.images['zoomOut_hover'];
  		zoomOutImg.normal = this.images['zoomOut_normal'];
  		zoomOutImg.alt = this.images['zoomOut_normal'].alt;
  		zoomOutImg.title = this.images['zoomOut_normal'].title;
  		zoomOutImg.src = this.images['zoomOut_normal'].src;
  		zoomOutImg.onclick = this.zoomOut;
  		zoomOut.appendChild(zoomOutImg);
  		this.zoomContainer.appendChild(zoomOut);
*/
  	return true;
  };

  MDVMapControl.prototype.createImage = function() {
  	var newImage = new Image();
  		newImage.mdvMap = this.mdvMap;
  		newImage.hover 	= null;
  		newImage.normal = null;
  		newImage.onmouseover = MDVMapControl_onmouseover;
  		newImage.onmouseout  = MDVMapControl_onmouseout;
  		newImage.onclick 	 = MDVMapControl_onclick;
  		newImage.ondragstart = new Function([], 'var e=e?e:event;e.cancelBubble=true;e.returnValue=false;return false;');
  	return newImage;
  };

  MDVMapControl.prototype.update = function() {
  	if (!this.zoomLevels)
  		return false;

  	var currentZoomLevel = this.mdvMap.config.getZoomLevelIndex();

  	var len = this.zoomLevels.length;

  	for (var i=0; i < len; i++) {
  		if (this.zoomLevels[i].level == currentZoomLevel) {
  			this.zoomLevels[i].src = this.images['zoomLevel_active' + i].src;
  			this.zoomLevels[i].hover = this.images['zoomLevel_active' + i];
  			this.zoomLevels[i].normal = this.images['zoomLevel_active' + i];
  		} else {
  			this.zoomLevels[i].src = this.images['zoomLevel_normal' + i].src;
  			this.zoomLevels[i].hover = this.images['zoomLevel_hover' + i];
  			this.zoomLevels[i].normal = this.images['zoomLevel_normal' + i];
  		}
  	}

  	return true;
  };

  MDVMapControl.prototype.zoomIn = function() {
	var zoomLevel = this.mdvMap.config.getZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())+1);
	if (zoomLevel != null) {
  		this.mdvMap.setZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())+1);
  		this.mdvMap.update();
	}

  	return true;
  };

  MDVMapControl.prototype.zoomOut = function() {
	var zoomLevel = this.mdvMap.config.getZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())-1);
	if (zoomLevel != null) {
  		this.mdvMap.setZoomLevel(parseInt(this.mdvMap.config.getZoomLevelIndex())-1);
  		this.mdvMap.update();
	}

  	return true;
  };

  MDVMapControl.prototype.goEast = function() {
  	var realWidth = this.mdvMap.viewportRealWidth * 0.6;

  	var newCoords = new MDVCoordinates(this.mdvMap.getCentre().mapName,
  		this.mdvMap.getCentre().x,
  		this.mdvMap.getCentre().y);

  	newCoords.x = newCoords.x - Math.floor(realWidth + 0.5);

  	this.mdvMap.setCentre(newCoords);
  	this.mdvMap.update();

  	return true;
  };

  MDVMapControl.prototype.goWest = function() {
  	var realWidth = this.mdvMap.viewportRealWidth * 0.6;

  	var newCoords = new MDVCoordinates(this.mdvMap.getCentre().mapName,
  		this.mdvMap.getCentre().x,
  		this.mdvMap.getCentre().y);

  	newCoords.x = newCoords.x + Math.floor(realWidth + 0.5);

  	this.mdvMap.setCentre(newCoords);
  	this.mdvMap.update();

  	return true;
  };

  MDVMapControl.prototype.goNorth = function() {
  	var realHeight = this.mdvMap.viewportRealHeight * 0.6;

  	var newCoords = new MDVCoordinates(this.mdvMap.getCentre().mapName,
  		this.mdvMap.getCentre().x,
  		this.mdvMap.getCentre().y);

  	newCoords.y = newCoords.y - Math.floor(realHeight + 0.5);

  	this.mdvMap.setCentre(newCoords);
  	this.mdvMap.update();

  	return true;
  };

  MDVMapControl.prototype.goSouth = function() {
  	var realHeight = this.mdvMap.viewportRealHeight * 0.6;

  	var newCoords = new MDVCoordinates(this.mdvMap.getCentre().mapName,
  		this.mdvMap.getCentre().x,
  		this.mdvMap.getCentre().y);

  	newCoords.y = newCoords.y + Math.floor(realHeight + 0.5);

  	this.mdvMap.setCentre(newCoords);
  	this.mdvMap.update();

  	return true;
  };

  MDVMapControl.prototype.goBack = function() {
	this.mdvMap.setZoomLevel(this.mapControl.zoomLevel);
	this.mdvMap.setCentre(this.mapControl.origin);
	this.mdvMap.update();
  };

  function MDVMapControl_onmouseover(e) {
	if (this.hover && this.hover.src) {
	  	this.src = this.hover.src;
	  	this.style.cursor = 'pointer';
	}
  	return true;
  }

  function MDVMapControl_onmouseout(e) {
  	if (this.normal && this.normal.src) {
  		this.src = this.normal.src;
	  	this.style.cursor = 'auto';
  	}
  	return true;
  }

  function MDVMapControl_onclick(e) {
  	if (this.level) {
		var zoomLevel = this.mdvMap.config.getZoomLevel(this.level);
		if (zoomLevel != null) {
	  		this.mdvMap.setZoomLevel(this.level);
	  		this.mdvMap.update();
		}
  	}
  	return true;
  }
