
var MDVEventID=0;var MDVEvent_ERROR=MDVEventID++;var MDVEvent_DEBUG=MDVEventID++;var MDVEvent_WARNING=MDVEventID++;var MDVEvent_INITIALISED=MDVEventID++;var MDVEvent_MAP_INITIALISED=MDVEventID++;var MDVEvent_ZOOM_CHANGED=MDVEventID++;var MDVEvent_CENTRE_CHANGED=MDVEventID++;var MDVEvent_CONTEXT_MENU=MDVEventID++;var MDVEvent_GADGET_REGISTERED=MDVEventID++;var MDVEvent_LAYER_ADDED=MDVEventID++;var MDVEvent_LAYER_UPDATED=MDVEventID++;var MDVEvent_AJAX_CALLBACK=MDVEventID++;var MDVEvent_MOUSE_MOVED=MDVEventID++;var MDVEvent_TOOLTIP=MDVEventID++;var MDVEvent_OBJECT_CLICKED=MDVEventID++;var MDVEvent_ROUTE_TRACE_FINISHED=MDVEventID++;function MDVMap(viewport,name){this.config=null;this.name=name;this.viewport=viewport;this.viewport.mdvMap=this;this.mapTiles=null;this.markerObjects=null;this.markerLayer=null;this.tileRealWidth=-1;this.tileRealHeight=-1;this.tileCountWidth=-1;this.tileCountHeight=-1;this.startTileWidth=-1;this.startTileHeight=-1;this.imgCountWidth=0;this.imgCountHeight=0;this.viewportRealWidth=-1;this.viewportRealHeight=-1;this.tlReal=null;this.tlTileReal=null;this.offset=null;this.wrapOffset=null;this.real=new MDVCoordinates();this.viewport.style.overflow='hidden';this.viewport.style.position='relative';this.viewportHeight=-1;this.viewportWidth=-1;this.state=-1;this.lastImageID=0;this.lastMarkerID=0;this.lastLayerID=0;this.lastToolTipID=0;this.lastPolylineID=0;this.maxFailCount=3;this.transparent=new Image(1,1);this.mapper=null;this.events=new MDVEvents();this.gadgets=new Array();this.layers=new Array();this.renderer=null;this.speed=1;this.stepTime=45;this.stepPx=4.3;this.steps=null;this.moveJobID=null;this.crossHairSrc=new Image();this.crossHair=null;for(var i=0;i<MDVEventID;i++){this.events.addEventID(i);}};MDVMap.prototype.getViewportExtends=function(){return{width:this.viewportWidth,height:this.viewportHeight};};MDVMap.prototype.getViewportRealExtends=function(){return{width:this.viewportRealWidth,height:this.viewportRealHeight};};MDVMap.prototype.getPoint=function(coords){if(coords==null)return null;this._updateMapValues();var zoomLevel=this.config.getZoomLevel(this.config.currentZoomLevelIndex);var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var pxToRealRatioWidth=pxWidthAll/parseInt(zoomLevel.get('realWidth'));var pxHeightAll=parseInt(zoomLevel.get('tileSizeY'))*parseInt(zoomLevel.get('numberOfTilesY'));var pxToRealRatioHeight=pxHeightAll/parseInt(zoomLevel.get('realHeight'));var retPoint=new MDVPoint(Math.floor(0.5+(coords.x-this.tlTileReal.x)*pxToRealRatioWidth),Math.floor(0.5+(coords.y-this.tlTileReal.y)*pxToRealRatioHeight));retPoint.x=retPoint.x-this.wrapOffset.x;retPoint.y=retPoint.y-this.wrapOffset.y;return retPoint;};MDVMap.prototype.getCoordinates=function(point){if(point==null)return null;this._updateMapValues();var zoomLevel=this.config.getZoomLevel(this.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 retCoord=new MDVCoordinates(this.config.get('mapName'),Math.floor(0.5+this.tlReal.x+(point.x*realToPxRatioWidth)),Math.floor(0.5+this.tlReal.y+(point.y*realToPxRatioHeight)));return retCoord;};MDVMap.prototype.createMarker=function(coords,factor,imgSrc){if(imgSrc!='')return new MDVMarker(this,coords,imgSrc,factor);else return null;};MDVMap.prototype.createToolTip=function(innerHTML){return new MDVToolTip(this,innerHTML);};MDVMap.prototype._updateLayers=function(){for(var l=0;l<this.layers.length;l++){this.layers[l].update();};return true;};MDVMap.prototype.addMarker=function(marker){return this.markerLayer.addMarker(marker);};MDVMap.prototype.removeMarker=function(marker){return this.markerLayer.removeMarker(marker);};MDVMap.prototype.addLayer=function(layer){var found=false;for(var l=0;l<this.layers.length;l++){if(this.layers[l].id==layer.id)found=true;};if(!found){this.layers.push(layer);this.events.triggerEvent(MDVEvent_LAYER_ADDED,'MDVMap has added a new layer ('+this.layers[l].name+')',this.layers[l]);this.layers.append=true;layer.update();}};MDVMap.prototype.getLayer=function(name){for(var l=0;l<this.layers.length;l++){if(this.layers[l].name==name)return this.layers[l];};return null;};MDVMap.prototype.getLayers=function(){return this.layers;};MDVMap.prototype.registerGadget=function(gadget){var found=false;for(var g=0;g<this.gadgets.length;g++){if(this.gadgets[g].name==gadget.name)found=true;};if(gadget.name=='GadgetBase')found=true;if(!found){this.gadgets.push(gadget);this.events.triggerEvent(MDVEvent_GADGET_REGISTERED,'MDVMap registered a new gadget ('+gadget.name+')',gadget);}};MDVMap.prototype.getCentre=function(){if(this.real.x>0&&this.real.y>0)return this.real;else return null;};MDVMap.prototype.setCentre=function(centre){if(centre&&(!this.getCentre()||centre.x!=this.getCentre().x||centre.y!=this.getCentre().y)){var ret=false;if(this._checkBoundariesX(centre)){this.real.x=centre.x;this.real.mapName=centre.mapName;ret=true;};if(this._checkBoundariesY(centre)){this.real.y=centre.y;this.real.mapName=centre.mapName;ret=true;};if(ret)this.events.triggerEvent(MDVEvent_CENTRE_CHANGED,'MDVMap centre has been changed',centre);return ret;}else{return false;}};MDVMap.prototype._checkBoundariesX=function(coord){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var realOffsetX=parseInt(zoomLevel.get('realOffsetX'));var realWidth=parseInt(zoomLevel.get('realWidth'));var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var realToPxRatioWidth=realWidth/pxWidthAll;if(coord.x>=realOffsetX&&coord.x<=(realOffsetX+realWidth))return true;else return false;};MDVMap.prototype._checkBoundariesY=function(coord){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var realOffsetY=parseInt(zoomLevel.get('realOffsetY'));var realHeight=parseInt(zoomLevel.get('realHeight'));var pxHeightAll=parseInt(zoomLevel.get('tileSizeY'))*parseInt(zoomLevel.get('numberOfTilesY'));var realToPxRatioHeight=realHeight/pxHeightAll;if(coord.y>=realOffsetY&&coord.y<=(realOffsetY+realHeight))return true;else return false;};MDVMap.prototype.setZoomLevel=function(zoomLevelIndex){var zoomLevel=this.config.getZoomLevel(zoomLevelIndex);if(this.config.getZoomLevelIndex()!=zoomLevelIndex&&zoomLevel){this.config.setZoomLevelIndex(zoomLevelIndex);this.events.triggerEvent(MDVEvent_ZOOM_CHANGED,'MDVMap zoom level has been changed',zoomLevelIndex);return true;}else{if(!zoomLevel)this.events.triggerEvent(MDVEvent_ERROR,'MDVMap wasn\'t able to set new zoom level.');return false;}};MDVMap.prototype.getObjWidth=function(obj){var result=0;if(obj.offsetWidth){result=obj.offsetWidth;}else if(obj.clip&&obj.clip.width){result=obj.clip.width;}else if(obj.style&&obj.style.pixelWidth){result=obj.style.pixelWidth;};return parseInt(result);};MDVMap.prototype.getObjHeight=function(obj){var result=0;if(obj.offsetHeight){result=obj.offsetHeight;}else if(obj.clip&&obj.clip.height){result=obj.clip.height;}else if(obj.style&&obj.style.pixelHeight){result=obj.style.pixelHeight;};return parseInt(result);};MDVMap.prototype._setBackgroundColour=function(color){this.viewport.style.backgroundColor=color;};MDVMap.prototype.getName=function(){return this.name;};MDVMap.prototype.resize=function(){if(this.state==0){this.events.triggerEvent(MDVEvent_WARNING,'MDVMap is already loading... please wait.');return false;}else if(this.state==1){this.events.triggerEvent(MDVEvent_ERROR,'MDVMap has already been invoked.');return false;};this.viewportHeight=this.getObjHeight(this.viewport);this.viewportWidth=this.getObjWidth(this.viewport);if(this.viewportHeight<=2||this.viewportWidth<=2)this.events.triggerEvent(MDVEvent_ERROR,'MDVMap couldn\'t get size from target map object(' + this.viewport.id + ').');};MDVMap.prototype.execute=function(config){this.resize();this.wrapOffset=new MDVPoint(0,0);if(config&&this.config==null)this.config=config;else{this.events.triggerEvent(MDVEvent_ERROR,'MDVMap couldn\'t find an appropriate configuration or already has one.');this.state=-1;return false;};this.name=this.viewport.id;if(!document.mdvMaps)document.mdvMaps=new Array();document.mdvMaps['mdvMap_'+this.name]=this;if(this.config.get('defaultScale'))this.setZoomLevel(parseInt(this.config.get('defaultScale')));else this.setZoomLevel(3);if(!this.getCentre()){var newReal=new MDVCoordinates(this.config.get('mapName'),parseInt(this.config.get('xCenterReal')),parseInt(this.config.get('yCenterReal')));this.setCentre(newReal);};this._updateMapValues();this.mapper=document.createElement('div');this.mapper.id='mapper';this.mapper.style.position='absolute';this.mapper.style.left='0px';this.mapper.style.top='0px';this.mapper.style.zIndex='1';this.mapper.mdvMap=this;this.viewport.appendChild(this.mapper);this.mapper.onmousemove=MDVMap_onmousemove;this.mapper.onmouseover=MDVMap_onmouseover;this.mapper.onmousedown=MDVMap_onmousedown;this.mapper.onmouseup=MDVMap_onmouseup;this.viewport.onmouseout=MDVMap_onmouseout;this.mapper.onkeypress=MDVMap_onkeypress;this.mapper.ondblclick=MDVMap_ondblclick;this.mapper.oncontextmenu=MDVMap_oncontextmenu;this.mapper.onmousewheel=MDVMap_onmousewheel;if(window.addEventListener&&navigator.product&&navigator.product=='Gecko'){this.viewport.addEventListener('DOMMouseScroll',MDVMap_onmousewheel,false);};if(this.config.get('maxFailCount')){this.maxFailCount=parseInt(this.config.get('maxFailCount'));};if(this.config.get('crosshair')){this.crossHairSrc.src=this.config.get('crosshair');};this.mapper.ondragstart=new Function([],'var e=e?e:event;e.cancelBubble=true;e.returnValue=false;return false;');this.transparent.src=this.config.get('transparentImg');if(this.config.get('cursorIdle'))this.mapper.style.cursor=this.config.get('cursorIdle');this._viewMap();var ua=navigator.userAgent;if(ua.indexOf('Opera')<0)this.renderer=document.all?new MDVVMLRenderer(this,this.markerObjects):new MDVSVGRenderer(this,this.markerObjects);};MDVMap.prototype.destroy=function(){if(this.state==-1)return;var gLength=this.gadgets.length;for(var g=0;g<gLength;g++){var gadget=this.gadgets.pop();if(gadget)gadget.destroy();};var lLength=this.layers.length;for(var l=0;l<lLength;l++){var layer=this.layers.pop();if(layer)layer.destroy();};for(var i=0;i<this.mapTiles.childNodes.length;i++){if(this.mapTiles.childNodes[i].mdvMap)this.mapTiles.childNodes[i].mdvMap=null;};if(this.mapper){this.mapper.onmousemove=null;this.mapper.onmouseover=null;this.mapper.onmousedown=null;this.mapper.onmouseup=null;this.viewport.onmouseout=null;this.mapper.onkeypress=null;this.mapper.ondblclick=null;this.mapper.oncontextmenu=null;this.mapper.onmousewheel=null;this.mapper.mdvMap=null;};if(this.mapTiles&&this.mapTiles.mdvMap)this.mapTiles.mdvMap=null;if(this.markerObjects&&this.markerObjects.mdvMap)this.markerObjects.mdvMap=null;if(this.viewport&&this.viewport.mdvMap)this.viewport.mdvMap=null;if(this.crossHair)this.crossHair=null;if(this.crossHairSrc)this.crossHairSrc=null;this.transparent=null;document.mdvMaps['mdvMap_'+this.name]=null;};MDVMap.prototype._updateVisibleMap=function(){var zoomLevel=this.config.getZoomLevel(this.config.currentZoomLevelIndex);this._updateMapValues();var startColumn=parseInt((this.tlReal.x-parseInt(zoomLevel.get('realOffsetX')))/this.tileRealWidth);if(startColumn<0)startColumn=0;var endColumn=parseInt((this.tlReal.x+this.viewportRealWidth-zoomLevel.get('realOffsetX'))/this.tileRealWidth);if(endColumn>=parseInt(zoomLevel.get('numberOfTilesX')))endColumn=parseInt(zoomLevel.get('numberOfTilesX'))-1;var startRow=parseInt((this.tlReal.y-parseInt(zoomLevel.get('realOffsetY')))/this.tileRealHeight);if(startRow<0)startRow=0;var endRow=parseInt((this.tlReal.y+this.viewportRealHeight-parseInt(zoomLevel.get('realOffsetY')))/this.tileRealHeight);if(endRow>=parseInt(zoomLevel.get('numberOfTilesY')))endRow=parseInt(zoomLevel.get('numberOfTilesY'))-1;this.tileVisibleWidth=endColumn-startColumn+2;this.tileVisibleHeight=endRow-startRow+2;this.startTileWidth=startColumn;this.startTileHeight=startRow;if(zoomLevel.get('numberOfTilesX')<=1){this.tileVisibleWidth--;};if(zoomLevel.get('numberOfTilesY')<=1){this.tileVisibleHeight--;};var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var pxToRealRatioWidth=pxWidthAll/parseInt(zoomLevel.get('realWidth'));var pxHeightAll=parseInt(zoomLevel.get('tileSizeY'))*parseInt(zoomLevel.get('numberOfTilesY'));var pxToRealRatioHeight=pxHeightAll/parseInt(zoomLevel.get('realHeight'));var viewportCentre=new MDVPoint((this.getCentre().x-parseInt(zoomLevel.get('realOffsetX')))*pxToRealRatioWidth,(this.getCentre().y-parseInt(zoomLevel.get('realOffsetY')))*pxToRealRatioHeight);var tlViewport=new MDVPoint((this.tlReal.x-parseInt(zoomLevel.get('realOffsetX')))*pxToRealRatioWidth,(this.tlReal.y-parseInt(zoomLevel.get('realOffsetY')))*pxToRealRatioHeight);var tlTile=new MDVPoint();tlTile.x=(this.tlTileReal.x-parseInt(zoomLevel.get('realOffsetX')))*pxToRealRatioWidth;tlTile.y=(this.tlTileReal.y-parseInt(zoomLevel.get('realOffsetY')))*pxToRealRatioHeight;tlTile.x=Math.floor(tlTile.x+0.5);tlTile.y=Math.floor(tlTile.y+0.5);var tlOffset=new MDVPoint(tlTile.x-parseInt(tlViewport.x),tlTile.y-parseInt(tlViewport.y));this.mapper.style.left=tlOffset.x+'px';this.mapper.style.top=tlOffset.y+'px';this.getCentre().x=Math.floor(this.getCentre().x+0.5);this.getCentre().y=Math.floor(this.getCentre().y+0.5);this.wrapOffset=new MDVPoint(0,0);};MDVMap.prototype._updateMapValues=function(){var zoomLevel=this.config.getZoomLevel(this.config.currentZoomLevelIndex);if(!zoomLevel){this.events.triggerEvent(MDVEvent_ERROR,'MDVMap has an invalid zoom level.');return false;};var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var pxToRealRatioWidth=pxWidthAll/parseInt(zoomLevel.get('realWidth'));var pxHeightAll=parseInt(zoomLevel.get('tileSizeY'))*parseInt(zoomLevel.get('numberOfTilesY'));var pxToRealRatioHeight=pxHeightAll/parseInt(zoomLevel.get('realHeight'));this.tileRealWidth=parseInt(zoomLevel.get('realWidth'))/parseInt(zoomLevel.get('numberOfTilesX'));this.tileRealHeight=parseInt(zoomLevel.get('realHeight'))/parseInt(zoomLevel.get('numberOfTilesY'));this.tileCountWidth=parseInt(this.viewportWidth)/parseInt(zoomLevel.get('tileSizeX'));this.tileCountHeight=parseInt(this.viewportHeight)/parseInt(zoomLevel.get('tileSizeY'));this.viewportRealWidth=parseInt(this.tileRealWidth*this.tileCountWidth);this.viewportRealHeight=parseInt(this.tileRealHeight*this.tileCountHeight);this.tlReal=new MDVCoordinates(this.config.get('mapName'),parseInt(this.getCentre().x-(this.viewportRealWidth/2)),parseInt(this.getCentre().y-(this.viewportRealHeight/2)));var tlViewport=new MDVPoint((this.tlReal.x-parseInt(zoomLevel.get('realOffsetX')))*pxToRealRatioWidth,(this.tlReal.y-parseInt(zoomLevel.get('realOffsetY')))*pxToRealRatioHeight);var tlTileColumn=parseInt(tlViewport.x/parseInt(zoomLevel.get('tileSizeX')));var tlTileRow=parseInt(tlViewport.y/parseInt(zoomLevel.get('tileSizeY')));this.tlTileReal=new MDVCoordinates(this.config.get('mapName'),tlTileColumn*this.tileRealWidth+parseInt(zoomLevel.get('realOffsetX')),tlTileRow*this.tileRealHeight+parseInt(zoomLevel.get('realOffsetY')));this.tlTileReal.x=Math.floor(this.tlTileReal.x+0.5);this.tlTileReal.y=Math.floor(this.tlTileReal.y+0.5);return true;};MDVMap.prototype.getTopLeftTileReal=function(){return this.tlTileReal;};MDVMap.prototype._checkWrap=function(){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var tileSize=new MDVPoint(zoomLevel.get('tileSizeX'),zoomLevel.get('tileSizeY'));var tempX=this.viewportWidth-parseInt(zoomLevel.get('numberOfTilesX'))*parseInt(zoomLevel.get('tileSizeX'));var tempY=this.viewportWidth-parseInt(zoomLevel.get('numberOfTilesY'))*parseInt(zoomLevel.get('tileSizeY'));var wrapX=zoomLevel.get('numberOfTilesX')<=1|tempX>0;var wrapY=zoomLevel.get('numberOfTilesY')<=1|tempY>0;this.offset=new MDVPoint(parseInt(this.mapper.style.left)-this.wrapOffset.x,parseInt(this.mapper.style.top)-this.wrapOffset.y);if(this.offset.x>0){if(wrapX)return false;this._applyWrapR2L();};if(this.offset.x<-(tileSize.x)){if(wrapX)return false;this._applyWrapL2R();};if(this.offset.y>0){if(wrapY)return false;this._applyWrapB2T();};if(this.offset.y<-(tileSize.y)){if(wrapY)return false;this._applyWrapT2B();};return true;};MDVMap.prototype._applyWrapT2B=function(){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var tileSize=new MDVPoint(zoomLevel.get('tileSizeX'),zoomLevel.get('tileSizeY'));this.wrapOffset.y-=parseInt(tileSize.y);this.startTileHeight++;var mapTiles=this.mapTiles;var lastTile=parseInt(mapTiles.childNodes[this.imgCountHeight*this.imgCountWidth-1].style.top);for(var x=0;x<this.imgCountWidth;x++){var bottomImg=mapTiles.childNodes[0];bottomImg.src=this.transparent.src;bottomImg.style.top=(parseInt(lastTile)+parseInt(tileSize.y))+'px';mapTiles.removeChild(bottomImg);mapTiles.appendChild(bottomImg);};this._setMapTiles(false);};MDVMap.prototype._applyWrapB2T=function(){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var tileSize=new MDVPoint(zoomLevel.get('tileSizeX'),zoomLevel.get('tileSizeY'));this.wrapOffset.y+=parseInt(tileSize.y);this.startTileHeight--;var mapTiles=this.mapTiles;var topTile=parseInt(mapTiles.childNodes[0].style.top);for(var x=0;x<this.imgCountWidth;x++){var topImg=mapTiles.childNodes[(this.imgCountHeight*this.imgCountWidth)-1];topImg.src=this.transparent.src;topImg.style.top=(parseInt(topTile)-parseInt(tileSize.y))+'px';mapTiles.removeChild(topImg);mapTiles.insertBefore(topImg,mapTiles.childNodes[0]);};this._setMapTiles(false);};MDVMap.prototype._applyWrapL2R=function(){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var tileSize=new MDVPoint(zoomLevel.get('tileSizeX'),zoomLevel.get('tileSizeY'));this.wrapOffset.x-=parseInt(tileSize.x);this.startTileWidth++;var mapTiles=this.mapTiles;var lastTile=parseInt(mapTiles.childNodes[this.imgCountWidth-1].style.left);for(var y=0;y<this.imgCountHeight;y++){var firstImg=mapTiles.childNodes[y*this.imgCountWidth];var beforeImg;if(y<(this.imgCountHeight-1)){beforeImg=mapTiles.childNodes[(y+1)*this.imgCountWidth];}else{beforeImg=null;};firstImg.src=this.transparent.src;firstImg.style.left=(parseInt(lastTile)+parseInt(tileSize.x))+'px';mapTiles.removeChild(firstImg);if(beforeImg){mapTiles.insertBefore(firstImg,beforeImg);}else{mapTiles.appendChild(firstImg);}};this._setMapTiles(false);};MDVMap.prototype._applyWrapR2L=function(){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var tileSize=new MDVPoint(zoomLevel.get('tileSizeX'),zoomLevel.get('tileSizeY'));this.wrapOffset.x+=parseInt(tileSize.x);this.startTileWidth--;var mapTiles=this.mapTiles;var firstTile=parseInt(mapTiles.childNodes[0].style.left);for(var y=0;y<this.imgCountHeight;y++){var lastImg=mapTiles.childNodes[((y+1)*this.imgCountWidth)-1];var nextImg=mapTiles.childNodes[y*this.imgCountWidth];lastImg.src=this.transparent.src;lastImg.style.left=(firstTile-tileSize.x)+'px';mapTiles.removeChild(lastImg);mapTiles.insertBefore(lastImg,nextImg);};this._setMapTiles(false);};MDVMap.prototype.update=function(){this._updateVisibleMap();this._setLayers();this._updateLayers();if(this._setImages()){this._setMapTiles(true);}else{var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var cX=parseInt(zoomLevel.get('realOffsetX'))+parseInt(zoomLevel.get('realWidth'))/2;var cY=parseInt(zoomLevel.get('realOffsetY'))+parseInt(zoomLevel.get('realHeight'))/2;var cNew=new MDVCoordinates(this.config.get('mapName'),parseInt(cX),parseInt(cY));this.events.triggerEvent(MDVEvent_ERROR,'MDVMap has determined that the given coordinates are out of bounds. Setting zoom level centre.',cNew);this.setCentre(cNew);this.update();};this.events.triggerEvent(MDVEvent_MAP_INITIALISED,'MDVMap tiles have been initialised',this);};MDVMap.prototype._viewMap=function(){this.state=0;if(this.config.get('backgroundColour'))this._setBackgroundColour(this.config.get('backgroundColour'));else this._setBackgroundColour('#E5E5E5');this.events.triggerEvent(MDVEvent_INITIALISED,'MDVMap has been initialised',this);this._setLayers();this.update();this.state=1;};MDVMap.prototype._setMapTiles=function(adjust){var mapTiles=this.mapTiles;var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());if(!(this.imgCountWidth*this.imgCountHeight==this.mapTiles.childNodes.length)){this.events.triggerEvent(MDVEvent_ERROR,'MDVMap noticed an inconsistency within the tile layer.');this._removeImages();this.update();};var block=parseInt(this.config.get('block'));var fileType='.png';if(this.config.get('fileType')){fileType=this.config.get('fileType');};for(var y=0;y<this.imgCountHeight;y++){for(var x=0;x<this.imgCountWidth;x++){var img=mapTiles.childNodes[(y*this.imgCountWidth)+x];if(!img){this.events.triggerEvent(MDVEvent_ERROR,'Error accessing tile within DOM.');return false;};var pos=new MDVPoint(x*parseInt(zoomLevel.get('tileSizeX')),y*parseInt(zoomLevel.get('tileSizeY')));var src=this.config.get('serverURL');var level=this.config.getZoomLevelIndex();if(zoomLevel.get('zoomLevel'))level=zoomLevel.get('zoomLevel');if(this.config.get('block')){var block=parseInt(this.config.get('block'));var columnMin=Math.floor((this.startTileWidth+x)/block)*block;var columnMax=columnMin+block-1;var rowMin=Math.floor((this.startTileHeight+y)/block)*block;var rowMax=rowMin+block-1;src+='zoomlevel';src+=level;src+='/columns'+columnMin+'-'+columnMax;src+='/column';src+=(this.startTileWidth+x);src+='/rows'+rowMin+'-'+rowMax+'/';src+=(this.startTileHeight+y);src+='_';src+=(this.startTileWidth+x);src+='_';src+=level;src+=fileType;}else{src+='zoomlevel';src+=level;src+='/column';src+=(this.startTileWidth+x);src+='/'+this.config.get('network')+'_';src+=(this.startTileHeight+y);src+='_';src+=(this.startTileWidth+x);src+=fileType;};if(img.src!=src){img.src=src;if(adjust&&!document.all)img.style.visibility='hidden';};img.style.width=zoomLevel.get('tileSizeX');img.style.height=zoomLevel.get('tileSizeY');img.width=zoomLevel.get('tileSizeX');img.height=zoomLevel.get('tileSizeY');if(this.config.get('debug')){img.alt=src;img.title=src;};img.failCount=0;if(adjust){img.style.left=pos.x+'px';img.style.top=pos.y+'px';}}}};MDVMap.prototype._setLayers=function(){if(!this.mapTiles&&this.mapper){this.mapTiles=document.createElement('div');this.mapTiles.className='mdvLayer';this.mapTiles.style.zIndex='0';this.mapTiles.id=this.name+'_mdvMapTiles';this.mapTiles.style.position='absolute';this.mapTiles.style.visibility='visible';this.mapTiles.style.left='0px';this.mapTiles.style.top='0px';this.mapTiles.style.width='3000px';this.mapTiles.style.height='3000px';this.mapTiles.mdvMap=this;this.mapper.appendChild(this.mapTiles);this.mapTiles.append=true;this.events.triggerEvent(MDVEvent_DEBUG,'MDVMap has finished initialisation of the tile div.');};if(!this.markerObjects&&this.mapper){this.markerObjects=document.createElement('div');this.markerObjects.className='mdvLayer';this.markerObjects.style.zIndex='1';this.markerObjects.id=this.name+'_mdvMarkers';this.markerObjects.style.position='absolute';this.markerObjects.style.visibility='visible';this.markerObjects.style.left='0px';this.markerObjects.style.top='0px';this.markerObjects.style.width='3000px';this.markerObjects.style.height='3000px';this.markerObjects.mdvMap=this;this.mapper.appendChild(this.markerObjects);this.markerObjects.append=true;this.events.triggerEvent(MDVEvent_DEBUG,'MDVMap has finished initialisation of the marker objects div.');};if(!this.markerLayer){this.markerLayer=this.createLayer('mdvMarkers');this.addLayer(this.markerLayer);}};MDVMap.prototype._setImages=function(){if(this.tileVisibleWidth<=0||this.tileVisibleHeight<=0)return false;while(this.imgCountWidth<this.tileVisibleWidth){this._addColumn();}while(this.imgCountHeight<this.tileVisibleHeight){this._addRow();}while(this.imgCountHeight>this.tileVisibleHeight){this._removeRow();}while(this.imgCountWidth>this.tileVisibleWidth){this._removeColumn();};return true;};MDVMap.prototype._removeImages=function(){var count=this.mapTiles.childNodes.length;for(var i=0;i<count;i++){var remove=this.mapTiles.childNodes[count-i-1];remove.onmousedown=null;remove.onmousemove=null;remove.onmouseout=null;remove.onmouseover=null;remove.onmouseup=null;remove.onmousewheel=null;remove.onclick=null;remove.onload=null;remove.onerror=null;if(remove.mdvMap)remove.mdvMap=null;this.mapTiles.removeChild(remove);};this.imgCountWidth=0;this.imgCountHeight=0;};MDVMap.prototype._addColumn=function(){if(this.tileVisibleWidth==0)return;var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());for(var i=0;i<this.imgCountHeight;i++){var pos=new MDVPoint((this.imgCountWidth+1)*parseInt(zoomLevel.get('tileSizeX')),i*parseInt(zoomLevel.get('tileSizeY')));var img=this._createImage(pos);this.mapTiles.appendChild(img);};this.imgCountWidth++;};MDVMap.prototype._removeColumn=function(){if(this.imgCountWidth<=1)return;var children=this.mapTiles.childNodes.length+this.imgCountWidth-2;for(var y=0;y<this.imgCountHeight;y++){var index=(this.imgCountHeight*y)+(this.imgCountWidth-1);var img=this.mapTiles.childNodes[(children-index)];if(!img){this.events.triggerEvent(MDVEvent_ERROR,'Error accessing tile.');return false;};img.onmousedown=null;img.onmousemove=null;img.onmouseout=null;img.onmouseover=null;img.onmouseup=null;img.onmousewheel=null;img.onclick=null;if(img.mdvMap)img.mdvMap=null;img.onload=null;img.onerror=null;this.mapTiles.removeChild(img);};this.imgCountWidth--;};MDVMap.prototype._addRow=function(){if(this.tileVisibleWidth==0)return;var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var i;for(i=0;i<this.tileVisibleWidth;i++){var pos=new MDVPoint(i*parseInt(zoomLevel.get('tileSizeX')),this.imgCountHeight*parseInt(zoomLevel.get('tileSizeY')));var img=this._createImage(pos);this.mapTiles.appendChild(img);this.imgCountWidth++;};this.imgCountWidth=i;this.imgCountHeight++;};MDVMap.prototype._removeRow=function(){if(this.imgCountHeight<=1)return;var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());for(var i=0;i<this.imgCountWidth;i++){var index=(this.imgCountHeight*this.imgCountWidth)-i-1;var img=this.mapTiles.childNodes[index];if(!img){this.events.triggerEvent(MDVEvent_ERROR,'MDVMap has problems while accessing tile.');return false;};img.onload=null;img.onerror=null;this.mapTiles.removeChild(img);};this.imgCountHeight--;};MDVMap.prototype._createImage=function(pos){var zoomLevel=this.config.getZoomLevel(this.config.getZoomLevelIndex());var img=document.createElement('img');img.src=this.transparent.src;img.width=parseInt(zoomLevel.get('tileSizeX'));img.height=parseInt(zoomLevel.get('tileSizeY'));img.setAttribute('style','position:absolute; top:'+pos.y+'px; left:'+pos.x+'px;');img.style.position='absolute';img.style.width=parseInt(zoomLevel.get('tileSizeX'));+"px";img.style.height=parseInt(zoomLevel.get('tileSizeY'));+"px";img.style.top=pos.y;img.style.left=pos.x;img.galleryimg="no";img.onerror=MDVMap_imgOnError;img.onload=MDVMap_imgOnLoad;img.mdvMap=this;img.id="t"+this.lastImageID++;img.failCount=0;return img;};MDVMap.prototype.getPolylinePoints=function(){var xArr=new Array();var yArr=new Array();for(var l=0;l<this.layers.length;l++){var coords=this.layers[l].getPolylineCoords();for(var c=0;c<coords.length;c++){var point=this.getPoint(coords[c]);xArr.push(point.x);yArr.push(point.y);}};return[xArr,yArr];};MDVMap.prototype.getPolylineCoords=function(){var xArr=new Array();var yArr=new Array();for(var l=0;l<this.layers.length;l++){var coords=this.layers[l].getPolylineCoords();for(var c=0;c<coords.length;c++){xArr.push(coords[c].x);yArr.push(coords[c].y);}};return[xArr,yArr];};MDVMap.prototype.createLayer=function(name){var retLayer=new MDVLayer(this,name);return retLayer;};MDVMap.prototype.hideToolTips=function(){var layers=this.getLayers();var ret=false;for(var l=0;l<layers.length;l++){ret=layers[l].hideToolTips();};return ret;};MDVMap.prototype.createPolyline=function(coords){var polyline=new MDVPolyline(this,coords);return polyline;};MDVMap.prototype.moveBySeq=function(coordSeq){var update=true;if(this.moveJobID)mdvTimer.remove(this.moveJobID);var mSeq=this.getMoveSeq(coordSeq);var crosshair=null;if(arguments.length>=2){if(arguments[1])crosshair=arguments[1];if(arguments[2])update=arguments[2];};if(mSeq.length>0&&(crosshair!=null||this.config.get('crosshair'))){var crs=this.crossHairSrc.src;if(crosshair)crs=crosshair;if(this.crossHair==null){this.crossHair=this.createMarker(mSeq[0].clone(),new MDVPoint(0.5,0.5),crs);this.addMarker(this.crossHair);}};if(mSeq.length>0&&update){var centre=mSeq[0].clone();this.setCentre(centre);this.update();};thismoveJobID=mdvTimer.add(this.stepTime,this,this.move,[mSeq,0]);return true;};MDVMap.prototype.getMoveSeq=function(coordSeq){if(coordSeq.length<=0)return null;var zoomLevel=this.config.getZoomLevel(this.config.currentZoomLevelIndex);var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var realRatioWidthToPx=parseInt(zoomLevel.get('realWidth'))/pxWidthAll;var steps=new Array();var current=coordSeq[0].clone();var distance=0;var offset=null;var dest=null;var stepReal=this.stepPx*realRatioWidthToPx;for(var c=1;c<coordSeq.length;c++){dest=coordSeq[c];var vec=new MDVPoint(dest.x-current.x,dest.y-current.y);if(vec.x==0&&vec.y==0)continue;distance=Math.sqrt(Math.pow(vec.x,2)+Math.pow(vec.y,2));var norm=stepReal/distance;offset=new MDVPoint(vec.x*norm,vec.y*norm);while(distance>stepReal){current.x=(current.x+offset.x);current.y=(current.y+offset.y);steps.push(current.clone());distance=distance-stepReal;};if(distance>0){offset=new MDVPoint(dest.x-current.x,dest.y-current.y);current.x=(current.x+offset.x);current.y=(current.y+offset.y);steps.push(current.clone());};distance=0;};return steps;};MDVMap.prototype.move=function(mSeq,index){if(index>=mSeq.length){if(this.moveJobID)mdvTimer.remove(this.moveJobID);this.moveJobID=null;this.removeMarker(this.crossHair);this.crossHair=null;this.events.triggerEvent(MDVEvent_ROUTE_TRACE_FINISHED,'MDVMap has finished moving...',mSeq);return false;};this.moveTo(mSeq[index]);index++;this.moveJobID=mdvTimer.add(this.stepTime,this,this.move,[mSeq,index]);};MDVMap.prototype.moveTo=function(coords){var centre=this.getPoint(this.getCentre());var target=this.getPoint(coords);if(this.crossHair)this.crossHair.setCoords(coords.clone());var tl=new MDVPoint(parseInt(this.mapper.style.left),parseInt(this.mapper.style.top));if(centre==null||target==null)return false;var offset=new MDVPoint(target.x-centre.x,target.y-centre.y);this.mapper.style.left=(tl.x-offset.x)+'px';this.mapper.style.top=(tl.y-offset.y)+'px';this.setCentre(coords);this._checkWrap();return true;};function MDVMapConfig(){this.zoomLevels=new Array();this.currentZoomLevelIndex=null;this.params=new Array();};MDVMapConfig.prototype.clone=function(){var ret=new MDVMapConfig();for(var z=0;z<this.zoomLevels.length;z++){var zl=new MDVMapConfigZoomLevel(this.zoomLevels[z].getLevel());zl.setScale(this.zoomLevels[z].getScale());if(this.zoomLevels[z].get('tileSizeX'))zl.add('tileSizeX',this.zoomLevels[z].get('tileSizeX'));if(this.zoomLevels[z].get('tileSizeY'))zl.add('tileSizeY',this.zoomLevels[z].get('tileSizeY'));if(this.zoomLevels[z].get('numberOfTilesX'))zl.add('numberOfTilesX',this.zoomLevels[z].get('numberOfTilesX'));if(this.zoomLevels[z].get('numberOfTilesY'))zl.add('numberOfTilesY',this.zoomLevels[z].get('numberOfTilesY'));if(this.zoomLevels[z].get('realOffsetX'))zl.add('realOffsetX',this.zoomLevels[z].get('realOffsetX'));if(this.zoomLevels[z].get('realOffsetY'))zl.add('realOffsetY',this.zoomLevels[z].get('realOffsetY'));if(this.zoomLevels[z].get('realWidth'))zl.add('realWidth',this.zoomLevels[z].get('realWidth'));if(this.zoomLevels[z].get('realHeight'))zl.add('realHeight',this.zoomLevels[z].get('realHeight'));if(this.zoomLevels[z].get('arity'))zl.add('arity',this.zoomLevels[z].get('arity'));if(this.zoomLevels[z].get('showSTOP'))zl.add('showSTOP',this.zoomLevels[z].get('showSTOP'));if(this.zoomLevels[z].get('showPOI'))zl.add('showPOI',this.zoomLevels[z].get('showPOI'));if(this.zoomLevels[z].get('showLOCALITY'))zl.add('showLOCALITY',this.zoomLevels[z].get('showLOCALITY'));if(this.zoomLevels[z].get('block'))zl.add('block',this.zoomLevels[z].get('block'));if(this.zoomLevels[z].get('zoomLevel'))zl.add('zoomLevel',this.zoomLevels[z].get('zoomLevel'));ret.registerZoomLevel(zl);};return ret;};MDVMapConfig.prototype.registerZoomLevel=function(zoomLevelObj){this.zoomLevels[zoomLevelObj.level]=zoomLevelObj;};MDVMapConfig.prototype.getZoomLevels=function(){return this.zoomLevels;};MDVMapConfig.prototype.getZoomLevel=function(index){if(this.zoomLevels[index])return this.zoomLevels[index];else return null;};MDVMapConfig.prototype.add=function(key,value){this.params[key]=value;};MDVMapConfig.prototype.get=function(key){return this.params[key];};MDVMapConfig.prototype.setZoomLevelIndex=function(zoomLevelIndex){this.currentZoomLevelIndex=zoomLevelIndex;};MDVMapConfig.prototype.getZoomLevelIndex=function(){return this.currentZoomLevelIndex;};function MDVMapConfigZoomLevel(level){this.level=level;this.scale=null;this.params=new Array();};MDVMapConfigZoomLevel.prototype.add=function(key,value){this.params[key]=value;};MDVMapConfigZoomLevel.prototype.get=function(key){return this.params[key];};MDVMapConfigZoomLevel.prototype.setScale=function(scale){this.scale=scale;};MDVMapConfigZoomLevel.prototype.getScale=function(){return this.scale;};MDVMapConfigZoomLevel.prototype.getLevel=function(){return this.level;};function MDVEvents(){this.events=[];this.lastEventID=0;};MDVEvents.prototype.addEventID=function(id){if(!this.events[id]){this.events[id]=[];}};MDVEvents.prototype.registerEvent=function(id,target,func){if(this.events[id]){this.events[id].push([target,func]);}};MDVEvents.prototype.deregisterEvent=function(id,obj,func){var retVal=false;if(!this.events[id])return false;for(var i=0;i<this.events[id].length;i++){if(this.events[id][i][0]==obj&&this.events[id][i][1]==func){this.events[id].splice(i,1);retVal=true;}};return retVal;};MDVEvents.prototype.triggerEvent=function(id){if(!this.events[id]){return false;};var args=new Array();for(var i=0;i<arguments.length;i++)args[args.length]=arguments[i];if(document.getElementById&&document.getElementById('MDVMap_Console')&&args.length>=2){var curDate=new Date();var dateHr=curDate.getHours();var dateMin=curDate.getMinutes();var dateSec=curDate.getSeconds();if(dateHr<=9)dateHr='0'+dateHr;if(dateMin<=9)dateMin='0'+dateMin;if(dateSec<=9)dateSec='0'+dateSec;var dateStr=dateHr+':'+dateMin+':'+dateSec;document.getElementById('MDVMap_Console').value=dateStr+' '+args[1]+' (id: '+id+')'+'\n'+document.getElementById('MDVMap_Console').value;};for(var i=0;i<this.events[id].length;i++)this.events[id][i][1].apply(this.events[id][i][0],arguments);return true;};MDVMap_onmousemove=function(e){e=e?e:window.event;var ret=true;if(e.button==2)this.mdvMap.events.triggerEvent(MDVEvent_CONTEXT_MENU);for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmousemove(e))ret=false;};return ret;};MDVMap_onmouseover=function(e){e=e?e:window.event;var ret=true;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmouseover(e))ret=false;};return ret;};MDVMap_onmousedown=function(e){e=e?e:window.event;var ret=true;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmousedown(e))ret=false;};return ret;};MDVMap_onmouseup=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmouseup(e))return false;};return true;};MDVMap_onmouseout=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmouseout(e))return false;};return true;};MDVMap_onkeypress=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onkeypress(e))return false;};return true;};MDVMap_ondblclick=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].ondblclick(e))return false;};return true;};MDVMap_oncontextmenu=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].oncontextmenu(e))return false;};return true;};MDVMap_onmousewheel=function(e){e=e?e:window.event;for(var g=0;g<this.mdvMap.gadgets.length;g++){if(!this.mdvMap.gadgets[g].onmousewheel(e))return false;};return true;};MDVMap_imgOnError=function(){if(this.mdvMap){this.mdvMap.events.triggerEvent(MDVEvent_WARNING,'MDVMap couldn\'t load tile ' + this.id + '(failCount:' + this.failCount + ')');this.failCount++;var failSrc=this.src;this.src=this.mdvMap.transparent.src;if(this.failCount<=this.mdvMap.maxFailCount){this.src=failSrc;}else{this.src=this.mdvMap.transparent.src;}}};MDVMap_imgOnLoad=function(){this.style.visibility='visible';if(this.failCount>0&&this.src!=this.mdvMap.transparent.src)this.mdvMap.events.triggerEvent(MDVEvent_WARNING,'MDVMap recovered tile '+this.id+' (failCount: '+this.failCount+')');};function MDVCoordinates(mapName,x,y){this.x=x;this.y=y;if(typeof x=='string')this.x=parseInt(this.x);if(typeof y=='string')this.y=parseInt(this.y);this.mapName=mapName;};MDVCoordinates.prototype.toString=function(){return this.mapName+', x: '+this.x+', y: '+this.y;};MDVCoordinates.prototype.equals=function(coords){if(!coords||!coords.x||!coords.y)return false;var x=this.x;var y=this.y;var targetX=coords.x;var targetY=coords.y;if(x%1>0)x=parseInt(Math.floor(x+0.5));if(y%1>0)y=parseInt(Math.floor(y+0.5));if(targetX%1>0)targetX=parseInt(Math.floor(targetX+0.5));if(targetY%1>0)targetY=parseInt(Math.floor(targetY+0.5));return(x==targetX&&y==targetY&&this.mapName==coords.mapName);};MDVCoordinates.prototype.clone=function(){return new MDVCoordinates(this.mapName,this.x,this.y);};function MDVPoint(x,y){this.x=x;this.y=y;if(typeof x=='string')this.x=parseInt(this.x);if(typeof y=='string')this.y=parseInt(this.y);};MDVPoint.prototype.toString=function(){return 'x: '+this.x+', y: '+this.y;};MDVPoint.prototype.equals=function(point){if(!point||!point.x||!point.y)return false;var x=this.x;var y=this.y;var targetX=point.x;var targetY=point.y;if(x%1>0)x=parseInt(Math.floor(x+0.5));if(y%1>0)y=parseInt(Math.floor(y+0.5));if(targetX%1>0)targetX=parseInt(Math.floor(targetX+0.5));if(targetY%1>0)targetY=parseInt(Math.floor(targetY+0.5));return(x==targetX&&y==targetY);};MDVPoint.prototype.clone=function(){return new MDVPoint(this.x,this.y);};function MDVMarker(mdvMap,coords,imgSrc,factor){if(!mdvMap)return;this.mdvMap=mdvMap;this.img=new Image();this.img.marker=this;this.img.mdvMap=mdvMap;this.img.onload=MDVMarker_onload;this.imgSrc=imgSrc;this.marker=this;this.id=mdvMap.lastMarkerID++;this.coords=coords;this.toolTip=null;this.visible=true;this.objectId={type:'coord',desc:'',id:this.getCoords().x+':'+this.getCoords().y+':'+this.getCoords().mapName,omc:'',marker:this};this.append=false;if(typeof factor=='object'&&factor&&factor.x>=0&&factor.y>=0){this.xFactor=factor.x;this.yFactor=factor.y;}else{this.xFactor=factor;this.yFactor=1;}};MDVMarker.prototype.setVisibility=function(visible){var value=visible?'visible':'hidden';this.img.style.visibility=value;this.visible=visible;return true;};MDVMarker.prototype.isVisible=function(){return this.visible;};MDVMarker.prototype.equals=function(marker){return this.id==marker.id;};MDVMarker.prototype.intersects=function(mrkr){if(mrkr==null)return false;var recThis=this.getRectangle();var recMrkr=mrkr.getRectangle();return recMrkr.width>0&&recMrkr.height>0&&recThis.width>0&&recThis.height>0&&recMrkr.x<recThis.x+recThis.width&&recMrkr.x+recMrkr.width>recThis.x&&recMrkr.y<recThis.y+recThis.height&&recMrkr.y+recMrkr.height>recThis.y;};MDVMarker.prototype.getRectangle=function(){var point=this.mdvMap.getPoint(this.getCoords());var width=this.img.width;var height=this.img.height;var xFactor=this.getXFactor();var yFactor=this.getYFactor();var upperLeft=new MDVPoint(point.x-width*xFactor,point.y-height*yFactor);return{x:upperLeft.x,y:upperLeft.y,width:width,height:height};};MDVMarker.prototype.update=function(){var point=this.mdvMap.getPoint(this.getCoords());var ttUpdate=true;if(!point){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap wasn\'t able to get px coordinates for marker.');return false;};if(arguments.length>0)ttUpdate=arguments[0];var width=this.img.width;var height=this.img.height;var xFactor=this.getXFactor();var yFactor=this.getYFactor();this.img.style.position='absolute';this.img.style.left=(point.x-width*xFactor)+'px';this.img.style.top=(point.y-height*yFactor)+'px';this.img.style.zIndex=this.zIndex;var visb=this.visible?'visible':'hidden';if(this.img.style.visibility!=visb)this.img.style.visibility=visb;if(this.toolTip&&this.layer&&!this.append)this.toolTip.setZIndex(this.layer.zIndex+10);if(this.toolTip&&ttUpdate)this.toolTip.update();return true;};MDVMarker.prototype.destroy=function(){this.img.marker=null;this.img.mdvMap=null;if(this.toolTip)this.toolTip.destroy();if(this.marker.layer)this.marker.layer=null;this.toolTip=null;this.objectId=null;this.coords=null;this.marker=null;this.img.onload=null;this.img=null;};MDVMarker.prototype.getCoords=function(){if(this.coords&&this.coords.x>0&&this.coords.y>0){return this.coords;};return null;};MDVMarker.prototype.setCoords=function(coords){this.coords=coords;this.update();if(this.toolTip){this.toolTip.setCoords(this.getCoords());this.toolTip.update();}};MDVMarker.prototype.getXFactor=function(){return this.xFactor;};MDVMarker.prototype.getYFactor=function(){return this.yFactor;};MDVMarker.prototype.setTitle=function(title){this.img.title=title;this.img.alt=title;};MDVMarker.prototype.setToolTip=function(tooltip){if(!tooltip)return false;var update=true;if(arguments.length==2)update=arguments[1];var ttCoords=new MDVCoordinates(this.coords.mapName,this.coords.x,this.coords.y);this.toolTip=tooltip;this.toolTip.setParent(this);this.img.toolTip=tooltip;this.toolTip.setCoords(ttCoords);if(update)this.toolTip.update();this.img.onmouseover=MDVMap_displayToolTip;this.img.onmouseout=MDVMap_hideToolTip;this.img.onclick=MDVMap_onclick;return true;};MDVMarker.prototype.setObjectId=function(objectId){this.objectId=objectId;};MDVMarker.prototype.getObjectId=function(){return this.objectId;};MDVMarker.prototype.getImage=function(){return this.img;};MDVMarker.prototype.checkToolTipExtents=function(){if(!this.toolTip)return false;var currentPoint=new MDVPoint(parseInt(this.toolTip.div.style.left),parseInt(this.toolTip.div.style.top));var point=this.mdvMap.getPoint(this.toolTip.coords);if(currentPoint!=point)return true;var width=this.mdvMap.getObjWidth(this.toolTip.div);var height=this.mdvMap.getObjHeight(this.toolTip.div);var offset=new MDVPoint(parseInt(this.mdvMap.mapper.style.left),parseInt(this.mdvMap.mapper.style.top));if(point.x+offset.x+(width+1.1)>this.mdvMap.viewportWidth){return true;};if(point.y+offset.y+(height*1.1)>this.mdvMap.viewportHeight){return true;};return false;};function MDVMarker_onload(e){e=e?e:window.event;if(this.marker){this.marker.update();if(!this.marker.append&&this.marker.layer){this.mdvMap.markerObjects.appendChild(this);this.marker.append=true;}}};function MDVToolTip(mdvMap,innerHTML){if(!mdvMap)return;this.mdvMap=mdvMap;this.id=this.mdvMap.lastToolTipID++;this.hideJob=null;this.displayJob=null;this.coords=null;this.mousePos=null;this.div=null;this.visibility=null;this.append=false;this.parentMarker=null;this.slidable=true;this.div=document.createElement('div');this.div.onmouseover=MDVToolTip_CancelHiding;this.div.onmouseout=MDVToolTip_TriggerHiding;this.div.onmousedown=MDVToolTip_OnMouseDown;this.div.className='MDVToolTip';this.div.innerHTML=innerHTML;this.div.toolTip=this;this.setVisibility(false);};MDVToolTip.prototype.destroy=function(){this.mdvMap=null;this.parentMarker=null;this.div.onmouseover=null;this.div.onmouseout=null;this.div.onmousedown=null;this.div.toolTip=null;this.div=null;};MDVToolTip.prototype.setVisibility=function(visibility){var visb=visibility?'visible':'hidden';this.visibility=visibility;if(this.div)this.div.style.visibility=visb;if(this.mdvMap&&this.mdvMap.events)this.mdvMap.events.triggerEvent(MDVEvent_TOOLTIP,this);};MDVToolTip.prototype.setMousePosition=function(pos){this.mousePos=pos;};MDVToolTip.prototype.getMousePosition=function(){return this.mousePos;};MDVToolTip.prototype.triggerDisplaying=function(){var timeout=500;this.displayJob=mdvTimer.add(timeout,this,this.setVisibility,[true]);};MDVToolTip.prototype.cancelDisplaying=function(){if(this.displayJob!=null){if(mdvTimer.remove(this.displayJob)){this.displayJob=null;return true;}};return false;};MDVToolTip.prototype.triggerHiding=function(){var timeout=100;if(this.mdvMap.config.get('toolTimeOut'))timeout=parseInt(this.mdvMap.config.get('toolTimeOut'));this.hideJob=mdvTimer.add(timeout,this,this.setVisibility,[false]);};MDVToolTip.prototype.cancelHiding=function(){if(this.hideJob!=null){if(mdvTimer.remove(this.hideJob)){this.hideJob=null;return true;}};return false;};MDVToolTip.prototype.setInnerHTML=function(innerHTML){this.div.innerHTML=innerHTML;};MDVToolTip.prototype.getInnerHTML=function(){return this.div.innerHTML;};MDVToolTip.prototype.invertVisibility=function(){if(this.visibility){this.setVisibility(false);}else{this.setVisibility(true);}};MDVToolTip.prototype.isVisible=function(){return this.visibility;};MDVToolTip.prototype.setCoords=function(coords){if(!coords||!coords.x||!coords.y)return false;this.coords=coords;return true;};MDVToolTip.prototype.getCoords=function(){return this.coords;};MDVToolTip.prototype.setParent=function(parent){this.parentMarker=parent;};MDVToolTip.prototype.getParent=function(){return this.parentMarker;};MDVToolTip.prototype.update=function(){var point=this.mdvMap.getPoint(this.coords);var toolTipOffset=4;if(!point){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap wasn\'t able to get px coordinates for marker.');return false;};if(!this.append){this.mdvMap.markerObjects.appendChild(this.div);this.append=true;};var parent=this.getParent();var xFactor=0;var iwidth=0;var iheight=0;if(parent.img){xFactor=parent.img.width*parent.getXFactor();iwidth=parent.img.width;iheight=parent.img.height;};this.div.style.position='absolute';this.div.style.left=(point.x+xFactor+toolTipOffset)+'px';this.div.style.top=(point.y+toolTipOffset)+'px';var width=this.mdvMap.getObjWidth(this.div);var height=this.mdvMap.getObjHeight(this.div);var offset=new MDVPoint(parseInt(this.mdvMap.mapper.style.left),parseInt(this.mdvMap.mapper.style.top));if(point.x+offset.x+width+xFactor+toolTipOffset>(this.mdvMap.viewportWidth-2)){this.div.style.left=(point.x-width-iwidth+xFactor-toolTipOffset)+'px';if(point.x-width-iwidth+xFactor-(toolTipOffset*2)+offset.x<=0){var moveLeft=point.x-width-iwidth+xFactor-(toolTipOffset*2)+offset.x;this.div.style.left=parseInt(this.div.style.left)-moveLeft+'px';}};if(point.y+offset.y+height+toolTipOffset>(this.mdvMap.viewportHeight-2)){var deltaTop=(point.y-height-iheight-(toolTipOffset*2)+offset.y);if(deltaTop>0)deltaTop=0;this.div.style.top=(point.y-height-iheight-toolTipOffset-deltaTop)+'px';};return true;};MDVToolTip.prototype.setZIndex=function(zIndex){this.div.style.zIndex=zIndex;};MDVToolTip.prototype.isSlidable=function(){return this.slidable;};MDVToolTip.prototype.setSlidable=function(slidable){this.slidable=slidable;};function MDVMap_displayToolTip(e){e=e?e:window.event;var element=this.marker||this;if(element){if(element.toolTip)element.toolTip.cancelHiding();this.mdvMap.hideToolTips();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=e.target||e.srcElement;while(obj){if(obj.offsetLeft&&obj.offsetTop){offsetL+=obj.offsetLeft;offsetT+=obj.offsetTop;};obj=obj.offsetParent;};mX=mX-(offsetL);mY=mY-(offsetT);var mousePosition=new MDVPoint(mX,mY);if(!this.marker){element.toolTip.setMousePosition(mousePosition);};if(element.checkToolTipExtents){if(element.checkToolTipExtents())element.toolTip.update();}else element.toolTip.update();element.toolTip.triggerDisplaying();}};function MDVMap_hideToolTip(e){e=e?e:window.event;var element=this.marker||this;if(element&&element.toolTip){element.toolTip.cancelDisplaying();element.toolTip.triggerHiding();}};function MDVToolTip_CancelHiding(e){e=e?e:window.event;if(this.toolTip)this.toolTip.cancelHiding();};function MDVToolTip_TriggerHiding(e){e=e?e:window.event;if(this.toolTip)this.toolTip.triggerHiding();};function MDVToolTip_OnMouseDown(e){e=e?e:window.event;if(!this.toolTip.isSlidable()){e.cancelBubble=true;e.returnValue=false;if(e.stopPropogation)e.stopPropogation();if(e.preventDefault)e.preventDefault();return false;};return true;};function MDVLayer(mdvMap,layerName){if(!mdvMap||layerName=='')return;this.name=layerName;this.mdvMap=mdvMap;this.zIndex=0;this.id=mdvMap.lastLayerID++;this.visible=true;this.append=false;this.markers=new Array();this.polylines=new Array();};MDVLayer.prototype.getPolylineCoords=function(){var arr=new Array();for(var i=0;i<this.polylines.length;i++){if(this.polylines[i]==null)continue;for(var c=0;c<this.polylines[i].coords.length;c++){arr.push(this.polylines[i].coords[c]);}};return arr;};MDVLayer.prototype.getName=function(){return this.name;};MDVLayer.prototype.destroy=function(){var pLength=this.polylines.length;for(var p=0;p<pLength;p++){var polyline=this.polylines.pop();if(polyline)polyline.destroy();};this.mdvMap=null;this.layer=null;this.renderer=null;};MDVLayer.prototype.addPolyline=function(polyline){if(!polyline)return false;var update=true;for(var p=0;p<this.polylines.length;p++){if(this.polylines[p]&&this.polylines[p].id==polyline.id)return false;};if(arguments.length==2)update=arguments[1];polyline.layer=this;this.polylines.push(polyline);if(update){this.update();};return true;};MDVLayer.prototype.removePolyline=function(polyline){if(!polyline)return false;for(var p=0;p<this.polylines.length;p++){if(this.polylines[p]&&this.polylines[p].id==polyline.id){if(this.mdvMap.renderer.removePolyline(this.polylines[p]))this.polylines[p]=null;return true;}};return false;};MDVLayer.prototype.hideToolTips=function(){var ret=false;for(var m=0;m<this.markers.length;m++){if(this.markers[m].toolTip){mdvTimer.remove(this.markers[m].toolTip.job);if(this.markers[m].toolTip.isVisible()){this.markers[m].toolTip.setVisibility(false);ret=true;}}};for(var p=0;p<this.polylines.length;p++){if(this.polylines[p].toolTip){mdvTimer.remove(this.polylines[p].toolTip.job);if(this.polylines[p].toolTip.isVisible())this.polylines[p].toolTip.setVisibility(false);ret=true;}};return ret;};MDVLayer.prototype.setVisibility=function(visibility){if(this.visible!=visibility){this.visible=visibility;for(var m=0;m<this.markers.length;m++){this.markers[m].setVisibility(this.visible)}}};MDVLayer.prototype.update=function(){for(var m=0;m<this.markers.length;m++){this.markers[m].update();};if(this.mdvMap.renderer)this.mdvMap.renderer.update();for(var p=0;p<this.polylines.length;p++){this.mdvMap.renderer.drawPolyline(this.polylines[p]);};this.mdvMap.events.triggerEvent(MDVEvent_LAYER_UPDATED,'MDVMap has updated layer ('+this.name+')',this);};MDVLayer.prototype.addMarker=function(marker){var update=true;for(var m=0;m<this.markers.length;m++){if(this.markers[m].id==marker.id){return false;}};if(arguments.length==2)update=arguments[1];marker.layer=this;this.markers.push(marker);marker.img.src=marker.imgSrc;return true;};MDVLayer.prototype.removeMarker=function(marker){var tempArr=new Array();var update=false;var markersLength=this.markers.length;for(var m=0;m<markersLength;m++){var temp=this.markers.shift();if(temp.id==marker.id){this.markers=tempArr.concat(this.markers);this.mdvMap.markerObjects.removeChild(temp.img);if(temp.toolTip)this.mdvMap.markerObjects.removeChild(temp.toolTip.div);temp.destroy();update=true;break;};tempArr.push(temp);};return update;};MDVLayer.prototype.getMarkers=function(){return this.markers;};MDVLayer.prototype.removeAll=function(){var markersLength=this.markers.length;for(var m=0;m<markersLength;m++){var temp=this.markers.pop();this.mdvMap.markerObjects.removeChild(temp.img);if(temp.toolTip)this.mdvMap.markerObjects.removeChild(temp.toolTip.div);temp.destroy();};return true;};MDVLayer.prototype.setZIndex=function(zIndex){this.zIndex=zIndex*this.id;};function MDVTimer(){this.jobs=new Array();};MDVTimer.prototype.add=function(timeout,target,func,arg){var pos=this.jobs.length;for(var i=0;i<this.jobs.length;i++){if(this.jobs[i]==null){pos=i;break;}};var id=window.setTimeout('MDVTimer_execute('+pos+')',timeout);this.jobs[pos]=new MDVTimerJob(id,target,func,arg);return pos;};MDVTimer.prototype.remove=function(id){if(this.jobs[id]!=null){window.clearTimeout(this.jobs[id].id);this.jobs[id]=null;return true;};return false;};var mdvTimer=new MDVTimer();function MDVTimerJob(id,target,func,arg){this.id=id;this.target=target;this.func=func;this.arg=arg;};function MDVTimer_execute(pos){if(mdvTimer.jobs[pos]!=null){var target=mdvTimer.jobs[pos].target;var func=mdvTimer.jobs[pos].func;if(mdvTimer.jobs[pos].arg!=null)func.apply(target,mdvTimer.jobs[pos].arg);else func.apply(target);mdvTimer.jobs[pos]=null;}};function MDVMap_onclick(e){if(this.marker)this.mdvMap.events.triggerEvent(MDVEvent_OBJECT_CLICKED,this.marker.objectId);return false;};function MDVRenderer(mdvMap,container){this.mdvMap=mdvMap;this.container=container;this.max=null;this.min=null;this.border=10;this.offset=new MDVPoint(0,0);this.boundingBox=null;};MDVRenderer.prototype.drawPolyline=function(polyline){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap: Not implemented.');return false;};MDVRenderer.prototype.removePolyline=function(polyline){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap: Not implemented.');return false;};MDVRenderer.prototype.setBoundingBox=function(){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap: Not implemented.');return false;};MDVRenderer.prototype.update=function(){var coords=this.mdvMap.getPolylinePoints();if(coords.length!=2||coords[0].length<=0||coords[1].length<=0)return false;var x=coords[0];var y=coords[1];x.sort(MDVMap_NumSort);y.sort(MDVMap_NumSort);this.max=new MDVPoint(x[x.length-1],y[y.length-1]);this.min=new MDVPoint(x[0],y[0]);var bBoxMax=this.max.clone();var bBoxMin=this.min.clone();bBoxMax.x+=this.getBorder();bBoxMax.y+=this.getBorder();bBoxMin.x-=this.getBorder();bBoxMin.y-=this.getBorder();this.boundingBox=[bBoxMin.clone(),bBoxMax.clone()];this.setBoundingBox();return true;};MDVRenderer.prototype.getBorder=function(){return this.border;};function MDVVMLRenderer(mdvMap,container){this.mdvMap=mdvMap;this.container=container;this.max=null;this.min=null;this.border=50;this.offset=new MDVPoint(0,0);this.boundingBox=null;this.group=null;document.namespaces.add("v","urn:schemas-microsoft-com:vml");var style=document.createStyleSheet();style.addRule('v\\:*',"behavior: url(#default#VML);");this.group=document.createElement('v:group');this.container.appendChild(this.group);for(var method in MDVRenderer.prototype){if(!MDVVMLRenderer.prototype[method])MDVVMLRenderer.prototype[method]=MDVRenderer.prototype[method];}};MDVVMLRenderer.prototype.drawPolyline=function(polyline){if(!polyline)return false;var pathStr='m';for(var i=0;i<polyline.coords.length;i++){var point=this.mdvMap.getPoint(polyline.coords[i]);var x=point.x-this.offset.x;var y=point.y-this.offset.y;pathStr+=x+','+y;if(i<polyline.coords.length-1)pathStr+=' ';if(i==0)pathStr+='l';};pathStr+=' e';var width=this.boundingBox[1].x-this.boundingBox[0].x;var height=this.boundingBox[1].y-this.boundingBox[0].y;var left=this.boundingBox[0].x;var top=this.boundingBox[0].y;var colour=polyline.get('colour');if(!colour)colour='red';var weight=polyline.get('weight');if(!weight)weight='4px';if(!polyline.append){var shape=document.createElement("v:shape");shape.style.position='relative';shape.style.top='0px';shape.style.left='0px';shape.style.width=width;shape.style.height=height;shape.setAttribute('filled','false');shape.setAttribute('stroked','true');shape.setAttribute('strokecolor',colour);shape.setAttribute('strokeweight',weight);shape.setAttribute('path',pathStr);var stroke=document.createElement("v:stroke");stroke.setAttribute('opacity','0.5');stroke.setAttribute('joinstyle','round');stroke.setAttribute('endcap','round');shape.appendChild(stroke);this.group.appendChild(shape);polyline.element=shape;polyline.append=true;}else if(polyline.element.path.value!=pathStr){polyline.element.path.value=pathStr;};return true;};MDVVMLRenderer.prototype.removePolyline=function(polyline){if(!polyline||!polyline.append||polyline.element==null)return false;this.group.removeChild(polyline.element);polyline.destroy();polyline.append=false;return true;};MDVVMLRenderer.prototype.setBoundingBox=function(){var width=this.boundingBox[1].x-this.boundingBox[0].x;var height=this.boundingBox[1].y-this.boundingBox[0].y;var left=this.boundingBox[0].x;var top=this.boundingBox[0].y;this.offset=new MDVPoint(left,top);this.group.style.behavior='url(#default#VML)';this.group.style.width=width+'px';this.group.style.height=height+'px';this.group.style.position='absolute'
this.group.style.left=left+'px';this.group.style.top=top+'px';this.group.setAttribute('coordsize',width+','+height);return true;};function MDVSVGRenderer(mdvMap,container){this.mdvMap=mdvMap;this.container=container;this.max=null;this.min=null;this.border=10;this.offset=new MDVPoint(0,0);this.boundingBox=null;this.svgNS='http://www.w3.org/2000/svg';this.svg=document.createElementNS(this.svgNS,"svg");this.svg.setAttributeNS(null,'overflow','visible');this.container.appendChild(this.svg);for(var method in MDVRenderer.prototype){if(!MDVSVGRenderer.prototype[method])MDVSVGRenderer.prototype[method]=MDVRenderer.prototype[method];}};MDVSVGRenderer.prototype.drawPolyline=function(polyline){if(!polyline)return false;var pathStr='M';for(var i=0;i<polyline.coords.length;i++){var point=this.mdvMap.getPoint(polyline.coords[i]);var x=point.x-this.offset.x;var y=point.y-this.offset.y;pathStr+=x+','+y;if(i<polyline.coords.length-1)pathStr+=' ';if(i==0)pathStr+='L';};if(!polyline.append){var colour=polyline.get('colour');if(!colour)colour='red';var weight=polyline.get('weight');if(!weight)weight='4px';var path=document.createElementNS(this.svgNS,'path');path.setAttributeNS(null,'d',pathStr);path.setAttributeNS(null,'stroke-linejoin','round');path.setAttributeNS(null,'stroke-linecap','round');path.setAttributeNS(null,'stroke-opacity','0.50');path.setAttributeNS(null,'stroke-width',weight);path.setAttributeNS(null,'stroke',colour);path.setAttributeNS(null,'fill','none');this.svg.appendChild(path);polyline.element=path;polyline.append=true;}else{if(polyline.element)polyline.element.setAttributeNS(null,'d',pathStr);};return true;};MDVSVGRenderer.prototype.removePolyline=function(polyline){if(!polyline||!polyline.append||polyline.element==null)return false;this.svg.removeChild(polyline.element);polyline.destroy();polyline.append=false;return true;};MDVSVGRenderer.prototype.setBoundingBox=function(){var width=this.boundingBox[1].x-this.boundingBox[0].x;var height=this.boundingBox[1].y-this.boundingBox[0].y;var left=this.boundingBox[0].x;var top=this.boundingBox[0].y;this.offset=new MDVPoint(left,top);this.svg.setAttributeNS(null,'width',width+'px');this.svg.setAttributeNS(null,'height',height+'px');this.svg.setAttributeNS(null,'style','position: absolute; left: '+left+'px; top: '+top+'px;');return true;};function MDVPolyline(mdvMap,coords){if(!mdvMap)return;this.mdvMap=mdvMap;this.id=mdvMap.lastPolylineID++;this.coords=null;this.toolTip=null;this.attributes=new Array();this.element=null;this.renderer=this.mdvMap.renderer;this.layer=null;this.append=false;this.markers=new Array();if(typeof coords=='string')this.coords=this.parseString(coords);else if(typeof coords=='object')this.coords=coords;};MDVPolyline.prototype.destroy=function(){this.mdvMap=null;this.coords=null;if(this.toolTip)this.toolTip.destroy();this.coords=null;this.mdvMap=null;if(this.element){if(this.element.mdvMap)this.element.mdvMap=null;this.element.onmouseover=null;this.element.onmouseout=null;this.element.onclick=null;this.element=null;}};MDVPolyline.prototype.parseString=function(coordStr){var coordArray=coordStr.split(' ');var retArr=new Array();for(var i=0;i<coordArray.length;i++){var couple=coordArray[i].split(',');if(couple[0]&&couple[1]){var tempCoords=new MDVCoordinates(this.mdvMap.config.get('mapName'),couple[0],couple[1]);retArr.push(tempCoords);}};return retArr;};MDVPolyline.prototype.add=function(key,value){for(var i=0;i<this.attributes.length;i++){if(this.attributes[i].key==key)return false;};this.attributes[key]=value;return true;};MDVPolyline.prototype.get=function(key){if(this.attributes[key])return this.attributes[key];else return false;};MDVPolyline.prototype.getCoords=function(){return this.coords;};MDVPolyline.prototype.setToolTip=function(tooltip){if(!tooltip)return false;var update=true;if(arguments.length==2)update=arguments[1];var ttCoords=this.coords[0].clone();ttCoords.x=Math.floor(0.5+(parseInt(ttCoords.x)+parseInt(this.coords[this.coords.length-1].x))/2);ttCoords.y=Math.floor(0.5+(parseInt(ttCoords.y)+parseInt(this.coords[this.coords.length-1].y))/2);this.toolTip=tooltip;this.toolTip.setParent(this);this.toolTip.setCoords(ttCoords);if(update)this.toolTip.update();this.element.toolTip=tooltip;this.element.onmouseover=MDVMap_displayToolTip;this.element.onmouseout=MDVMap_hideToolTip;return true;};function MDVMap_NumSort(a,b){return a-b;};function MDVGadgetBase(mdvMap){if(!mdvMap)return;this.name='GadgetBase';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.destroy=function(){if(this.mdvMap)this.mdvMap=null;this.ondblclick=null;this.onkeypress=null;this.onmousedown=null;this.onmousemove=null;this.onmouseout=null;this.onmouseover=null;this.onmouseup=null;this.onmousewheel=null;this.oncontextmenu=null;};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;};function MDVMapNavigator(mdvMap){if(!mdvMap)return;this.name='MapNavigator';this.mdvMap=mdvMap;this.mouseDown=false;this.centre;this.mouseLast=new MDVPoint(-1,-1);this.mouseStart=new MDVPoint(-1,-1);this.mwHotSpot=null;this.mdvMap.registerGadget(this);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);this.mdvMap.events.registerEvent(MDVEvent_MOUSE_MOVED,this,this.updateMWHotSpot);};MDVMapNavigator.prototype.destroy=function(){if(this.mdvMap)this.mdvMap=null;this.ondblclick=null;this.onkeypress=null;this.onmousedown=null;this.onmousemove=null;this.onmouseout=null;this.onmouseover=null;this.onmouseup=null;this.onmousewheel=null;this.oncontextmenu=null;};MDVMapNavigator.prototype.updateMWHotSpot=function(id,msg,coords){if(this.mdvMap.config.get('centreOnMouseWheel')&&this.mdvMap.config.get('centreOnMouseWheel')=='true')this.mwHotSpot=coords.clone();};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){e=e?e: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));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);if(this.mdvMap.config.get('zoomOnDoubleClick')&&this.mdvMap.config.get('zoomOnDoubleClick')=='true'){this.mdvMap.setCentre(newC);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();}else if(this.mdvMap.config.get('moveOnDoubleClick')&&this.mdvMap.config.get('moveOnDoubleClick')=='true'){var seq=[this.mdvMap.getCentre().clone(),newC.clone()];this.mdvMap.moveBySeq(seq);}else{this.mdvMap.setCentre(newC);this.mdvMap.update();};return false;};MDVMapNavigator.prototype.onmousewheel=function(e){e=e?e:window.event;var ua=navigator.userAgent;var newC=null;if(this.mdvMap.config.get('centreOnMouseWheel')&&this.mdvMap.config.get('centreOnMouseWheel')=='true')newC=this.mwHotSpot;var wheelDelta=e.wheelDelta?e.wheelDelta:e.detail*-1;if(ua.indexOf('Opera')>=0)wheelDelta*=-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);if(newC)this.mdvMap.setCentre(newC);newC=null;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);newC=null;this.mdvMap.update();}};this.stopEvent(e);return false;};MDVMapNavigator.prototype.onmousedown=function(e){e=e?e:window.event;var ua=navigator.userAgent;if((e.button==0&&!window.event)||(e.button==1&&window.event)||(e.button==0&&ua.indexOf('Opera')>=0)){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;return false;};MDVMapNavigator.prototype.onmouseout=function(e){};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);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();}};function MDVMapCrosshair(mdvMap){if(!mdvMap)return;this.name='MapCrosshair';this.mdvMap=mdvMap;this.mdvMap.registerGadget(this);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;}}}};function MDVMapEFAInfo(mdvMap){this.mdvMap=mdvMap;this.name='MapEFAInfo';this.stops=null;this.poi=null;this.centre=null;this.id=null;this.lastCentre=null;this.stopImg=new Image();this.stopImg.src='images/stop.gif';this.mot1Img=new Image();this.mot1Img.src='images/mot1.gif';this.mot2Img=new Image();this.mot2Img.src='images/mot2.gif';this.mot3Img=new Image();this.mot3Img.src='images/mot3.gif';this.mot4Img=new Image();this.mot4Img.src='images/mot4.gif';this.mot5Img=new Image();this.mot5Img.src='images/mot5.gif';this.mot6Img=new Image();this.mot6Img.src='images/mot6.gif';this.mot7Img=new Image();this.mot7Img.src='images/mot7.gif';this.mot8Img=new Image();this.mot8Img.src='images/mot8.gif';this.mot9Img=new Image();this.mot9Img.src='images/mot9.gif';this.mot10Img=new Image();this.mot10Img.src='images/mot10.gif';this.mot11Img=new Image();this.mot11Img.src='images/mot11.gif';this.mot12Img=new Image();this.mot12Img.src='images/mot12.gif';this.poiImg=new Image();this.poiImg.src='images/pin.gif'
for(var method in MDVGadgetBase.prototype){if(!MDVMapEFAInfo.prototype[method])MDVMapEFAInfo.prototype[method]=MDVGadgetBase.prototype[method];};this.mdvMap.registerGadget(this);this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.trigger);this.mdvMap.events.registerEvent(MDVEvent_AJAX_CALLBACK,this,this.processPins);};MDVMapEFAInfo.prototype.destroy=function(){this.stopImg.onclick=null;this.stopImg=null;this.mot1Img.onclick=null;this.mot1Img=null;this.mot2Img.onclick=null;this.mot2Img=null;this.mot3Img.onclick=null;this.mot3Img=null;this.mot4Img.onclick=null;this.mot4Img=null;this.mot5Img.onclick=null;this.mot5Img=null;this.mot6Img.onclick=null;this.mot6Img=null;this.mot7Img.onclick=null;this.mot7Img=null;this.mot8Img.onclick=null;this.mot8Img=null;this.mot9Img.onclick=null;this.mot9Img=null;this.mot10Img.onclick=null;this.mot10Img=null;this.mot11Img.onclick=null;this.mot11Img=null;this.mot12Img.onclick=null;this.mot12Img=null;this.poiImg.onclick=null;this.poiImg=null;if(this.stops)this.stops.removeAll();if(this.poi)this.poi.removeAll();};MDVMapEFAInfo.prototype.createLayers=function(){if(!this.stops){this.stops=this.mdvMap.createLayer('efa_stops');this.stops.setZIndex(2);this.mdvMap.addLayer(this.stops);};if(!this.poi){this.poi=this.mdvMap.createLayer('efa_poi');this.poi.setZIndex(1);this.mdvMap.addLayer(this.poi);}};MDVMapEFAInfo.prototype.trigger=function(){if(this.id){mdvTimer.remove(this.id);this.id=null;};this.id=mdvTimer.add(700,this,this.execute,[]);};MDVMapEFAInfo.prototype.execute=function(){mdvTimer.remove(this.id);this.id=null;this.createLayers();var zoomLevel=this.mdvMap.config.getZoomLevel(this.mdvMap.config.getZoomLevelIndex());var showStops=zoomLevel.get('showSTOP')=="true";var showPOI=zoomLevel.get('showPOI')=="true";if(showStops||showPOI){this.fetchPins();}else{this.stops.removeAll();this.poi.removeAll();}};MDVMapEFAInfo.prototype.processPins=function(id,gadName,request){mdvTimer.remove(this.id);this.id=null;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=0;i<pins.length;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;}};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:if(pinType.toUpperCase()=='POI')tmpImg.src=this.poiImg.src;else 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('Stop: <b>'+pinName+'</b>');mapPin.setToolTip(mapPinTitle,false);mapPinTitle.objectId=pinId;break;case 'poi':var mapPinTitle=this.mdvMap.createToolTip('Landmark: <b>'+pinName+'</b>');mapPin.setToolTip(mapPinTitle,false);break;};switch(pinType){case 'poi':if(showPOI){this.poi.addMarker(mapPin,false);updatePOI=true;};break;default:if(showStops){this.stops.addMarker(mapPin,false);updateStops=true;};break;}};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(){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 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()});_params=$H(_params[0]);_params=_params.toQueryString();var _ajax=new Ajax.Request(host,{method:'post',parameters:_params,onComplete:MDVMapEFAInfo_onAjaxComplete});}};MDVMapEFAInfo.prototype.onmousedown=function(e){mdvTimer.remove(this.id);this.id=null;this.lastCentre=this.mdvMap.getCentre().clone();return true;};MDVMapEFAInfo.prototype.onmouseup=function(e){if(this.lastCentre.equals(this.mdvMap.getCentre())){this.trigger();};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;}}}};function MDVMapEFATrips(mdvMap){this.mdvMap=mdvMap;this.name='MDVMapEFATrips';this.layer=null;this.wizardJobID=null;this.wizardIndex=null;this.wizardScreenPlay=new Array();this.response=null;this.polylines=new Array();this.zoomLevel=null;this.markers=new Array();this.origin=null;this.destination=null;this.imgs=new Array();this.imgs['stop']=new Image();this.imgs['stop'].src='images/stop.gif';this.imgs['1']=new Image();this.imgs['1'].src='images/mot1.gif';this.imgs['1_follow']=new Image();this.imgs['1_follow'].src='images/mot1_follow.gif'
this.imgs['2']=new Image();this.imgs['2'].src='images/mot2.gif';this.imgs['2_follow']=new Image();this.imgs['2_follow'].src='images/mot2_follow.gif';this.imgs['3']=new Image();this.imgs['3'].src='images/mot3.gif';this.imgs['3_follow']=new Image();this.imgs['3_follow'].src='images/mot3_follow.gif';this.imgs['4']=new Image();this.imgs['4'].src='images/mot4.gif';this.imgs['4_follow']=new Image();this.imgs['4_follow'].src='images/mot4_follow.gif';this.imgs['5']=new Image();this.imgs['5'].src='images/mot5.gif';this.imgs['5_follow']=new Image();this.imgs['5_follow'].src='images/mot5_follow.gif';this.imgs['6']=new Image();this.imgs['6'].src='images/mot6.gif';this.imgs['6_follow']=new Image();this.imgs['6_follow'].src='images/mot6_follow.gif';this.imgs['7']=new Image();this.imgs['7'].src='images/mot7.gif';this.imgs['7_follow']=new Image();this.imgs['7_follow'].src='images/mot7_follow.gif';this.imgs['8']=new Image();this.imgs['8'].src='images/mot8.gif';this.imgs['8_follow']=new Image();this.imgs['8_follow'].src='images/mot8_follow.gif';this.imgs['9']=new Image();this.imgs['9'].src='images/mot9.gif';this.imgs['9_follow']=new Image();this.imgs['9_follow'].src='images/mot9_follow.gif';this.imgs['10']=new Image();this.imgs['10'].src='images/mot10.gif';this.imgs['10_follow']=new Image();this.imgs['10_follow'].src='images/mot10_follow.gif';this.imgs['11']=new Image();this.imgs['11'].src='images/mot11.gif';this.imgs['11_follow']=new Image();this.imgs['11_follow'].src='images/mot11_follow.gif';this.imgs['12']=new Image();this.imgs['12'].src='images/mot12.gif';this.imgs['12_follow']=new Image();this.imgs['12_follow'].src='images/mot12_follow.gif';this.imgs['99']=new Image();this.imgs['99'].src='images/mot99.gif';this.imgs['99_follow']=new Image();this.imgs['99_follow'].src='images/mot99_follow.gif';this.imgs['100']=new Image();this.imgs['100'].src='images/mot100.gif';this.imgs['100_follow']=new Image();this.imgs['100_follow'].src='images/mot100_follow.gif';this.imgs['100_arrival']=new Image();this.imgs['100_arrival'].src='images/mot100_arrival.gif';this.imgs['100_departure']=new Image();this.imgs['100_departure'].src='images/mot100.gif';this.imgs['poi']=new Image();this.imgs['poi'].src='images/pin.gif'
for(var method in MDVGadgetBase.prototype){if(!MDVMapEFATrips.prototype[method])MDVMapEFATrips.prototype[method]=MDVGadgetBase.prototype[method];};this.mdvMap.registerGadget(this);this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.execute);this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.update);this.mdvMap.events.registerEvent(MDVEvent_AJAX_CALLBACK,this,this.processTrip);};MDVMapEFATrips.prototype.execute=function(){if(this.layer==null){this.layer=this.mdvMap.createLayer('efa_trip');this.mdvMap.addLayer(this.layer);}};MDVMapEFATrips.prototype.loadTrip=function(sessionID,requestID,tripIndex){if(!this.mdvMap.config.get('tripURL')){this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'No tripURL specified.');return false;};var host=this.mdvMap.config.get('tripURL');var selector=('tripSelector'+tripIndex);var _params={language:'en',sessionID:sessionID,requestID:requestID,coordListOutputFormat:'STRING',command:'nop',tripSelection:'on',itdLPxx_mdvMap:'MDVMapEFATrips',itdLPxx_mdvMapName:this.mdvMap.getName()};_params[selector]='on';_params=$H(_params);_params=_params.toQueryString();var _ajax=new Ajax.Request(host,{method:'post',parameters:_params,onComplete:MDVMapEFATrips_onAjaxComplete});return true;};MDVMapEFATrips.prototype.processTrip=function(id,gName,efa){if(gName!='MDVMapEFATrips')return false;this.response=efa;var leg=null;if(this.response.trips.trip.legs.leg&&!this.response.trips.trip.legs.length){leg=this.response.trips.trip.legs.leg;}else if(this.response.trips.trip.legs.length){leg=this.response.trips.trip.legs[0];};var l=0;while(leg){var type=leg.mode.type;var colour=this.getLegColour(type);var pathStr=leg.path.replace(/\.00000/gi,'');this.polylines.push(this.mdvMap.createPolyline(pathStr));this.polylines[l].add('colour',colour);if(!this.polylines[l].markers['departure']){var coords=this.polylines[l].getCoords();var src;if(type==100&&this.imgs[type+"_departure"])src=this.imgs[type+"_departure"];else if(this.imgs[type])src=this.imgs[type];else src=this.imgs['stop'];this.polylines[l].markers['departure']=this.mdvMap.createMarker(coords[0],0.5,src.src);this.polylines[l].markers['departure'].mode=type;this.polylines[l].markers['departure'].point=leg.points[0];};if(!this.polylines[l].markers['arrival']){var coords=this.polylines[l].getCoords();var src;if(type==100&&this.imgs[type+"_arrival"])src=this.imgs[type+"_arrival"];else if(this.imgs[type])src=this.imgs[type];else src=this.imgs['stop'];this.polylines[l].markers['arrival']=this.mdvMap.createMarker(coords[coords.length-1],0.5,src.src);this.polylines[l].markers['arrival'].mode=type;this.polylines[l].markers['arrival'].point=leg.points[1];};this.polylines[l].leg=leg;this.layer.addPolyline(this.polylines[l],false);l++;leg=this.response.trips.trip.legs[l];};this.beautify();this.processMarkers();this.mdvMap.update();this.processPolylines();};MDVMapEFATrips.prototype.updateWizard=function(){var _polyline=this.polylines[0];for(var sp=0;sp<this.wizardScreenPlay.length;sp++)this.wizardScreenPlay.pop();if(_polyline.markers['departure']&&_polyline.markers['departure'].img&&_polyline.markers['departure'].img.toolTip){this.wizardScreenPlay.push({object:_polyline.markers['departure'],type:'marker',state:true,timeout:2000});this.wizardScreenPlay.push({object:_polyline.markers['departure'],type:'marker',state:false,timeout:10});this.wizardScreenPlay.push({object:_polyline,type:'polyline',state:true,timeout:10});};for(var p=1;p<this.polylines.length;p++){if(_polyline.markers['arrival']&&_polyline.markers['arrival'].img&&_polyline.markers['arrival'].img.toolTip){this.wizardScreenPlay.push({object:_polyline.markers['arrival'],type:'marker',state:true,timeout:2000});this.wizardScreenPlay.push({object:_polyline.markers['arrival'],type:'marker',state:false,timeout:100});var test='';};_polyline=this.polylines[p];if(_polyline.markers['departure']&&_polyline.markers['departure'].img&&_polyline.markers['departure'].img.toolTip){this.wizardScreenPlay.push({object:_polyline.markers['departure'],type:'marker',state:true,timeout:2000});this.wizardScreenPlay.push({object:_polyline.markers['departure'],type:'marker',state:false,timeout:100});var test='';};this.wizardScreenPlay.push({object:_polyline,type:'polyline',state:true,timeout:10});};if(_polyline.markers['arrival']&&_polyline.markers['arrival'].img&&_polyline.markers['arrival'].img.toolTip){this.wizardScreenPlay.push({object:_polyline.markers['arrival'],type:'marker',state:true,timeout:2000});this.wizardScreenPlay.push({object:_polyline.markers['arrival'],type:'marker',state:false,timeout:100});var test='';};return true;};MDVMapEFATrips.prototype.beautify=function(){var coords=this.mdvMap.getPolylineCoords();var x=coords[0];var y=coords[1];x.sort(MDVMap_NumSort);y.sort(MDVMap_NumSort);var width=x[x.length-1]-x[0];var height=y[y.length-1]-y[0];var newX=parseInt(x[0])+Math.floor(0.5+width/2);var newY=parseInt(y[0])+Math.floor(0.5+height/2);var centre=new MDVCoordinates(this.mdvMap.config.get('mapName'),newX,newY);var zoom=0;var extd=this.mdvMap.getViewportExtends();var zls=this.mdvMap.config.getZoomLevels();for(var i=zls.length-1;i>=0;i--){var zl=zls[i];var bWidth=false;var bHeight=false;var vpTiles=new MDVPoint(extd.width/zl.get('tileSizeX'),0.5+extd.height/zl.get('tileSizeY'));var numTiles=new MDVPoint(zl.get('numberOfTilesX'),zl.get('numberOfTilesY'));var realExtends=new MDVPoint(zl.get('realWidth'),zl.get('realHeight'));var tileSize=new MDVPoint(Math.floor(0.5+realExtends.x/numTiles.x),Math.floor(0.5+realExtends.y/numTiles.y));var real=new MDVPoint(tileSize.x*vpTiles.x,tileSize.y*vpTiles.y);if(real.x>(width*1.15)&&!bWidth){zoom=i;bWidth=true;};if(real.y>(height*1.15)&&!bHeight){zoom=i;bHeight=true;};if(bWidth&&bHeight)break;};this.mdvMap.setCentre(centre);this.mdvMap.setZoomLevel(zoom);};MDVMapEFATrips.prototype.processMarkers=function(){var sessionID=0;var requestID=0;for(var p=0;p<this.response.parameters.length;p++){if(this.response.parameters[p].name=='sessionID')sessionID=this.response.parameters[p].value;if(this.response.parameters[p].name=='requestID')requestID=this.response.parameters[p].value;};for(var p=0;p<this.polylines.length;p++){var polyline=this.polylines[p];this.markers.push(['departure',polyline.markers['departure']]);this.markers.push(['arrival',polyline.markers['arrival']]);};var map='';for(var m=0;m<this.markers.length;m++){var marker=this.markers[m];var deparr=m%2==0?'Abfahrt um ':'Ankunft um '
if(marker[1].point.links&&marker[1].point.links.link)map=marker[1].point.links.link.href;var text='<b>'+marker[1].point.name+'</b><br/>';text+=deparr+marker[1].point.dateTime.time;text+='<br><a href=\"XSLT_TRIP_REQUEST2?language=de&sessionID=';text+=sessionID+'&requestID='+requestID;text+=' &command=mapRequest&mapName='+map;text+='\" target=\"_blank\">PDF Karte</a>';map='';marker[1].setToolTip(this.mdvMap.createToolTip(text));this.layer.addMarker(marker[1],false);};this.origin=this.markers[0];this.destination=this.markers[this.markers.length-1];this.markers.sort(MDVMapEFATrips_PrioritySort);};MDVMapEFATrips.prototype.update=function(id,msg,obj){if(this.markers.length<=0||this.zoomLevel==obj.config.getZoomLevelIndex())return false;this.zoomLevel=obj.config.getZoomLevelIndex();for(var m=0;m<this.markers.length;m++){if(this.markers[m]&&this.markers[m][1])this.markers[m][1].visible=false;};this.origin[1].setVisibility(true);this.destination[1].setVisibility(true);for(var m=0;m<this.markers.length;m++){var current=this.markers[m];var value=true;for(var p=0;p<this.markers.length;p++){var previous=this.markers[p];if(previous[1].equals(current[1])||!previous[1].isVisible())continue;if(previous&&previous[1].isVisible()&&current[1].intersects(previous[1]))value=false;};if((this.origin&&current[1].equals(this.origin[1]))||(this.destination&&current[1].equals(this.destination[1])))value=true;current[1].setVisibility(value);};this.updateWizard();return true;};MDVMapEFATrips.prototype.processPolylines=function(){for(var l=0;l<this.polylines.length;l++){var polyline=this.polylines[l];var text='<b>'+polyline.leg.mode.name+'</b><br/>';if(polyline.leg.mode.destination)text+='Richtung '+polyline.leg.mode.destination+'<br/>';text+='Von '+polyline.leg.points[0].name+'<br/>';text+='Nach '+polyline.leg.points[1].name+'<br/>';var tooltip=this.mdvMap.createToolTip(text);polyline.setToolTip(tooltip,false);polyline.element.mdvMap=this.mdvMap;}};MDVMapEFATrips.prototype.getLegColour=function(type){if(this.mdvMap.config.get('motColour_'+type))return this.mdvMap.config.get('motColour_'+type);return '#FF0000';};MDVMapEFATrips.prototype.launchWizard=function(zoomLevel){if(this.polylines.length>0){if(zoomLevel>=0)this.mdvMap.setZoomLevel(zoomLevel);this.mdvMap.setCentre(this.polylines[0].getCoords()[0].clone());this.mdvMap.update();};this.wizardIndex=0;this.wizardJobID=mdvTimer.add(1,this,this.wizardRun,[null,null,null]);};MDVMapEFATrips.prototype.wizardRun=function(id,msg,obj){var _sp=this.wizardScreenPlay[this.wizardIndex];this.wizardIndex++;if(id==MDVEvent_ROUTE_TRACE_FINISHED)this.mdvMap.events.deregisterEvent(MDVEvent_ROUTE_TRACE_FINISHED,this,this.wizardRun);if(_sp){switch(_sp.type){case 'marker':_sp.object.img.toolTip.setVisibility(_sp.state);this.wizardJobID=mdvTimer.add(_sp.timeout,this,this.wizardRun,[null,null,null]);break;default:this.mdvMap.events.registerEvent(MDVEvent_ROUTE_TRACE_FINISHED,this,this.wizardRun);var coords=_sp.object.getCoords();var mrkr=null;if(_sp.object.leg.mode.type&&this.imgs[_sp.object.leg.mode.type+'_follow']&&this.imgs[_sp.object.leg.mode.type+'_follow'].complete)mrkr=this.imgs[_sp.object.leg.mode.type+'_follow'].src;this.wizardJobID=mdvTimer.add(_sp.timeout,this,this.wizardMoveBySeq,[coords,mrkr]);break;}}};MDVMapEFATrips.prototype.wizardMoveBySeq=function(coords,marker){this.mdvMap.moveBySeq(coords,marker);};function MDVMapEFATrips_onAjaxComplete(request){var efa;var mdvMapName='';eval('efa = '+request.responseText+';');for(var i=0;i<efa.parameters.length;i++){if(efa.parameters[i].name=='mdvMapName'){mdvMapName=efa.parameters[i].value;break;}};if(document.mdvMaps['mdvMap_'+mdvMapName])document.mdvMaps['mdvMap_'+mdvMapName].events.triggerEvent(MDVEvent_AJAX_CALLBACK,'MDVMapEFATrips',efa);};function MDVMapEFATrips_PrioritySort(a,b){return MDVMapEFATrips_GetPrority(a)-MDVMapEFATrips_GetPrority(b);};function MDVMapEFATrips_GetPrority(marker){if(marker[0]=='departure'&&marker[1].mode>0&&marker[1].mode<96)return 1;else if(marker[0]=='arrival'&&marker[1].mode>0&&marker[1].mode<96)return 2;else if(marker[0]=='departure'&&marker[1].mode>100)return 3;else if(marker[0]=='arrival'&&marker[1].mode>100)return 4;else if(marker[0]=='departure'&&marker[1].mode==100)return 5;else if(marker[0]=='arrival'&&marker[1].mode==100)return 6;else return 100;};function MDVMapContextMenu(mdvMap,contMenu){if(!mdvMap)return;this.name='MapContextMenu';this.mdvMap=mdvMap;this.mdvMap.registerGadget(this);this.mdvMap.events.registerEvent(MDVEvent_ZOOM_CHANGED,this,this.zoomLevelChange);this.contextMenu=contMenu;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;document.body.contextMenu=this;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;};this.contextMenu.div.oncontextmenu=function(){return false;};for(var method in MDVGadgetBase.prototype){if(!MDVMapContextMenu.prototype[method])MDVMapContextMenu.prototype[method]=MDVGadgetBase.prototype[method];}};MDVMapContextMenu.prototype.destroy=function(){if(this.mdvMap)this.mdvMap=null;for(var i=0;i<this.contextMenu.div.childNodes.length;i++){if(this.contextMenu.div.childNodes[i]&&this.contextMenu.div.childNodes[i].mdvMap){this.contextMenu.div.childNodes[i].mdvMap=null;}};this.ondblclick=null;this.onkeypress=null;this.onmousedown=null;this.onmousemove=null;this.onmouseout=null;this.onmouseover=null;this.onmouseup=null;this.onmousewheel=null;this.oncontextmenu=null;};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';this.contextMenu.div.style.left=x+'px';this.contextMenu.div.style.top=y+'px';this.contextMenu.div.style.display='block';var mousePoint=new MDVPoint(mX,mY);var mouseCoord=this.mdvMap.getCoordinates(mousePoint);this.mdvMap.events.triggerEvent(MDVEvent_CONTEXT_MENU,true,mouseCoord);return false;};MDVMapContextMenu.prototype.hideContextMenu=function(){this.contextMenu.div.style.display='none';this.mdvMap.events.triggerEvent(MDVEvent_CONTEXT_MENU,false,null);};MDVMapContextMenu.prototype.onmousedown=function(e){e=e?e:window.event;if(e==null||e.button!=2){this.hideContextMenu();};this.stopEvent(e);return false;};MDVMapContextMenu.prototype.zoomLevelChange=function(id,message,zoomLevelIndex){this.onmousedown(null);};function MDVMapMenu(menuItems){this.menuItems=menuItems;var menu=document.createElement("div");menu.className="mapContextMenu";document.body.appendChild(menu);menu.style.cursor='default';for(var i=0;i<this.menuItems.length;i++){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;var itemDescription=document.createTextNode(" "+this.menuItems[i].description+" ");item.appendChild(itemDescription);menu.appendChild(item);}else{var item=document.createElement("hr");menu.appendChild(item);}};function hideMenu(){menu.style.display='none';};this.div=menu;};function MDVMapMenuItem(description,func){this.description=description;if(func){this.func=func;}};function MDVMapControl(mdvMap){if(!mdvMap)return;this.name='MapControl';this.mdvMap=mdvMap;this.origin=null;this.zoomLevel=null;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();this.mapControl=null;this.arrowContainer=null;this.zoomContainer=null;this.mdvMap.registerGadget(this);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='images/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;this.images['zoomLevel_normal'].src=imgPath+'zoomLevelNormal.gif';this.images['zoomLevel_active'].src=imgPath+'zoomLevelActive.gif';this.images['zoomLevel_hover'].src=imgPath+'zoomLevelHover.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(){this.preloadImgs();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');this.mapControl=this.createDiv();this.mapControl.className='MDVMapControl';this.mdvMap.viewport.appendChild(this.mapControl);this.arrowContainer=this.createDiv();this.zoomContainer=this.createDiv();this.zoomContainer.className='MDVMapControl_ZoomLevels';this.zoomLevels=new Array();this.mapControl.appendChild(this.arrowContainer);this.mapControl.appendChild(this.zoomContainer);this.populateContainers();this.update();};MDVMapControl.prototype.destroy=function(){if(this.mdvMap)this.mdvMap=null;for(var row=0;row<this.arrowContainer.childNodes.length;row++){for(var div=0;div<this.arrowContainer.childNodes[row].childNodes.length;div++){for(var i=0;i<this.arrowContainer.childNodes[row].childNodes[div].childNodes.length;i++){if(this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].mdvMap){this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].mdvMap=null;};if(this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].normal){this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].normal=null;};if(this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].hover){this.arrowContainer.childNodes[row].childNodes[div].childNodes[i].hover=null;}}}};for(var row=0;row<this.zoomContainer.childNodes.length;row++){for(var i=0;i<this.zoomContainer.childNodes[row].childNodes.length;i++){var tmp=this.zoomContainer.childNodes[row].childNodes[i];tmp.onmouseover=null;tmp.onmouseout=null;tmp.onclick=null;tmp.hover=null;tmp.normal=null;if(tmp.mdvMap)tmp.mdvMap=null;}};this.ondblclick=null;this.onkeypress=null;this.onmousedown=null;this.onmousemove=null;this.onmouseout=null;this.onmouseover=null;this.onmouseup=null;this.onmousewheel=null;this.oncontextmenu=null;if(this.arrowContainer){this.arrowContainer.onmouseover=null;this.arrowContainer.onmouseout=null;this.arrowContainer.onclick=null;this.arrowContainer=null;};if(this.zoomContainer){this.zoomContainer.onmouseover=null;this.zoomContainer.onmouseout=null;this.zoomContainer.onclick=null;this.zoomContainer=null;};if(this.mapControl){this.mapControl.onmouseover=null;this.mapControl.onmouseout=null;this.mapControl.onclick=null;this.mapControl=null;}};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;var firstRow=this.createDiv();var secondRow=this.createDiv();var thirdRow=this.createDiv();this.arrowContainer.appendChild(firstRow);this.arrowContainer.appendChild(secondRow);this.arrowContainer.appendChild(thirdRow);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);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);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);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);var zoomIn=this.createDiv();zoomIn.className='MDVMapControl_Zoom';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);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);var zoomLevels=0;var zoomLevelArr=this.mdvMap.config.getZoomLevels();if(zoomLevelArr)zoomLevels=zoomLevelArr.length;for(var z=0;z<zoomLevels;z++){var level=zoomLevelArr[zoomLevels-z-1];if(level){var tmpZL=this.createDiv();tmpZL.className='MDVMapControl_ZoomLevel';tmpZLImg=this.createImage();tmpZLImg.level=level.level;tmpZLImg.hover=this.images['zoomLevel_hover'];tmpZLImg.normal=this.images['zoomLevel_normal'];tmpZLImg.src=this.images['zoomLevel_normal'].src;tmpZLImg.alt="1:"+level.getScale();tmpZLImg.title=tmpZLImg.alt;tmpZLImg.onclick=MDVMapControl_onclick;tmpZL.appendChild(tmpZLImg);this.zoomContainer.appendChild(tmpZL);this.zoomLevels.push(tmpZLImg);}};var zoomOut=this.createDiv();zoomOut.className='MDVMapControl_Zoom';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'].src;this.zoomLevels[i].hover=this.images['zoomLevel_active'];this.zoomLevels[i].normal=this.images['zoomLevel_active'];}else{this.zoomLevels[i].src=this.images['zoomLevel_normal'].src;this.zoomLevels[i].hover=this.images['zoomLevel_hover'];this.zoomLevels[i].normal=this.images['zoomLevel_normal'];}};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;};function MDVMapZoomBar(mdvMap){this.mdvMap=mdvMap;this.zoomBars=new Array();this.zoomImg=null;for(var method in MDVGadgetBase.prototype){if(!MDVMapZoomBar.prototype[method])MDVMapZoomBar.prototype[method]=MDVGadgetBase.prototype[method];};this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.preloadImgs);this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.update);};MDVMapZoomBar.prototype.preloadImgs=function(){if(this.zoomImg)return false;var zoomlevels=this.mdvMap.config.getZoomLevels();var serverURL='';if(this.mdvMap.config.get('serverURL'))serverURL=this.mdvMap.config.get('serverURL');else{this.mdvMap.events.triggerEvent(MDVEvent_ERROR,'MDVMap wasn\'t able to find serverURL.');return false;};for(var z=0;z<zoomlevels.length;z++){this.zoomBars[zoomlevels[z].level]=new Image();this.zoomBars[zoomlevels[z].level].src=serverURL+'zoomlevel'+zoomlevels[z].level+'/ZoomBar_'+zoomlevels[z].level+'.gif';};this.zoomImg=document.createElement('img');this.zoomImg.className='MDVMap_ScaleBar';this.zoomImg.src=this.zoomBars[this.mdvMap.config.getZoomLevelIndex()].src;this.mdvMap.viewport.appendChild(this.zoomImg);return true;};MDVMapZoomBar.prototype.update=function(){if(this.zoomBars[this.mdvMap.config.getZoomLevelIndex()]==null){this.mdvMap.events.triggerEvent(MDVEvent_WARNING,'MDVMap wasn\'t able to load appropriate zoom bar image.');this.zoomImg.style.visibility='hidden';return false;};this.zoomImg.style.visibility='visible';this.zoomImg.src=this.zoomBars[this.mdvMap.config.getZoomLevelIndex()].src;return true;};MDVMapZoomBar.prototype.destroy=function(){if(this.mdvMap)this.mdvMap=null;this.ondblclick=null;this.onkeypress=null;this.onmousedown=null;this.onmousemove=null;this.onmouseout=null;this.onmouseover=null;this.onmouseup=null;this.onmousewheel=null;this.oncontextmenu=null;for(var i=0;i<this.zoomBars.length;i++){this.zoomBars[i].onload=null;this.zoomBars[i].onerror=null;this.zoomBars[i].available=null;}};function MDVMapSync(mdvMap,mdvMiniMap){this.mdvMap=mdvMap;this.mdvMiniMap=mdvMiniMap;this.lastMap=null;this.lastMiniMap=null;for(var method in MDVGadgetBase.prototype){if(!MDVMapSync.prototype[method])MDVMapSync.prototype[method]=MDVGadgetBase.prototype[method];};this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.updateMiniMap);this.mdvMiniMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.updateMap);};MDVMapSync.prototype.updateMiniMap=function(id,msg,mdvMap){if(this.lastMiniMap&&this.lastMiniMap.centre.equals(mdvMap.getCentre())&&this.lastMiniMap.zoomLevel==mdvMap.config.getZoomLevelIndex())return false;this.mdvMiniMap.setCentre(mdvMap.getCentre().clone());this.mdvMiniMap.setZoomLevel(mdvMap.config.getZoomLevelIndex());this.lastMiniMap={centre:this.mdvMiniMap.getCentre(),zoomLevel:this.mdvMiniMap.config.getZoomLevelIndex()};return this.mdvMiniMap.update();};MDVMapSync.prototype.updateMap=function(id,msg,mdvMiniMap){if(this.lastMap&&this.lastMap.centre.equals(mdvMiniMap.getCentre())&&this.lastMap.zoomLevel==mdvMiniMap.config.getZoomLevelIndex())return false;this.mdvMap.setCentre(mdvMiniMap.getCentre().clone());this.mdvMap.setZoomLevel(mdvMiniMap.config.getZoomLevelIndex());this.lastMap={centre:this.mdvMap.getCentre(),zoomLevel:this.mdvMap.config.getZoomLevelIndex()};return this.mdvMap.update();};function MDVMapSyncBound(mdvMap,mdvMiniMap){for(var method in MDVMapSync.prototype){if(!MDVMapSyncBound.prototype[method])MDVMapSyncBound.prototype[method]=MDVMapSync.prototype[method];};this.mdvMap=mdvMap;this.mdvMiniMap=mdvMiniMap;this.lastMap=null;this.lastMiniMap=null;this.border=null;this.inner=null;this.mdvMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.updateMiniMap);this.mdvMiniMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.updateMap);this.mdvMiniMap.events.registerEvent(MDVEvent_MAP_INITIALISED,this,this.update);this.update();};MDVMapSyncBound.prototype.update=function(){if(!this.border){this.border=document.createElement('div');this.border.className='MDVMapSync_Outer';this.border.style.zIndex='150';this.border.style.position='absolute';this.inner=document.createElement('div');this.inner.className='MDVMapSync_Inner';this.border.appendChild(this.inner);this.mdvMiniMap.viewport.appendChild(this.border);};var tl=this.mdvMiniMap.getPoint(this.mdvMap.tlReal);tl=this.getAbsolutePoint(tl);this.border.style.left=tl.x+'px';this.border.style.top=tl.y+'px';var ext=this.mdvMap.getViewportRealExtends();ext=this.getExtends(ext);this.inner.style.width=ext.width+'px';this.inner.style.height=ext.height+'px';return true;};MDVMapSyncBound.prototype.getAbsolutePoint=function(point){var offset=new MDVPoint(parseInt(this.mdvMiniMap.mapper.style.left),parseInt(this.mdvMiniMap.mapper.style.top));point.x+=offset.x;point.y+=offset.y;return point;};MDVMapSyncBound.prototype.getExtends=function(ext){var zoomLevel=this.mdvMiniMap.config.getZoomLevel(this.mdvMiniMap.config.getZoomLevelIndex());var pxWidthAll=parseInt(zoomLevel.get('tileSizeX'))*parseInt(zoomLevel.get('numberOfTilesX'));var realToPxRatioWidth=pxWidthAll/parseInt(zoomLevel.get('realWidth'));var pxHeightAll=parseInt(zoomLevel.get('tileSizeY'))*parseInt(zoomLevel.get('numberOfTilesY'));var realToPxRatioHeight=pxHeightAll/parseInt(zoomLevel.get('realHeight'));var ext={width:Math.floor(0.5+(ext.width*realToPxRatioWidth)),height:Math.floor(0.5+(ext.height*realToPxRatioHeight))};return ext;};


