﻿/*=====================================================
  CONF
  =====================================================*/
    var user_id = 0;
    var xFactor = 100*72/2.54;
  
    var panRBack = "pan_R_B.gif";
    var panLBack = "pan_L_B.gif";
    var panNBack = "pan_N_B.gif";
    var panSBack = "pan_S_B.gif";
    var panNGfx = "pan_N_i.gif";
    var panEGfx = "pan_E_i.gif";
    var panSGfx = "pan_S_i.gif";
    var panWGfx = "pan_W_i.gif";
    var panNWGfx = "pan_NW_.gif";
    var panNWBackGfx = "pan_NW_Back.gif";
    var panNWHGfx = "pan_NW_H.gif";
    var panNWVGfx = "pan_NW_V.gif";
    var panNEGfx = "pan_NE_.gif";
    var panNEBackGfx = "pan_NE_Back.gif";
    var panNEHGfx = "pan_NE_H.gif";
    var panNEVGfx = "pan_NE_V.gif";
    var panSEGfx = "pan_SE_.gif";
    var panSEBackGfx = "pan_SE_Back.gif";
    var panSEHGfx = "pan_SE_H.gif";
    var panSEVGfx = "pan_SE_V.gif";
    var panSWGfx = "pan_SW_.gif";
    var panSWBackGfx = "pan_SW_Back.gif";
    var panSWHGfx = "pan_SW_H.gif";
    var panSWVGfx = "pan_SW_V.gif";
   
    //Graphics folder
    var gfxFolderZoom = "./Images/Zoom/";
    var gfxFolderPan = "./Images/Pan/panNew/";
     
    //Zoom controls 
    var zoombarInWidth = 23;
    var zoombarOutWidth = 23;
    var zoombarInHeight = 18;
    var zoombarOutHeight = 18;
    var zoombarBackWidth = 23;
    var zoombarBackHeight = 10 * 13; //numbers of zoomlevels * height of zoombarBack graphic
    var zoombarHandlerWidth = 19;
    var zoombarHandlerHeight = 9;
    var zoombarInSrc = "zoombarPlus.gif";
    var zoombarBackSrc = "zoombarBack2.gif";
    var zoombarOutSrc = "zoombarMin.gif";
    var zoombarHandlerSrc = "zoomHandle.gif";

    //Pan controls
    var panHorizWidth = 79;
    var panHorizHeight = 10;
    var panVertWidth = 10;
    var panVertHeight = 79;
    var panBackHorizWidth = 1;
    var panBackHorizHeight = 10;
    var panBackVertWidth = 10;
    var panBackVertHeight = 1;
    var panBackCornerWidth_Height = 11;
    var panArrowsWidth_Height = 7;    
    /**************************************************/
    /* Localization                                   */
    /**************************************************/
    /**** Generel. DK er default ****/
    var f_zoomPlus = "Zoom ind";    
    var f_zoomMinus = "Zoom ud";
    
    var f_panVest = "Vest";
    var f_panNordVest = "Nordvest";
    var f_panNord = "Nord";    
    var f_panNordOest = "Nordøst";
    var f_panOest = "Øst";
    var f_panSydOest = "Sydøst";
    var f_panSyd = "Syd";
    var f_panSydVest = "Sydvest";
    
    /*=====================================================
      f_localization
      
      Sets language dependent texts. "dk" (=dansk) is default
      Sets zoomLevel options
      Possible values for language parameter: "dk", "se" og "no"
      =====================================================*/
    FoliaMap.prototype.f_localization = function(language) {

        if (language == null || language == "" || !(language == "dk" || language == "se" || language == "no")) {
            language = "dk";
        }
            
        this.zLevelsLocator = new Array(2594,6477,12960,30813,130394,482202,1090772,3823134,9243780,32314961);        

        if (language == "dk") {
            this.zLevels = new Array(2594,6477,12960,30813,130394,482202,1090772,3823134);
        } else if (language == "se") {
            f_zoomPlus = "Zooma in";
            f_zoomMinus = "Zooma ut";
            
            f_panNord = "Norr";    
            f_panNordOest = "Nordöst";
            f_panOest = "Öst";
            f_panSydOest = "Sydöst";
        
            this.zLevels = new Array(2594,6477,12960,30813,130394,482202,1090772,2773134,9243780,32314961);                             
        }
        else if (language == "no") {
            f_zoomPlus = "Zoom inn";
            f_zoomMinus = "Zoom ut";    
              
            f_panSydOest = "Sørøst";
            f_panSyd = "Sør";
            f_panSydVest = "Sørvest";
            
            //this.zLevels = new Array(458,1142,2286,5435,23000,85054,192400,489150,1630500);                                                 
            this.zLevels = new Array(2594,6477,12960,30813,130394,482202,1090772,2773134,9243780,32314961);                                                 
        }
        
    }//f_localization
  
    
    Function.prototype.bind = function(obj) {
        var methods = this, temp = function() {
            return methods.apply(obj, arguments);
        }
        return temp;
    }//bind

/*=====================================================
  FOLIAMAP OBJECT
  =====================================================*/

    function FoliaMap(xmin, ymin, xmax, ymax, mapwidth, mapheight, mapstyle, mapdiv, mapuser, mappasswd, language, page, usemastertile) {

        if(arguments.length == 13 && usemastertile == false) {
            this.usemastertile = false;
        } else {
            this.usemastertile = true;
        }       
        
        this.page = page;
        this.showScalebar = false;
        this.f_localization(language); //"dk" er default
        
        //set loadimg
        this.loadimg = this.gfxPath + this.loadimg;
        //cache loadimg
        var loadimg = new Image();
        loadimg.src = this.loadimg;

        this.mapwidth = mapwidth;
        this.mapheight = mapheight;

        //create POI object
        this.POIenabled = new Object();
        
        //set the map user id
        this.userId = user_id;

        //set the map user
        this.fUsername = mapuser;
        this.fPassword = mappasswd;

        //zoom level
        this.zLevel = 0;

        //get unique identifier for this map object used when naming divs in DOM
        this.name = mapdiv + "_";

        //set div names used in DOM
        this.mapdiv = mapdiv;
        this.x0y0 = document.createElement("img");
        //create main divs
        this.mapControls = document.createElement("div");
        this.mapControls.setAttribute("id",this.name + "mapControls");
        this.addEventHandler(this.mapControls, "click", function () {return false;});

        //add navbox
        this.navbox = document.createElement("div");
        this.navbox.setAttribute("id",this.name + "navbox");
        this.navbox.style.width = mapwidth + "px";
        this.navbox.style.height = mapheight+ "px";
        this.navbox.style.position = "absolute";
        this.navbox.style.top = "0px";
        this.navbox.style.left = "0px";
        this.navbox.style.zIndex = "1";
        this.navbox.style.overflow = "hidden";
        this.mapControls.appendChild(this.navbox);

        //add actionLayer
        this.actionLayer = document.createElement("div");
        this.actionLayer.setAttribute("id",this.name + "actionLayer");
        this.actionLayer.style.backgroundImage = "url('" + this.gfxPath + "1x1_transparent.gif')";
        this.actionLayer.style.position = "absolute";
        this.actionLayer.style.top = "0px";
        this.actionLayer.style.left = "0px";
        this.actionLayer.style.zIndex = "10";

        this.addEventHandler(this.actionLayer, "mousedown", this.moveActivate.bind(this));
        this.addEventHandler(this.actionLayer, "mousemove", this.moveMap.bind(this));
        //this.addEventHandler(this.actionLayer, "mousemove", this.registerMouseMove.bind(this));
        //this.addEventHandler(this.actionLayer, "mousemove", this.display.bind(this));
        this.addEventHandler(this.actionLayer, "mouseup", this.moveDeActivate.bind(this));
        this.addEventHandler(this.actionLayer, "dblclick", this.setCenterZoom.bind(this));
        this.mapControls.appendChild(this.actionLayer);

        //add mapbox
        this.mapbox = document.createElement("div");
        this.mapbox.setAttribute("id",this.name + "mapbox");
        this.mapbox.style.position = "absolute"; 
        this.mapbox.style.top = "0px"; 
        this.mapbox.style.left = "0px"; 
        this.mapbox.style.zIndex = "0"; 
        this.addEventHandler(this.mapbox, "mouseup", this.moveDeActivate.bind(this));
        this.navbox.appendChild(this.mapbox);

        try {     
            document.getElementById(mapdiv).appendChild(this.mapControls);
            this.mapholder = document.getElementById(mapdiv);
        } catch(e) {
            this.mapholder = document.createElement("div");
            this.mapholder.setAttribute("id",mapdiv);
            document.body.appendChild(this.mapholder);
            this.mapholder.appendChild(this.mapControls);
        }//try catch

        this.addEventHandler(this.mapholder, "mouseout", this.mapholderOut.bind(this));
        this.mapholder.style.width = mapwidth + "px";
        this.mapholder.style.height = mapheight+ "px";

        //calculate and set mapsize:
        this.displayWidth = mapwidth > mapheight ? mapwidth : mapheight;
        this.displayHeight = this.displayWidth;

        this.displaySize = Math.ceil ( this.displayWidth / this.tileSize );

        this.themeLayer = document.createElement("div");
        this.themeLayer.style.position = "absolute";
        this.themeLayer.style.top = "0px";
        this.themeLayer.style.left = "0px";
        this.themeLayer.setAttribute("id",this.name + "themeLayer");
        //this.actionLayer.appendChild(this.themeLayer);
        this.actionLayer.appendChild(this.themeLayer);
        

        this.themeIb = document.createElement("div");
        this.themeIb.style.position = "absolute";
        this.themeIb.style.top = "0px";
        this.themeIb.style.left = "0px";
        this.themeIb.style.zIndex = "107";
        this.themeIb.setAttribute("id",this.name + "themeIb");
        //this.actionLayer.appendChild(this.themeLayer);
        this.mapholder.appendChild(this.themeIb);

        this.setMapStyle(mapstyle);
        
        this.masterTileSize = this.displaySize * this.tileSize;

        this.x0y0.setAttribute("id",this.name + "x0y0");

        if (window.addEventListener)
            this.actionLayer.addEventListener('DOMMouseScroll', this.wheel.bind(this), false);
        this.actionLayer.onmousewheel = this.wheel.bind(this);
        
        this.mapControls.style.width = mapwidth + "px";
        this.mapControls.style.height = mapheight + "px";
        this.mapControls.style.overflow = "hidden";
        this.mapbox.style.width = this.mapbox.style.height = this.masterTileSize + "px";
        this.actionLayer.style.width = this.actionLayer.style.height = this.masterTileSize + "px";

        if(this.usemastertile) this.x0y0.style.width = this.x0y0.style.height = this.masterTileSize + "px";

        this.setBBox(xmin, ymin, xmax, ymax);

        if ( this.usemastertile ) {
            this.x0y0.src = this.buildUrl(this.bbox.ix, this.bbox.iy, this.bbox.ex, this.bbox.ey, this.masterTileSize);            
            this.x0y0.style.position = "absolute"; 
            this.x0y0.style.top = "0px"; 
            this.x0y0.style.left = "0px"; 
            this.mapbox.appendChild(this.x0y0);
        }//if

        //Center map in viewport
        var cTop = parseInt((mapheight - parseInt(this.mapbox.style.height)) / 2);
        var cLeft = parseInt((mapwidth - parseInt(this.mapbox.style.width)) / 2);
        this.mapbox.style.top = this.themeLayer.style.top = this.themeIb.style.top = (parseInt(this.mapbox.style.top) + cTop) + "px";
        this.mapbox.style.left = this.themeLayer.style.left = this.themeIb.style.left = (parseInt(this.mapbox.style.left) + cLeft) + "px";

        this.noOfTilesLoaded = 0;

        this.tiles = new Object();

        //register unused tiles:
        if ( this.usemastertile ) {
            for( var xval = 0; xval < this.displaySize; xval ++ ) {
                for( var yval = 0; yval < this.displaySize; yval ++ ) {
                    this.tiles[this.name + xval + "," + yval] = 1;
                }//for
            }//for
        } else {
            for( var xval = 0; xval < this.displaySize; xval ++ ) {
                for( var yval = 0; yval < this.displaySize; yval ++ ) {
                    this.addTile(xval,yval);
                }//for
            }//for
        }//if/else
        
        this.FAddCopyrightLabel(this.mapControls,this.mapwidth-122,9);
        
        this.updateBBox();
        

	if ( this.name.indexOf("locator") == -1 ) {
          this.enableRightClick();
	}
        
        this.doWheelZoom = true;

        //set default value for POIs on zoom
        this.hidePOIonZoom = false;

        //set initial values for tile offset in order to force tileload
        this.xTileBeginP = -1;
        this.yTileBeginP = -1;
        
    }//FoliaMap


    FoliaMap.prototype.enableRightClick = function() {
    
    	var body;
			if ( this.name == this.mapdiv + "_" ) {
				body = this.mapholder;
			} else {
        body = document;
      }
			try {
        this.showrcmenu = false;
        body.oncontextmenu=new Function("if(!this.showrcmenu) {this.setCenterZoomout();return false;}").bind(this);
			} catch(e) {

			}
    }//enableRightClick

    
    FoliaMap.prototype.mapholderOut = function(e) {

        if ( !e ) var e = window.event;
        var body = document.getElementsByTagName("body")[0];
        var p = e.target ? e.target : e.srcElement;

        var x = this.getCoord(e).x;
        var y = this.getCoord(e).y;

        var ix = this.getElementPosition(this.mapholder).x;
        var iy = this.getElementPosition(this.mapholder).y;
        var ex = ix + parseInt(this.mapholder.style.width);
        var ey = iy + parseInt(this.mapholder.style.height);



        if( ix >= x || x >= ex || iy  >= y || y >= ey ) {
            //debug(ix + " >= " + x + " >= " + ex +" og " + iy + " >= " + y + " >= " + ey);
            this.moveDeActivate();
            try {
                this.searchBoxUnsetHandle();
            } catch(ex) {} 
        }//if

    }//mapholderOut

    //FIXME
    FoliaMap.prototype.enableTileLoad = function(key) {
        switch ( key ) {
            case "all":
                this.display(false,parseInt(this.mapbox.style.left),parseInt(this.mapbox.style.top));
            case "zoom":
                this.tileLoadEnabled = true;
                break;
        }
    }


    FoliaMap.prototype.setZLevels = function(zLevels) {
        this.zLevels = zLevels;
    }


    FoliaMap.prototype.moveMap = function(e) {
        if (!e) e = window.event;
        this.registerMouseMove(e);
        this.display(e);
    }//moveMaps


    FoliaMap.prototype.registerBodyEvents = function () {
			var body;
			if ( this.name == this.mapdiv + "_" ) {
				body = this.mapholder;
			} else {
        body = document.getElementsByTagName("body")[0];
      }
			try {
					body.attachEvent('onselectstart',function() {return false;} );
			} catch(e) {

			}
    }//registerBodyEvents

/*=====================================================
  PROTOTYPE VARIABLES
  =====================================================*/
    FoliaMap.prototype.tileSize = 250;
    FoliaMap.prototype.gfxPath = "./Images/Boligsiden/";
    FoliaMap.prototype.horizon = 0;
    //mapbox offset
    FoliaMap.prototype.xMapbox = 0;
    FoliaMap.prototype.yMapbox = 0;
    
    FoliaMap.prototype.zLevels = new Array();

    //cursor offset
    FoliaMap.prototype.xOffset = 0;
    FoliaMap.prototype.yOffset = 0;

    FoliaMap.prototype.xTileBeginP = 0;
    FoliaMap.prototype.yTileBeginP = 0;

    FoliaMap.prototype.loadimg = "load.png";
    FoliaMap.prototype.mapPanPct = 20;

/*=====================================================
  UTILITIES SECTION
  =====================================================*/


    /**
     * Updates the boundary box defined by the viewport position - initiated on map pan
     **/
    FoliaMap.prototype.updateBBox = function () {

        if(! this.bbox ) this.bbox = new Object();
        if(! this.bbox.current ) this.bbox.current = new Object();

        var xpos = parseInt(this.mapbox.style.left);
        var ypos = parseInt(this.mapbox.style.top);

        this.bbox.current.ix = ( this.bbox.ix - Math.round(xpos * this.bbox.rel) );
        this.bbox.current.iy = Math.round((this.masterTileSize + (ypos - parseInt(this.navbox.style.height))) * this.bbox.rel) + this.bbox.iy;
        this.bbox.current.ex = this.bbox.current.ix + Math.round(parseInt(this.navbox.style.width) * this.bbox.rel);
        this.bbox.current.ey = this.bbox.current.iy + Math.round(parseInt(this.navbox.style.height) * this.bbox.rel);

    }//updateBBox

    /**
     * Sets the initial boundary box coordinates.
     * @param integer xmin - the minor x UTM coordinate
     * @param integer ymin - the minor y UTM coordinate
     * @param integer xmax - the major x UTM coordinate
     * @param integer ymax - the major y UTM coordinate
     * @return void
     * @access private
     **/
    FoliaMap.prototype.setBBox = function ( xmin, ymin, xmax, ymax ) {
        var xdiff = xmax - xmin;
        var ydiff = ymax - ymin;
        
        this.zLevel = this.getZoomlevel(xmin, ymin, xmax, ymax, this.masterTileSize);

        var addx = Math.round((this.masterTileSize/2)*(this.zLevelsLocator[this.zLevel]/xFactor));
        var addy = Math.round((this.masterTileSize/2)*(this.zLevelsLocator[this.zLevel]/xFactor));

        if ( ! this.bbox ) this.bbox = new Object();
        
        this.bbox.centerx = xmin + Math.round(xdiff/2);
        this.bbox.centery = ymin + Math.round(ydiff/2);

        this.bbox.ix = this.bbox.centerx - addx; 
        this.bbox.iy = this.bbox.centery - addy;
        this.bbox.ex = this.bbox.centerx + addx;
        this.bbox.ey = this.bbox.centery + addy;
   
        this.bbox.rel = this.zLevelsLocator[this.zLevel]/xFactor;
        
        // Taget væk af Jacob d. 11/2 2008
        //this.updateBBox();        
        // Taget væk...

    }//FoliaMap.prototype.setBBox


    FoliaMap.prototype.setMapStyle = function ( mapstyle ) {

            try {
                document.getElementById(this.name + "mapClassicBtn").src = this.gfxPath + "classicbtn.gif";
                document.getElementById(this.name + "mapOrthoBtn").src = this.gfxPath + "orthobtn.gif";
                document.getElementById(this.name + "mapCombiBtn").src = this.gfxPath + "combibtn.gif";
                document.getElementById(this.name + "mapPictometryBtn").src = this.gfxPath + "pictometry.gif";         
            } catch(e) {
                //void - the control doesn't exist yet
            }

            // highlight selected button
            switch (mapstyle) {
                 case "ortho":
                    this.imageType = "JPG";
                    this.fMtwstyle = 250;
                    try { document.getElementById(this.name + "mapOrthoBtn").src = this.gfxPath + "orthobtnOn.gif";} catch(e) {}
                    break;
                case "combi":
                    this.imageType = "JPG";
                    this.fMtwstyle = 240;
                    try { document.getElementById(this.name + "mapCombiBtn").src = this.gfxPath + "combibtnOn.gif";} catch(e) {}
                    break;                   
                case "pictometry":
                    this.imageType = "JPG";
                    this.fMtwstyle = 510;
                    try { document.getElementById(this.name + "mapPictometryBtn").src = this.gfxPath + "pictometryOn.gif";} catch(e) {}
                    break;     
                case "classic":
                default:
                    this.imageType = "PNG";
                    this.fMtwstyle = 230; //classic
                    try { document.getElementById(this.name + "mapClassicBtn").src = this.gfxPath + "classicbtnOn.gif";} catch(e) {}
            }//switch
            
            this.setCopyrightText();
          
    }//FSetMapStyle  


    /**
     * Build a map image url
     * @param integer boxIX
     * @param integer boxIY
     * @param integer boxEX
     * @param integer boxEY
     * @param integer size
     **/
     var imgNo = 0;
    FoliaMap.prototype.buildUrl = function (boxIX, boxIY, boxEX, boxEY, size) {
        
        var url = "";
        if (this.fMtwstyle >= 500 && this.fMtwstyle <= 599 ) {
            url = "http://demo.maptoweb.dk/fms_PictometryDemo/map.aspx?VERSION=1.3&REQUEST=GetMap&map_I1=F*0*0&"        
        }
        else {
            url = "http://www.maptoweb.dk/fms/map.aspx?VERSION=1.3.0&REQUEST=GetMap&";
            //url = "http://10.0.0.240/fms-php/map.php?";
            //url = "http://demo.maptoweb.dk/fms_PictometryDemo/map.aspx?VERSION=1.3&REQUEST=GetMap&map_I1=F*0*0&"        

        }
            
        url += "BBOX=" + boxIX + "," + boxIY + "," + boxEX + "," + boxEY + "&";
        url += "LAYERS=POI,ROUTENO&FORMAT=" + this.imageType + "&";
        url += "HEIGHT=" + size + "&WIDTH=" + size + "&";
        url += "mtwSTYLE=" + this.fMtwstyle + "&u=" + this.fUsername + "&mtwUSER=" + this.fUsername;
        //var d = new Date();
        //url = "http://www.maptoweb.dk/danbolig/kort.png?"+d.getSeconds() + "," + d.getMilliseconds() + boxIX;
            
        return url;
    }//buildUrl

    FoliaMap.prototype.buildBoligsidenStartUrl = function (boxIX, boxIY, boxEX, boxEY, size) {
        var url = "http://www.maptoweb.dk/fms/map.aspx?VERSION=1.3.0&REQUEST=GetMap&";
            url += "BBOX=" + boxIX + "," + boxIY + "," + boxEX + "," + boxEY + "&";
            url += "LAYERS=POI,ROUTENO&FORMAT=" + this.imageType + "&";
            url += "HEIGHT=" + size + "&WIDTH=" + size + "&";
            url += "mtwSTYLE=230" + "&u=" + this.fUsername + "&mtwUSER=" + this.fUsername;

        return url;
    }//buildUrl

    FoliaMap.prototype.getElementPosition = function(o) {
        try {
            var element_id = o.getAttribute("id");
        } catch(e) {
            var element_id = false;
        }

        var cache = arguments.length == 2 ? false : true;
        if ( !this.elementpositioncache ) this.elementpositioncache = new Object();

        if ( element_id && this.elementpositioncache[element_id] && cache) {
            return this.elementpositioncache[element_id];
        }
 
        var pos = new Object()
        pos.x = pos.y = 0;
        if (o.offsetParent) {
            pos.x = o.offsetLeft
            pos.y = o.offsetTop
            while (o = o.offsetParent) {
                pos.x += o.offsetLeft
                pos.y += o.offsetTop
            }//while
        }//if

        if( cache && element_id) this.elementpositioncache[element_id] = pos;

        return pos;

    }//if



    //Modyfied function from quirksmode
    FoliaMap.prototype.getCoord = function(e) {
        var pos = new Object();
            pos.x = 0;
            pos.y = 0;

        if (!e) var e = window.event;

        if (e.pageX || e.pageY) {
            pos.x = e.pageX;
            pos.y = e.pageY;
        }

        else if (e.clientX || e.clientY)    {
            pos.x = e.clientX + document.body.scrollLeft
                + document.documentElement.scrollLeft;
            pos.y = e.clientY + document.body.scrollTop
                + document.documentElement.scrollTop;
        }//else if
        return pos;
    }//getCoord


    FoliaMap.prototype.getMousePos = function(o,e) {
        var pos = new Object();
        var ep = this.getElementPosition(document.getElementById(o));
        var X = this.getCoord(e).x;
        var Y = this.getCoord(e).y;
        pos.x = (X - ep.x);
        pos.y = (Y - ep.y);
        return pos;
    }//getMousePos


    FoliaMap.prototype.addEventHandler = function(obj,eventname, functionname) {
        try {
            obj.addEventListener(eventname,functionname, true);
        } catch(e) {
            obj.attachEvent('on' + eventname,functionname);
        }
    } //addEventHandler


    FoliaMap.prototype.registerMouseMove = function (e) {        
        this.mx = this.getMousePos(this.actionLayer.getAttribute("id"),e).x;
        this.my = this.getMousePos(this.actionLayer.getAttribute("id"),e).y;
    } //registerMouseMove


    FoliaMap.prototype.changeMapStyle = function(mapstyle) {
        this.setMapStyle(mapstyle);
        this.setZoomLevel(this.zLevel, this.displayWidth/2, this.displayHeight/2);
    }//changeMapStyle

/*=====================================================
  ZOOM SECTION
  =====================================================*/

    /**
     *Event handler for mouse wheel event.
     **/
     
    var doWheelZoom = true;
     
    FoliaMap.prototype.wheel = function(event){
    
        if (!this.zoomAnimate) {
        
            //this.x0y0.style.display = "none";           

            //prevent scrollzoom on locatormap
            if ( this.parentmap ) return false;

            var delta = 0;
            if (!event) /* For IE. */
                    event = window.event;
            if (event.wheelDelta) { /* IE/Opera. */
                    delta = event.wheelDelta/120;
                    /** In Opera 9, delta differs in sign as compared to IE.
                     */
                    if (window.opera)
                            delta = -delta;
            } else if (event.detail) { /** Mozilla case. */
                    /** In Mozilla, sign of delta is different than in IE.
                     * Also, delta is multiple of 3.
                     */
                    delta = -event.detail/3;
            }

            if (delta)
                    this.handle(delta,event);

            if (event.preventDefault)
                    event.preventDefault();
            event.returnValue = false;
        
            this.doWheelZoom = false;
            
            //doWheelZoom = false;
            
            //setTimeout("doWheelZoom = true",200);
        }//if
        
    }//FoliaMap.prototype.wheel

    /** 
     * This is high-level function.
     * It must react to delta being more/less than zero.
     **/
    FoliaMap.prototype.handle = function (delta,event) {

        if ( this.hidePOIonZoom ) this.themeLayer.style.display = "none";

        var zLevelOld = this.zLevel;
        if (delta < 0) {
            if( this.zLevel < ( this.zLevels.length - 1) ) {
                this.zLevel++;
                this.setZoomLevel(zLevelOld);
                //grow(50);
            }
        } else {

            if ( this.zLevel > 0 ) {
                this.zLevel--;
                this.setZoomLevel(zLevelOld);
                //schrink(50);
            }
        }//else

    }//handle
  
   FoliaMap.prototype.moveActivate = function(e) {
        if ( !this.DAPan ) {
            var ep = this.getElementPosition(this.navbox);
            //this.actionLayer.style.cursor = "./Images/Pan/panClosed.cur";
            this.actionLayer.style.cursor = "url('./Images/Pan/panClosed.cur'), -moz-grabbing";
            this.moveactive = true;
            var X = this.getCoord(e).x;
            var Y = this.getCoord(e).y;
            
            this.panPosXstart = this.mx;
            this.panPosYstart = this.my;
            
            this.xOffset = X - ep.x;
            this.yOffset = Y - ep.y;
            
            this.xMapbox = this.mapbox.offsetLeft;
            this.yMapbox = this.mapbox.offsetTop;

            if ( this.parentmap ) {
                this.parentmap.xMapbox = this.parentmap.mapbox.offsetLeft;
                this.parentmap.yMapbox = this.parentmap.mapbox.offsetTop;
            }

            if ( this.locator ) {
                this.locator.xMapbox = this.locator.mapbox.offsetLeft;
                this.locator.yMapbox = this.locator.mapbox.offsetTop;
            }

        }
    }//moveActivate

    FoliaMap.prototype.moveDeActivate = function(e) {
        
        this.actionLayer.style.cursor = "url('./Images/Pan/panOpen.cur'), -moz-grab";

        this.panPosXend = this.mx;
        this.panPosYend = this.my;
                        
        //debug(this.panPosXend + ', ' + this.panPosYend);

        if ( this.parentmapOffset ) delete this.parentmapOffset;
        if ( this.locatormapOffset ) delete this.locatormapOffset;
        
        if (this.moveactive == true) {
            try { this.panStopped(); } catch (ex) { }
            
            //this.logPanAction();
            
            //Ændret af Jacob - Hele If sætningen
            //Hvis det er locator'en som der er lavet panstop i
            if (this.name.indexOf("locator") != -1) {
                
                
                var ep = this.getElementPosition(this.navbox);

                var X = this.getCoord(e).x;
                var Y = this.getCoord(e).y;

                //Hvor meget skal der flyttes
                var xMoveby = (X - ep.x) - this.xOffset;
                var yMoveby = (Y - ep.y) - this.yOffset;
                
                this.parentmap.xOffset = 0;
                this.parentmap.yOffset = 0;
                
                //Find den nye position for kortets top og left
                var xNewPos = this.xMapbox + xMoveby;
                var yNewPos = this.yMapbox + yMoveby;
                
                var xv = Math.round( (xMoveby * this.bbox.rel) / this.parentmap.bbox.rel );
                var yv = Math.round((yMoveby * this.bbox.rel)/ this.parentmap.bbox.rel);
                this.parentmap.display(false,xv,yv);
            }
        }

        this.moveactive = false;
         
    }//moveDeActivate

    FoliaMap.prototype.setZoomLevel = function(zLevelOld) {
        //this.saveZoomMapLog();
        
        this.updateBBox();
        
        this.zLevelOld = zLevelOld;
                    
        //hooks for user defined actions on zoom
        if (this.zLevel > zLevelOld) {
            try { zoomOut_event(); } catch(e) {}
        } else {
            try { zoomIn_event(); } catch(e) {}
        }//else

        //if mx and my is explicit
        if(arguments.length > 1) {
            var m_x = arguments[1];
            var m_y = arguments[2];
        } else {
            var m_x = this.mx;
            var m_y = this.my;
        }//if             
        
       
        // Old and new meter pr pixel values
        var old_meter_pr_pixel = this.zLevels[zLevelOld]/xFactor;
        var new_meter_pr_pixel = this.zLevels[this.zLevel]/xFactor;
        
        // Mouseposition in geocoordinates (UTM)
        var m_x_utm = this.bbox.current.ix + Math.round(m_x*old_meter_pr_pixel);
        var m_y_utm = this.bbox.current.ey - Math.round(m_y*old_meter_pr_pixel);
               
        // Calculate new bounding box in geocoordinates (UTM)       
        this.bbox.ix = m_x_utm - Math.round(m_x*new_meter_pr_pixel);
        this.bbox.iy = m_y_utm - Math.round((this.masterTileSize - m_y)*new_meter_pr_pixel);
        this.bbox.ex = m_x_utm + Math.round((this.masterTileSize - m_x)*new_meter_pr_pixel);
        this.bbox.ey = m_y_utm + Math.round(m_y*new_meter_pr_pixel); 

        this.bbox.rel = new_meter_pr_pixel;

        if (this.usemastertile) {
            this.zImage = new Image();
            this.zImage.src = this.buildUrl(this.bbox.ix,this.bbox.iy,this.bbox.ex,this.bbox.ey,this.masterTileSize);
        }
        else {
            this.preloadTiles();
        }
        
        this.zoomAnimate = true;
        
        this.preZoom(zLevelOld,this.zLevel,m_x,m_y);

        this.redrawPOI();

        this.resetMap();

        this.setZoomSlider(this.zLevel);
                
        this.setCopyrightText();
        
        this.scaleBar();

    }//setZoomLevel
    
    FoliaMap.prototype.getZoomlevel = function ( xmin, ymin, xmax, ymax, mappixelwidth ) {
        var dpc = 72/2.54;
        var mapGeoWidth = xmax - xmin;
        var mapGeoHeight = ymax - ymin;
        var scaleX = mapGeoWidth/(this.mapwidth+1);
        var scaleY = mapGeoHeight/(this.mapheight+1);
        var scale = scaleX>scaleY ? scaleX : scaleY;
        scale *= 100*dpc;
        var mapFileLevel = 0;
        while ( mapFileLevel<this.zLevels.length && scale > this.zLevels[mapFileLevel]) mapFileLevel++;
        //Ændret af Jacob - Nedenstående linje
        if (mapFileLevel == this.zLevels.length && this.name.indexOf("locator") == -1) { mapFileLevel = this.zLevels.length-1 }
        return mapFileLevel;
    }
    
//    FoliaMap.prototype.getZoomlevel = function ( xmin, ymin, xmax, ymax, mappixelwidth ) {
//        var mapGeoWidth = xmax - xmin;
//        var dpc = 72/2.54;
//        var mapWidth_cm = mappixelwidth/dpc;
//        var mapScale = mapGeoWidth *100 /mapWidth_cm;
//        var mapFileLevel = this.zLevels.length;
//        var mapFileLevelBorder=0;

//        for (var i = mapFileLevel-1; i>=0; i--) {
//            mapFileLevelBorder = (this.zLevels[i] + this.zLevels[i-1])/2;
//            if (mapScale < mapFileLevelBorder) {
//                mapFileLevel = i;
//            }
//        } 
//        return mapFileLevel;
//    }
    

    FoliaMap.prototype.preZoom = function(zLO,zL,m_x,m_y) {

        //get new tile width
        var scale = this.zLevels[zLO] / this.zLevels[zL];

        //fetch tile
        var xpos = Math.floor((m_x - parseInt(this.mapbox.style.left)) / this.tileSize);
        var ypos = Math.floor((m_y - parseInt(this.mapbox.style.top)) / this.tileSize);


        //fetch tiles current position
        if ( this.tiles[this.name + xpos + "," + ypos] == 1 ) {

            xpos = 0;
            ypos = 0;

            var newTileWidth = scale * this.masterTileSize;

            //fetch mouse position in tile
            var xpospx = (m_x - parseInt(this.mapbox.style.left)) - Math.floor((m_x - parseInt(this.mapbox.style.left)) / this.masterTileSize) * this.masterTileSize;
            var ypospx = (m_y - parseInt(this.mapbox.style.top)) - Math.floor((m_y - parseInt(this.mapbox.style.top)) / this.masterTileSize) * this.masterTileSize;

            var tileCurPosX = parseInt(document.getElementById(this.name + "x0y0").style.left);
            var tileCurPosY = parseInt(document.getElementById(this.name + "x0y0").style.top);

            //get mouse percentage
            var tileCurPosXPct = xpospx / this.masterTileSize;
            var tileCurPosYPct = ypospx / this.masterTileSize;

        } else {

            var newTileWidth = scale * this.tileSize;

            //fetch mouse position in tile
            var xpospx = (m_x - parseInt(this.mapbox.style.left)) - Math.floor((m_x - parseInt(this.mapbox.style.left)) / this.tileSize) * this.tileSize;
            var ypospx = (m_y - parseInt(this.mapbox.style.top)) - Math.floor((m_y - parseInt(this.mapbox.style.top)) / this.tileSize) * this.tileSize;

            var tileCurPosX = parseInt(document.getElementById(this.name + "x" + xpos + "y" + ypos).style.left);
            var tileCurPosY = parseInt(document.getElementById(this.name + "x" + xpos + "y" + ypos).style.top);

            //get mouse percentage
            var tileCurPosXPct = xpospx / this.tileSize;
            var tileCurPosYPct = ypospx / this.tileSize;

        }

        //calculate new x-offset
        var deltaX = xpospx - tileCurPosXPct * newTileWidth;
        var tileNewPosX = tileCurPosX + deltaX;
        
        //calculate new y-offset
        var deltaY = ypospx - tileCurPosYPct * newTileWidth;
        var tileNewPosY = tileCurPosY + deltaY;

        this.animateZoom(tileCurPosX, tileCurPosY, deltaX, deltaY, scale, xpos, ypos,14,1);
        
    }//preZoom


    FoliaMap.prototype.animateZoom = function (tileCurPosX, tileCurPosY, deltaX, deltaY, scale, xpos, ypos,res,count) { 

        if ( count == 1 ) {
            this.aZoom = new Object();
            this.aZoom.tileCurPosX = tileCurPosX;
            this.aZoom.tileCurPosY = tileCurPosY;
            this.aZoom.deltaX = deltaX;
            this.aZoom.deltaY = deltaY;
            this.aZoom.scale = scale;
            this.aZoom.xpos = xpos;
            this.aZoom.ypos = ypos;
            this.aZoom.res = res;
            this.aZoom.count = count;
        }

        var tilesEnabled = this.mapbox.getElementsByTagName("img");
        for( var c = 0; c < tilesEnabled.length; c++ ) {
            var imgid = tilesEnabled[c].getAttribute("id");
            if(imgid == this.name + "x0y0" && this.usemastertile) var oldTileSize = this.masterTileSize;
            else var oldTileSize = this.tileSize;

                imgid = imgid.replace(/^[^_]+_/,"");
                imgid = imgid.replace(/^x/,"");
                imgid = imgid.split(/y/);

            var gX = parseInt(imgid[0]);
            var gY = parseInt(imgid[1]);

            var relX = gX - this.aZoom.xpos;
            var relY = gY - this.aZoom.ypos;
    
            //set tile size
            var newsize = Math.ceil(oldTileSize * this.aZoom.scale);
            var sizediff = oldTileSize - newsize;
            sizediff = sizediff * this.aZoom.count / this.aZoom.res;
            newsize = oldTileSize - sizediff;
            tilesEnabled[c].style.width = newsize + "px";
            tilesEnabled[c].style.height = newsize + "px";

            //set new position
            var tileSize = this.tileSize * this.aZoom.scale;
            var sizediff = this.tileSize - tileSize;
            sizediff = Math.ceil(sizediff * this.aZoom.count / this.aZoom.res);
            tileSize = this.tileSize - sizediff;

            //calculate new x-offset
            var tileNewPosX = this.aZoom.tileCurPosX + this.aZoom.deltaX * this.aZoom.count / this.aZoom.res;
        
            //calculate new y-offset
            var tileNewPosY = this.aZoom.tileCurPosY + this.aZoom.deltaY * this.aZoom.count / this.aZoom.res;

            var newposx = Math.ceil(tileNewPosX + relX * tileSize);
            var newposy = Math.ceil(tileNewPosY + relY * tileSize);
            tilesEnabled[c].style.top = newposy + "px";
            tilesEnabled[c].style.left = newposx + "px";

        }//for

        if( this.aZoom.count < this.aZoom.res ) {
            this.aZoom.count++;
            this.timera = window.setTimeout(this.animateZoom.bind(this),1);
        } else {
            this.zoomAnimate = false;
            if ( this.hidePOIonZoom ) this.themeLayer.style.display = "block";
        }//if

    }//animateZoom

/*
   FoliaMap.prototype.resetMap = function() {
        
        this.updateBBox();

        var imgReady = true;
        
        if (this.zImage && !this.zImage.complete) {
            imgReady = false;
        }
        
        if(!this.zoomAnimate && imgReady) {
        
            //this.clearTiles();
              
            delete this.timera;
            delete this.tTimer;

            this.mapbox.innerHTML = "";
            this.mapbox.style.top = "0px";
            this.mapbox.style.left = "0px";

            //NOTE placement must be recalculated or cached for further use.
            this.themeLayer.style.top = "0px";
            this.themeLayer.style.left = "0px";
            this.themeIb.style.top = "0px";
            this.themeIb.style.left = "0px";

            //create tiles object - this object contains all image objects with tiles:
            this.tiles = new Object();

            if (this.usemastertile) {
                this.x0y0.src = this.zImage.src;
                this.x0y0.style.width = (this.masterTileSize) + "px";
                this.x0y0.style.height = (this.masterTileSize) + "px";
                this.x0y0.style.top = "0px";
                this.x0y0.style.left = "0px";
                this.mapbox.appendChild(this.x0y0);
            }
            else {
                this.x0y0.style.display = "none";
            }

            for( var xval = 0; xval < this.displaySize; xval ++ ) {
                for( var yval = 0; yval < this.displaySize; yval ++ ) {
                    this.addTile(xval,yval);
                }//for
            }//for
            
            this.updateBBox();
            
            try {this.zoomStopped();} catch(ex) {}  
                        
            if ( this.locator ) this.addLocator();
            
        } else {
            this.tTimer = setTimeout(this.resetMap.bind(this),40);
        }//else
    }//resetMap
*/


    FoliaMap.prototype.resetMap = function() {

        this.updateBBox();        
        
        var imgReady = true;
        
        if (this.zImage && !this.zImage.complete) {
            imgReady = false;
        }
        
        if(!this.zoomAnimate && imgReady) {
            delete this.timera;
            delete this.tTimer;

            this.mapbox.innerHTML = "";
            
            if (this.usemastertile) {
                this.x0y0.src = this.zImage.src;

                this.x0y0.style.width = (this.masterTileSize) + "px";
                this.x0y0.style.height = (this.masterTileSize) + "px";
                this.x0y0.style.top = "0px";
                this.x0y0.style.left = "0px";
                this.mapbox.appendChild(this.x0y0);

            }
            else {
                this.x0y0.style.display = "none";
            }

            this.mapbox.style.top = "0px";
            this.mapbox.style.left = "0px";

            //NOTE placement must be recalculated or cached for further use.
            
            this.themeLayer.style.top = "0px";
            this.themeLayer.style.left = "0px";
            this.themeIb.style.top = "0px";
            this.themeIb.style.left = "0px";
            //create tiles object - this object contains all image objects with tiles:
            

            if (this.usemastertile) {
                this.tiles = new Object();
                //register unused tiles:
                for( var xval = 0; xval < this.displaySize; xval ++ ) {
                    for( var yval = 0; yval < this.displaySize; yval ++ ) {
                        this.tiles[this.name + xval + "," + yval] = 1;
                    }//for
                }//for
            }
            else {
//                var xpos = Math.floor((this.mx - parseInt(this.mapbox.style.left)) / this.tileSize);
//                var ypos = Math.floor((this.my - parseInt(this.mapbox.style.top)) / this.tileSize);
//                this.addTile(xpos,ypos);
                for( var xval = 0; xval < this.displaySize; xval ++ ) {
                for( var yval = 0; yval < this.displaySize; yval ++ ) {
                    //if (xval != xpos || yval != ypos) {
                        this.addTile(xval,yval);
                    //}
                }//for
            }//for
            }
            //NOTE Garbage collection removed in favor of innerHTML = ""
            if ( this.tileLoadEnabled ) {
                this.xTileBeginP = -1;
                this.yTileBeginP = -1;
                this.display(false,0,0);
            }//if
            
            this.updateBBox();
            
            try {this.zoomStopped();} catch(ex) {}  
                        
            if ( this.locator ) this.addLocator();
            
        } else {
            this.tTimer = setTimeout(this.resetMap.bind(this),60);
        }//else
    }//resetMap

    FoliaMap.prototype.preloadTiles = function() {
        
        this.tiles = new Object();

        var xpos = Math.floor((this.mx - parseInt(this.mapbox.style.left)) / this.tileSize);
        var ypos = Math.floor((this.my - parseInt(this.mapbox.style.top)) / this.tileSize);
        
        var boxIX = Math.round(this.bbox.ix + xpos * this.tileSize * this.bbox.rel);
        var boxIY = Math.round((this.bbox.ey - ypos * this.tileSize * this.bbox.rel) - this.tileSize * this.bbox.rel);                                
        var boxEX = Math.round((this.bbox.ix + xpos * this.tileSize * this.bbox.rel) + this.tileSize * this.bbox.rel);
        var boxEY = Math.round(this.bbox.ey - ypos * this.tileSize * this.bbox.rel);
        
        this.tiles[this.name + xpos + "," + ypos] = new Image();
        this.tiles[this.name + xpos + "," + ypos].src = this.buildUrl(boxIX,boxIY,boxEX,boxEY,this.tileSize); 

        for( var xval = 0; xval < this.displaySize; xval ++ ) {
            for( var yval = 0; yval < this.displaySize; yval ++ ) {
                //if (xval != xpos || yval != ypos) {
                    boxIX = Math.round(this.bbox.ix + xval * this.tileSize * this.bbox.rel);
                    boxIY = Math.round((this.bbox.ey - yval * this.tileSize * this.bbox.rel) - this.tileSize * this.bbox.rel);                                
                    boxEX = Math.round((this.bbox.ix + xval * this.tileSize * this.bbox.rel) + this.tileSize * this.bbox.rel);
                    boxEY = Math.round(this.bbox.ey - yval * this.tileSize * this.bbox.rel);
                    this.tiles[this.name + xval + "," + yval] = new Image();
                    this.tiles[this.name + xval + "," + yval].src = this.buildUrl(boxIX,boxIY,boxEX,boxEY,this.tileSize); 
                //}
            }//for
        }//for
   
    }


    FoliaMap.prototype.zoom = function (newZLevel) {
        var zLevelOld = this.zLevel;
        this.zLevelOld = this.zLevel;
        this.zLevel = newZLevel;
        var m_x = Math.round( parseInt( this.navbox.style.width ) / 2 );
        var m_y = Math.round( parseInt( this.navbox.style.height ) / 2 );
        this.setZoomLevel(zLevelOld,m_x,m_y);      
 
    }//zoom


    FoliaMap.prototype.zIn = function() {
        var newZLevel = this.zLevel - 1;
        if (newZLevel >= 0 ) this.zoom(newZLevel);    
    }
    
    FoliaMap.prototype.zOut = function() {
        var newZLevel = this.zLevel + 1;
        if (newZLevel < this.zLevels.length ) this.zoom(newZLevel);
    }

    FoliaMap.prototype.setCenterZoom = function(ev){
    
        //deaktiver dobbeltklik i oversigtskort
        if (this.name.indexOf("locator") > -1) return false;
    
        this.setCenterZoomOn = true;

        var mpos = this.getMousePos(this.name + "actionLayer",ev);      
       
        this.mapPanXY(Math.round(parseInt(this.navbox.style.width)/2) - mpos.x, Math.round(parseInt(this.navbox.style.height)/2) - mpos.y);

        setTimeout(function() {
            if ( this.animateMapPanDist.X == 0 && this.animateMapPanDist.Y == 0 ) {
                if ( this.zLevel - 1 <= 0 )
                    this.zoom(0);
                else
                    this.zoom(this.zLevel - 1);
            } else {
                setTimeout(arguments.callee.bind(this),40);
            }
        }.bind(this),40);
    }//FoliaMap.prototype.setCenterZoom
    
    FoliaMap.prototype.setCenterZoomout = function(e) {
        if ( this.zoomOutFlag ) {
            this.setCenterZoomOn = true;       
            this.mapPanXY(Math.round(parseInt(this.navbox.style.width)/2) - this.mx, Math.round(parseInt(this.navbox.style.height)/2) - this.my);

            setTimeout(function() {
                if ( this.animateMapPanDist.X == 0 && this.animateMapPanDist.Y == 0 ) {
                    if ( this.zLevel + 1 >= this.zLevels.length )
                        this.zoom( (this.zLevels.length -1) );
                    else
                        this.zoom(this.zLevel + 1);
                } else {
                    setTimeout(arguments.callee.bind(this),40);
                }
            }.bind(this),40);

        } else {
            this.zoomOutFlag = true;
            setTimeout(function() {this.zoomOutFlag = false}.bind(this), 500);
        }
    }


/*=====================================================
  PAN SECTION
  =====================================================*/

    FoliaMap.prototype.display = function(e) {
        var ep = this.getElementPosition(this.navbox);
        if(this.moveactive || arguments.length == 3) {

            if ( arguments.length == 3 ) {
                var X = parseInt(arguments[1]) + ep.x;
                var Y = parseInt(arguments[2]) + ep.y;
            } else {
                var X = this.getCoord(e).x;
                var Y = this.getCoord(e).y;
            }

            //Hvor meget skal der flyttes
            var xMoveby = (X - ep.x) - this.xOffset;
            var yMoveby = (Y - ep.y) - this.yOffset;
            
            //Find den nye position for kortets top og left
            var xNewPos = this.xMapbox + xMoveby;
            var yNewPos = this.yMapbox + yMoveby;
            
            //Her flyttes kortet
            this.mapbox.style.left = xNewPos + "px";
            this.mapbox.style.top = yNewPos + "px";

            /*ADDED*/
            this.themeLayer.style.left = this.themeIb.style.left = xNewPos + "px";
            this.themeLayer.style.top = this.themeIb.style.top = yNewPos + "px";
            
           //Ændret af Jacob
           //Her skal det fjernes hvor Hovedkortet flyttes samtidigt med oversigskortet

            //Hvis man flytter i hovedkortet skal locator også flyttes
            if(this.locator && this.moveactive) {
                var xv = Math.round( (xMoveby * this.bbox.rel) / this.locator.bbox.rel );
                var yv = Math.round((yMoveby * this.bbox.rel)/ this.locator.bbox.rel);

                this.locator.xOffset = 0;
                this.locator.yOffset = 0;
                this.locator.display(false,xv,yv);
            }//if

            //update boundarybox

            // devision by 100 replaced by devision by tileSize - ...
            xTileBegin = Math.ceil( xNewPos / this.tileSize ) * -1 - this.horizon;
            xTileEnd = xTileBegin + this.displaySize + ( this.horizon * 2 );


            //displaySize erstattet med masterTileSize
            yTileBegin = Math.ceil( yNewPos / this.tileSize ) * -1 - this.horizon;
            yTileEnd = yTileBegin + this.displaySize + ( this.horizon * 2 );

            // OBS - FIX THIS LATER - JDP
            //if ( xTileBegin != this.xTileBeginP || yTileBegin != this.yTileBeginP ) {

                //var tilesShown = new Object();
                //this.clearTiles();
                
                this.xTileBeginP = xTileBegin;
                this.yTileBeginP = yTileBegin;

                for( var xval = xTileBegin; xval <= xTileEnd; xval++ ) {
                    for( var yval = yTileBegin; yval <= yTileEnd; yval++ ) {
                        this.addTile(xval,yval);
                        //tilesShown[this.name + "x" + xval + "y" + yval] = 1;
                    }//for
                }//for
            //}
            //update current viewport boundary box coordinates
            //Gør at vi ved hvor vi er på kortet - fx ved zoom
            this.updateBBox();

            //update searchBox if any.
            try {
                this.searchBoxUTMUpdate();
            } catch(e) {

            }

        }//if


    }//display

//FIXME

   FoliaMap.prototype.addTile = function (x,y){
        if((!(x == 0 && y == 0) && this.usemastertile) || !this.usemastertile) {
            if(!this.tiles[this.name + x + "," + y]) {
            
                //Fang den tile som musen står i
                var xpos = Math.floor((this.mx - parseInt(this.mapbox.style.left)) / this.tileSize);
                var ypos = Math.floor((this.my - parseInt(this.mapbox.style.top)) / this.tileSize);
                
                //Tiles der vises for første gang
                this.tiles[this.name + x + "," + y] = new Image();
                var newTile = document.createElement("img");
                    newTile.setAttribute("id",this.name + "x" + x + "y" + y);
                    newTile.style.position = "absolute";
                    newTile.style.top = this.tileSize * y + "px";
                    newTile.style.left = this.tileSize * x + "px";
                    newTile.style.width = this.tileSize + "px";
                    newTile.style.height = this.tileSize + "px";
                    /****** TIL TEST ****/
//                        newTile.style.opasity = 0.5;
//                        newTile.style.filter =  "alpha(opacity=50)";
//                        newTile.style.MozOpacity = 0.5;
//                        newTile.style.border = "#000000 Solid 2px";
//                        
//                        var tmpTxt = document.createElement("div");
//                        tmpTxt.innerHTML = this.name + x + "," + y;
//                        tmpTxt.style.position = "absolute";
//                        tmpTxt.style.top = this.tileSize * y + (this.tileSize/2) + "px";
//                        tmpTxt.style.left = this.tileSize * x + (this.tileSize/2) - 20 + "px";
//                        this.mapbox.appendChild(tmpTxt);
//                        debug(this.name + x + "," + y);
                    /******/
                    newTile.src = this.loadimg;

                this.mapbox.appendChild(newTile);
                                             
                //TEST calculate tile image bounding box
                var boxIX = Math.round(this.bbox.ix + x * this.tileSize * this.bbox.rel);
                var boxIY = Math.round((this.bbox.ey - y * this.tileSize * this.bbox.rel) - this.tileSize * this.bbox.rel);                                
                var boxEX = Math.round((this.bbox.ix + x * this.tileSize * this.bbox.rel) + this.tileSize * this.bbox.rel);
                var boxEY = Math.round(this.bbox.ey - y * this.tileSize * this.bbox.rel);
                
                //this.doLoadTiles = true;
                //if (this.doLoadTiles) {
                    this.tiles[this.name + x + "," + y].src = this.buildUrl(boxIX,boxIY,boxEX,boxEY,this.tileSize);
                //}
                
                newTile.src = this.tiles[this.name + x + "," + y].src;
                
                //for (var t in this.tiles) {
                //    var myTile = t;
                //}
                
                //if(/MSIE 6\.0/.test(navigator.appVersion)) this.addToIECache(newTile.src);
                /*
                //test write tile name
                //BEGIN TEST
                var tilename = document.createElement("div");
                    tilename.style.position = "absolute";
                    tilename.style.top = this.tileSize * y + "px";
                    tilename.style.left = this.tileSize * x + "px";
                    tilename.style.zIndex = 40;
                    tilename.innerHTML = x + "," + y;
                    tilename.style.color = "#ff0000";
                    tilename.style.fontFamily = "sans-serif";
                    tilename.style.fontWeight = "bold";
                    tilename.style.backgroundColor = "#ffffff";
                    tilename.style.fontSize = "12px";
                this.mapbox.appendChild(tilename);
                //END TEST
                */
            } else if ( !document.getElementById(this.name + "x" + x + "y" + y) && this.tiles[this.name + x + "," + y] && this.tiles[this.name + x + "," + y] != 1) {
               // Tiles der har været vist før
                var newTile = document.createElement("img");
                    newTile.setAttribute("id",this.name + "x" + x + "y" + y);
                    newTile.style.position = "absolute";
                    newTile.style.top = this.tileSize * y + "px";
                    newTile.style.left = this.tileSize * x + "px";
                    newTile.style.width = this.tileSize + "px";
                    newTile.style.height = this.tileSize + "px";
                    //newTile.style.border = "#000000 Solid 1px";
                    newTile.src = this.loadimg;
                    /****** TIL TEST ****/
//                        newTile.style.opasity = 0.5;
//                        newTile.style.filter =  "alpha(opacity=50)";
//                        newTile.style.MozOpacity = 0.5;
//                        newTile.style.border = "#000000 Solid 2px";
                    /******/
                this.mapbox.appendChild(newTile);
                newTile.src = this.tiles[this.name + x + "," + y].src;
                //if(/MSIE 6\.0/.test(navigator.appVersion)) this.addToIECache(newTile.src);
            }
        }
    }//addTiles
    
    FoliaMap.prototype.clearTiles = function() {
        for (var t in this.tiles) {
            this.tiles[t].src = this.loadimg;
        }
        //this.tiles[this.name + x + "," + y].src
    }
    
    FoliaMap.prototype.addToIECache = function(img) {

        if(this.ieCachedImages) {
            document.getElementById("iecache").innerHTML = "";
            if (!this.ieCachedImages[img]) {

                var image = document.createElement("img");
                    image.src = img;
                document.getElementById("iecache").appendChild(image);
                this.ieCachedImages[img] = 1;
            }

        } else {
            this.ieCachedImages = new Object();
            var iecache = document.createElement("div");
            //iecache.style.display = "none";
            iecache.setAttribute("id","iecache");
            iecache.style.display = "none";
            document.body.appendChild(iecache);

            //append std 1x1 gif
            var image = document.createElement("img");
                image.src = this.gfxPath + "1x1_transparent.gif";
            document.getElementById("iecache").appendChild(image);
            this.ieCachedImages[this.gfxPath + "1x1_transparent.gif"] = 1;
        }//else

    }//addToIECache

    FoliaMap.prototype.mapPan = function(e) {

        if ( !e ) e = window.event;

        try {
            var panId = e.target.id;
        } catch(ex) {
            var panId = e.srcElement.id;
        }

        var pans = new Object();
        pans[this.name + "pan_N"] = "0,-1";
        pans[this.name + "pan_N_i"] = "0,-1";
        pans[this.name + "pan_N_"] = "0,-1";
        pans[this.name + "pan_E"] = "1,0";
        pans[this.name + "pan_E_i"] = "1,0";
        pans[this.name + "pan_E_"] = "1,0";
        pans[this.name + "pan_S"] = "0,1";
        pans[this.name + "pan_S_i"] = "0,1";
        pans[this.name + "pan_S_"] = "0,1";
        pans[this.name + "pan_W"] = "-1,0";
        pans[this.name + "pan_W_i"] = "-1,0";
        pans[this.name + "pan_W_"] = "-1,0";
        pans[this.name + "img_pan_NW"] = "-1,-1";
        pans[this.name + "img_pan_NE"] = "1,-1";
        pans[this.name + "img_pan_SW"] = "-1,1";
        pans[this.name + "img_pan_SE"] = "1,1";
       

        if (panId != this.name + "img_pan_NW_" && panId != this.name + "img_pan_NE_" && panId != this.name + "img_pan_SW_" && panId != this.name + "img_pan_SE_" && panId != this.name + "pan_N_" && panId != this.name + "pan_E_" && panId != this.name + "pan_S_" && panId != this.name + "pan_W_") {
            panId = panId.split(/_/);               
            panId.pop();
        }
        else {
            panId = panId.split(/_/);         
        }
        panId = panId.join("_");            

        var x = parseInt(pans[panId].split(/,/)[0]);
        var y = parseInt(pans[panId].split(/,/)[1]);

        if ( /px$/.test(x) ) {
            var X = parseInt( this.navbox.style.width ) / 2  - parseInt(x);
            var Y = parseInt( this.navbox.style.height ) / 2 - parseInt(y);
        } else {
            var X = x * -1 * Math.round( this.displayWidth * this.mapPanPct / 100 );
            var Y = y * -1 * Math.round( this.displayHeight * this.mapPanPct / 100 );
        }
        
//        try{
//            this.logPanAction(((this.mapPanPct/100)*this.mapwidth)*Math.abs(x),((this.mapPanPct/100)*this.mapheight)*Math.abs(y));
//        }catch(e){};


        this.animateMapPanDist = {X:X,Y:Y};
        this.animateMapPan();
        

        
        if(this.locator) {
            var xv = Math.round( (X * this.bbox.rel) / this.locator.bbox.rel );
            var yv = Math.round((Y * this.bbox.rel)/ this.locator.bbox.rel);

            this.locator.xMapbox = this.locator.mapbox.offsetLeft;
            this.locator.yMapbox = this.locator.mapbox.offsetTop;
            this.locator.xOffset = 0;
            this.locator.yOffset = 0;
            this.locator.display(false,xv,yv);

        }//if
        
    }//mapPan
    
    FoliaMap.prototype.animateMapPan = function() {
        
        //desto større værdi dist har, desto hurtigere panoreres kortet.
        var dist = 30;
        var pixelX = this.animateMapPanDist.X >= 0 ? this.animateMapPanDist.X : -(this.animateMapPanDist.X);
        var pixelY = this.animateMapPanDist.Y >= 0 ? this.animateMapPanDist.Y : -(this.animateMapPanDist.Y);
        var X = 0;
        var Y = 0;

        if ( pixelX > pixelY ) {
            var distX = dist;
            var distY = parseInt( (pixelY / pixelX) * dist );
        } else {
            var distY = dist;
            var distX = parseInt( (pixelX / pixelY) * dist );
        }//else
    
        if ( this.animateMapPanDist.X )

        if ( this.animateMapPanDist.X > 0 ) {
            this.animateMapPanDist.X = this.animateMapPanDist.X >= distX ? this.animateMapPanDist.X - distX : 0;
            X = distX;
        } else if ( this.animateMapPanDist.X < 0 ) {
            this.animateMapPanDist.X = this.animateMapPanDist.X <= -(distX) ? this.animateMapPanDist.X + distX : 0;
            X = -(distX);
        }

        if ( this.animateMapPanDist.Y > 0 ) {
            this.animateMapPanDist.Y = this.animateMapPanDist.Y >= distY ? this.animateMapPanDist.Y - distY : 0;
            Y = distY;
        } else if ( this.animateMapPanDist.Y < 0 ) {
            this.animateMapPanDist.Y = this.animateMapPanDist.Y <= -(distY) ? this.animateMapPanDist.Y + distY : 0;
            Y = -(distY);
        }

        if ( X != 0 || Y != 0) {
            this.xMapbox = this.mapbox.offsetLeft;
            this.yMapbox = this.mapbox.offsetTop;
            this.xOffset = 0;
            this.yOffset = 0;
            this.display(false,X,Y);
            setTimeout(this.animateMapPan.bind(this),40);
        }//if

    }//animateMapPan    
    
    FoliaMap.prototype.mapPanXY = function(x,y) {

        this.animateMapPanDist = {X:x,Y:y};
        this.animateMapPan();
    }//mapPanXY
  
  

    
/*=====================================================
  POI SECTION
  =====================================================*/


/**
 * setPOI enables the layer poiname on the map.
 * @string poiname      - name of the theme - this is displayed in the title-attribute, when the user mouseovers
 * @integer id          - The theme id - this must be unique
 * @integer zindex      - The heigher the zindex the more important the layer
 * @string iconname     - the imagename of the icon used to display the POIs
 * @integer iconwidth   - the width of the icon in pixels
 * @integer iconheight  - the height of the icon in pixels
 * @array events        - an associative array ( object ) with key=eventname and value=eventfunction
 * @array points        - an object with value=point position, point id array(id,x,y)
 * @return void
 **/
FoliaMap.prototype.setPOI = function (poiname, id, zindex, iconpath, baseiconname, baseiconwidth, baseiconheight, events, points, visible) {
    //add the points to cache
    this.POIenabled[id] = new Object();
    this.POIenabled[id].poiname = poiname;
    this.POIenabled[id].zindex = zindex;
    this.POIenabled[id].iconpath = iconpath;
    this.POIenabled[id].baseiconname = baseiconname;
    this.POIenabled[id].baseiconwidth = baseiconwidth;
    this.POIenabled[id].baseiconheight = baseiconheight;
    this.POIenabled[id].events = events;
    this.POIenabled[id].points = points;
    this.POIenabled[id].visible = visible;

    //delete existing points in layer
    try {
        this.themeLayer.removeChild(document.getElementById(this.name + "theme_" + id));
    } catch(e) {}

    if ( parseInt(visible) > 0 ) {

    //enable the theme layer
    var theme = document.createElement("div");
        theme.style.zIndex = zindex;
        theme.style.position = "absolute";
        theme.style.top = "0px";
        theme.style.left = "0px";
        theme.setAttribute("id",this.name + "theme_" + id);
    this.themeLayer.appendChild(theme);

    //run through point and add the points
    for ( var poi_id in points ) {

        var pwidth = points[poi_id].iconwidth ? points[poi_id].iconwidth : baseiconwidth;
        var pheight = points[poi_id].iconheight ? points[poi_id].iconheight : baseiconheight;

        var point = document.createElement("div");
        
        var xp = Math.round(( ( points[poi_id]["x"] - this.bbox.ix ) / this.bbox.rel ) - pwidth / 2);
        var yp = ( this.displaySize * this.tileSize ) - Math.round(( ( points[poi_id]["y"] - this.bbox.iy ) / this.bbox.rel ) + pheight / 2);

            point.style.width = pwidth + "px";
            point.style.height = pheight + "px";
            point.style.position = "absolute";
            point.style.top = yp + "px";
            point.style.left = xp + "px";
            point.style.zIndex = 10 + zindex;
            point.style.cursor = "pointer";
            this.addEventHandler(point,"mousemove",this.unsetMoveActive.bind(this));
        
        var iconname = points[poi_id].iconname ? points[poi_id].iconname : baseiconname;
        var imgtitle = points[poi_id].onmouseoverinfo ? "" : points[poi_id].tooltiptext ? points[poi_id].tooltiptext : poiname;
        var html = document.createElement("img");

        if(/MSIE 6\.0/.test(navigator.appVersion) && /\.png$/.test(iconname)) {
            html.src = this.gfxPath + "1x1_transparent.gif";
            html.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iconpath + iconname +"', sizingMethod='scale');"
        } else {
            html.src = iconpath + iconname;
        }

        html.setAttribute("title",imgtitle);
        html.setAttribute("width",pwidth);
        html.setAttribute("height",pheight);
        html.setAttribute("id",this.name + id + '_' + poi_id);

        for ( var e in events ) {
            //FIXME
            //debug("this.addEventHandler(html,e,this." + events[e] + ".bind(this))");
            this.addEventHandler(html,e,this[events[e]].bind(this));
        }//for

        point.appendChild(html);
        theme.appendChild(point);
        
    }//for


    }//if visible > 0

}//setPOI


FoliaMap.prototype.redrawPOI = function() {

    var divs = this.themeLayer.getElementsByTagName("div");
    for( var c = 0; c < divs.length; c++ ) {
        if ( divs[c].className == "infobox") this.themeLayer.removeChild(divs[c]);
    }//for
    

    for ( var id in this.POIenabled ) {
        try {
            this.themeLayer.removeChild(document.getElementById(this.name + "theme_" + id));
        } catch(e) {}
        
        this.setPOI(this.POIenabled[id].poiname,id,this.POIenabled[id].zindex,this.POIenabled[id].iconpath,this.POIenabled[id].baseiconname,this.POIenabled[id].baseiconwidth,this.POIenabled[id].baseiconheight,this.POIenabled[id].events,this.POIenabled[id].points, this.POIenabled[id].visible);
        
        try {
            this.setClusterPoints(getHementMapItems());
        }
        catch(e) {}
    }//for
}//redrawPOI


FoliaMap.prototype.removePOI = function(id) {

    var divs = this.themeLayer.getElementsByTagName("div");
    for( var c = 0; c < divs.length; c++ ) {
        if ( divs[c].className == "infobox") this.themeLayer.removeChild(divs[c]);
    }//for
    

    for ( var id in this.POIenabled ) {
        try {
            this.themeLayer.removeChild(document.getElementById(this.name + "theme_" + id));
        } catch(e) {}
    }//for
    
    //delete this.POIenabled;
    this.POIenabled[id] = null;
        
}//removePOI


FoliaMap.prototype.setHidePOIonZoom = function(val) {
    if ( val ) {
        this.hidePOIonZoom = true;
    } else {
        this.hidePOIonZoom = false;
    }
}


FoliaMap.prototype.disallowPan = function () {
    this.DAPan = true;
}//disallowPan


FoliaMap.prototype.allowPan = function () {
    delete this.DAPan;
}//disallowPan

FoliaMap.prototype.unsetMoveActive = function () {
    this.moveactive = false;
}//unsetMoveActive


var infoBox = new Object();

FoliaMap.prototype.udskriv = function(e) {
    //debug("udskriv");
}

FoliaMap.prototype.displayInfoBox = function(e) {
    if(!e) e = window.event;

    try {
        var o_id = e.target.id;
    } catch(ex) {
        var o_id = e.srcElement.id;
    }
    
    this.showInfoBox(o_id);
}

FoliaMap.prototype.showInfoBox = function(o_id, left, bottom, top) {
    
    infoBox.keeper = false;
    infoBox.timeout = false;
    this.hideInfoBox();


    var arrtmp = o_id.toString().split(/_/);
    var theme_id = arrtmp[1];
    var poi_id = arrtmp[2];

    var o = document.getElementById(o_id);
 
    infoBox.theme_id = theme_id;
    infoBox.poi_id = poi_id;
    infoBox.timeout = true;
    infoBox.keeper = true;

    if ( this.POIenabled[theme_id].points[poi_id].onmouseoverinfo ) {
        var ib = document.createElement("div");
            ib.setAttribute("id","infobox_" + theme_id + "_" + poi_id);
            ib.style.position = "absolute";
            ib.style.left = left ? left : o.parentNode.style.left;
            ib.style.top = top ? top : parseInt(o.parentNode.style.top) + parseInt(o.parentNode.style.height) - 1 + "px";
 
            if(bottom) {
							ib.style.bottom = bottom;
							ib.style.top = "";
						}
//            ib.style.width = "auto !important";
//            ib.style.width = "10px";
//            ib.style.minWidth = "10px";

            ib.className = "infobox";
            ib.style.zIndex = "100";
            this.addEventHandler(ib,"mouseover",this.keepInfoBox.bind(this));
            this.addEventHandler(ib,"mouseout",this.releaseInfoBox.bind(this));
            ib.innerHTML = this.POIenabled[theme_id].points[poi_id].onmouseoverinfo;
        this.themeIb.appendChild(ib);
    }//if

}//showInfoBox


//removes all boxes everytime
FoliaMap.prototype.hideInfoBox = function() {

    if(infoBox.keeper) {
        infoBox.timeout = true;
    } else if(infoBox.timeout && !infoBox.keeper) {
        infoBox.timeout = false;
        var that = this;
        infoBox.timer = window.setTimeout(function () { that.hideInfoBox(); },500);
    } else if(!infoBox.keeper) {
        for ( var theme_id in this.POIenabled ) {

            for ( var poi_id in this.POIenabled[theme_id].points ) {

                try {
                    this.themeIb.removeChild(document.getElementById("infobox_" + theme_id + "_" + poi_id));
                } catch(ex) {

                }//try/catch
            }//for

        }//for
    }//else

}//hideInfoBox

FoliaMap.prototype.keepInfoBox = function(e) {
    delete(infoBox.timer);
    infoBox.keeper = true;
    infoBox.timeout = true;
}//keepInfoBox

FoliaMap.prototype.releaseInfoBox = function(e) {
    infoBox.keeper = false;
    this.hideInfoBox();
}

/*=====================================================
  WIDGET SECTION
  =====================================================*/

    FoliaMap.prototype.FAddZoomControl = function() {

        this.fZoomSliderDragFlag = false;
        zoombarBackHeight = this.zLevels.length * 13;
        
        var zoombarDiv = document.createElement("div");
            zoombarDiv.setAttribute("id", this.name + "divZoombar");
        this.mapholder.appendChild(zoombarDiv);
        
        var zoombarIn = document.createElement("img");
            zoombarIn.setAttribute("id", this.name + "zoombarIn");
            zoombarIn.style.width = zoombarInWidth + "px";
            zoombarIn.style.height = zoombarInHeight + "px";
            zoombarIn.src = gfxFolderZoom + zoombarInSrc;
            zoombarIn.alt = f_zoomPlus;
            zoombarIn.title = f_zoomPlus;
        zoombarDiv.appendChild(zoombarIn);
        this.addEventHandler(zoombarIn, "click", this.ZoomIn.bind(this))
       
        var zoombarBackGr = document.createElement("div");
            zoombarBackGr.setAttribute("id", this.name + "zoombarBack");
            zoombarBackGr.style.width = zoombarBackWidth + "px";
            zoombarBackGr.style.height = zoombarBackHeight + "px";
            zoombarBackGr.style.backgroundImage = "url('" + gfxFolderZoom + zoombarBackSrc + "')";
        zoombarDiv.appendChild(zoombarBackGr);
        this.addEventHandler(zoombarBackGr, "mousemove", this.SliderMouseMove.bind(this));
        
        var zoombarOut = document.createElement("img");
            zoombarOut.setAttribute("id", this.name + "zoombarOut");
            zoombarOut.style.width = zoombarOutWidth + "px";
            zoombarOut.style.height = zoombarOutHeight + "px";
            zoombarOut.src = gfxFolderZoom + zoombarOutSrc;
            zoombarOut.alt = f_zoomMinus;
            zoombarOut.title = f_zoomMinus;
        zoombarDiv.appendChild(zoombarOut);
        this.addEventHandler(zoombarOut, "click", this.ZoomOut.bind(this))
        
        var zoombarSlide = document.createElement("img");
            zoombarSlide.setAttribute("id", this.name + "zoombarHandler");
            zoombarSlide.style.position = "absolute";
            zoombarSlide.style.marginLeft = "2px";
            zoombarSlide.style.width = zoombarHandlerWidth + "px";
            zoombarSlide.style.height = zoombarHandlerHeight + "px";
            zoombarSlide.style.zIndex = 1;
            zoombarSlide.src = gfxFolderZoom + zoombarHandlerSrc;
            zoombarSlide.alt = "zoom";
        zoombarBackGr.appendChild(zoombarSlide);

        var zoombarEvent = document.createElement("div");
            zoombarEvent.setAttribute("id", this.name + "zoombarEvent");
            zoombarEvent.style.position = "absolute";
            zoombarEvent.style.width = zoombarBackWidth + "px";
            zoombarEvent.style.height = zoombarBackHeight + "px";
            zoombarEvent.style.top = "18px";
            zoombarEvent.style.zIndex = 2;
            zoombarEvent.style.backgroundImage = "url('" + this.gfxPath + "1x1_transparent.gif')";
        zoombarBackGr.appendChild(zoombarEvent);
        this.addEventHandler(zoombarEvent, "mousedown", this.SliderMouseDown.bind(this));
        this.addEventHandler(zoombarEvent, "mouseup", this.SliderMouseUp.bind(this));
        this.addEventHandler(zoombarEvent, "mouseout", this.SliderMouseOut.bind(this));
  
        this.setZoomSlider(this.zLevel);
        //enableDisableMapStyleButtons(this.zLevel);
    }
        
    FoliaMap.prototype.ZoomOut = function() {
    
        var zoombarHandler = document.getElementById(this.name + "zoombarHandler");
        var zoombarBackGround = document.getElementById(this.name + "zoombarBack");
        var y = this.getElementPosition(zoombarHandler).y;
        var yBack = this.getElementPosition(zoombarBackGround).y;
        
        if (this.zLevel + 1 < this.zLevels.length ) this.zOut();
            
    }//zoomOut
    
    FoliaMap.prototype.ZoomIn = function() {
    
        var zoombarHandler = document.getElementById(this.name + "zoombarHandler");
        var zoombarBackGround = document.getElementById(this.name + "zoombarBack");        
        var y = this.getElementPosition(zoombarHandler).y;
        var yBack = this.getElementPosition(zoombarBackGround).y;        
        
        if (this.zLevel - 1 >= 0) this.zIn();
            
    } //zoomOut
            
    FoliaMap.prototype.setZoomSlider = function(zoomLevel) {
        try {
            var zoombarHandler = document.getElementById(this.name + "zoombarHandler");
            zoombarHandler.style.top = ( 14 + 7 + zoomLevel * 13 ) + "px";
        } catch(event) {
            //void
        }
    } //setZoomSlider
        
    FoliaMap.prototype.SliderMouseDown = function() {
        this.fZoomSliderDragFlag = true;
    } //SliderMouseDown
    
    FoliaMap.prototype.SliderMouseUp = function(e) {
        if(this.fZoomSliderDragFlag) {
            var zoomSlider = document.getElementById(this.name + "zoombarHandler");
            var pos = this.getMousePos(this.name + "zoombarEvent",e);
            var newZLevel = pos.y - 8;
                newZLevel = Math.round(newZLevel / 13);
            if(newZLevel > (this.zLevels.length -1 ) ) newZLevel = this.zLevels.length -1;
            if ( newZLevel < 0 ) newZLevel = 0;
            this.zoom(newZLevel);
            this.fZoomSliderDragFlag = false;
        }
    } //SliderMouseUp

    FoliaMap.prototype.SliderMouseMove = function (e) {
        var zoomSlider = document.getElementById(this.name + "zoombarHandler");
        var pos = this.getMousePos(this.name + "zoombarEvent",e);
        
        if (this.fZoomSliderDragFlag && pos.y > 0 && pos.y <= (7 + this.zLevels.length * 13) )
        {
            zoomSlider.style.top = pos.y + 14 + "px";
        }
    } //SliderMouseMove
    
    FoliaMap.prototype.SliderMouseOut = function(e) {
        this.SliderMouseUp(e);
        //this.fZoomSliderDragFlag = false;
    } //SliderMouseOut

    FoliaMap.prototype.FAddMapStyleControl = function(classic, ortho, combi, pictometry) {

        this.mapstyle = document.createElement("div");
        this.mapstyle.setAttribute('id',this.name + "divMapstyle");
        this.mapholder.appendChild(this.mapstyle);
        
        this.cartograpyCtrlExists = true;
        this.cartograpybtns = new Object();

        var argv = new Array (
            "classic",
            "ortho",
            "combi",
            "pictometry"
        );

        for (var c = 0; c < arguments.length; c++ ) {
            btnName = argv[c];
            this.cartograpybtns.btnName = document.createElement("img");
            this.cartograpybtns.btnName.setAttribute('id',this.name + "map" + btnName + "Btn");
            this.cartograpybtns.btnName.src = this.gfxPath + btnName + "btn.gif";
            this.cartograpybtns.btnName.style.width = "117px";
            this.cartograpybtns.btnName.style.height = "18px";            
            this.addEventHandler(this.cartograpybtns.btnName,"click",this[btnName +  "BtnClickHandler"].bind(this));
            this.mapstyle.appendChild(this.cartograpybtns.btnName);
            if (arguments[c])
                this.cartograpybtns.btnName.style.visibility = "visible";
            else
                this.cartograpybtns.btnName.style.visibility = "hidden";
        }//for

         this.setMapStyle(this.fMtwstyle);            
    }//FAddMapStyleControl


    FoliaMap.prototype.classicBtnClickHandler = function() {
        this.changeMapStyle("classic");
    }
    
    FoliaMap.prototype.combiBtnClickHandler = function() {
        this.changeMapStyle("combi");
    }
    
    FoliaMap.prototype.orthoBtnClickHandler = function() {
        this.changeMapStyle("ortho");
    }
               
    FoliaMap.prototype.pictometryBtnClickHandler = function() {
        this.changeMapStyle("pictometry");
    }

    FoliaMap.prototype.FAddPanControl = function(pantype) {
        
        //sets panHorizSize and panVertSize
        var panHorizSize = (this.displayWidth - 52) * 0.5;
        var panVertSize = (this.displayHeight - 52) * 0.5;
        var mapHorizSize = this.displayWidth - 32;
        var mapVertSize = this.displayHeight - 32;
        
        var imgS;
        var imgE;
        var i=0;
        
        var pan = new Object();
        pan["pan_N_"] = new Array(f_panNord,panNGfx,panNBack);
        pan["pan_S_"] = new Array(f_panSyd,panSGfx,panSBack);
        pan["pan_E_"] = new Array(f_panOest,panEGfx,panRBack);
        pan["pan_W_"] = new Array(f_panVest,panWGfx,panLBack);
            
        if (pantype == "advanced") { //creates extra pan options and place pan controls around map
        
            for(var panname in pan) {
                this.panname = document.createElement("div");
                this.panname.setAttribute("id", this.name + panname); 
                this.panname.style.backgroundImage = "url('" + gfxFolderPan + pan[panname][2] + "')";
                this.panname.style.position = "absolute";
                this.panname.style.zIndex = 20;
                var panimg = document.createElement("img");
                if (i==2) imgE = panimg;
                if (i==1) imgS = panimg;
                panimg.setAttribute("id",this.name + panname + "i");
                panimg.setAttribute("alt",pan[panname][0]);
                panimg.setAttribute("title",pan[panname][0]);
                panimg.src = gfxFolderPan + pan[panname][1];
                panimg.style.cursor = "pointer";
                this.addEventHandler(panimg,"click",this.mapPan.bind(this));
                this.panname.appendChild(panimg);
                this.mapholder.appendChild(this.panname);
                i++;
            }//for
            

            var pan = new Object();
            pan["pan_NW_"] = new Array(f_panNordVest,panNWGfx);
            pan["pan_NW_Back"] = new Array(f_panNordVest, panNWBackGfx);
            pan["pan_NW_H"] = new Array(f_panNordVest,panNWHGfx);
            pan["pan_NW_V"] = new Array(f_panNordVest,panNWVGfx);
            pan["pan_NE_"] = new Array(f_panNordOest,panNEGfx);
            pan["pan_NE_Back"] = new Array(f_panNordOest, panNEBackGfx);
            pan["pan_NE_H"] = new Array(f_panNordOest,panNEHGfx);
            pan["pan_NE_V"] = new Array(f_panNordOest,panNEVGfx);
            pan["pan_SE_"] = new Array(f_panSydOest,panSEGfx);
            pan["pan_SE_Back"] = new Array(f_panSydOest, panSEBackGfx);
            pan["pan_SE_H"] = new Array(f_panSydOest,panSEHGfx);
            pan["pan_SE_V"] = new Array(f_panSydOest,panSEVGfx);
            pan["pan_SW_"] = new Array(f_panSydVest,panSWGfx);
            pan["pan_SW_Back"] = new Array(f_panSydVest, panSWBackGfx);
            pan["pan_SW_H"] = new Array(f_panSydVest,panSWHGfx);
            pan["pan_SW_V"] = new Array(f_panVest,panSWVGfx);
        

            for(var panname in pan) {
                var panimg = document.createElement("img");
                panimg.setAttribute("id",this.name + "img_" + panname);
                panimg.setAttribute("alt",pan[panname][0]);
                panimg.setAttribute("title",pan[panname][0]);
                panimg.src = gfxFolderPan + pan[panname][1];
                panimg.style.cursor = "pointer";
                panimg.style.position = "absolute";
                panimg.style.zIndex = 15;
                this.addEventHandler(panimg,"click",this.mapPan.bind(this));
                this.mapholder.appendChild(panimg);
            }//for
            
            //sets style
            var height = parseInt( this.navbox.style.height );
            var width = parseInt( this.navbox.style.width );
            
            var panNWBack = document.getElementById(this.name + "img" + "_pan_NW_Back");
            panNWBack.style.left = "0px";
            panNWBack.style.top = "0px";
            panNWBack.style.width = panBackCornerWidth_Height + "px";
            panNWBack.style.height = panBackCornerWidth_Height + "px";
            this.addEventHandler(panNWBack, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNWBack, "mouseout", this.swapImgOut.bind(this));
            
            var panNWH = document.getElementById(this.name + "img" + "_pan_NW_H");
            panNWH.style.left = panBackCornerWidth_Height + "px";
            panNWH.style.top = "0px";
            panNWH.style.width = panHorizWidth + "px";
            panNWH.style.height = panHorizHeight + "px";
            this.addEventHandler(panNWH, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNWH, "mouseout", this.swapImgOut.bind(this));
            
            var panNWV = document.getElementById(this.name + "img" + "_pan_NW_V");
            panNWV.style.left = "0px";
            panNWV.style.top = panBackCornerWidth_Height + "px";
            panNWV.style.width = panVertWidth + "px";
            panNWV.style.height = panVertHeight + "px";
            this.addEventHandler(panNWV, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNWV, "mouseout", this.swapImgOut.bind(this));
            
            var panNW = document.getElementById(this.name + "img" + "_pan_NW_");
            panNW.style.left = "2px";
            panNW.style.top = "2px";
            panNW.style.width = panArrowsWidth_Height + "px";
            panNW.style.height = panArrowsWidth_Height + "px";
            panNW.style.zIndex = 16;
            this.addEventHandler(panNW, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNW, "mouseout", this.swapImgOut.bind(this));
        
            var panNEBack = document.getElementById(this.name + "img" + "_pan_NE_Back");
            panNEBack.style.left = width - panBackCornerWidth_Height + 2 + "px";
            panNEBack.style.top = "0px";
            panNEBack.style.width = panBackCornerWidth_Height + "px";
            panNEBack.style.height = panBackCornerWidth_Height + "px";
            this.addEventHandler(panNEBack, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNEBack, "mouseout", this.swapImgOut.bind(this));
            
            var panNEH = document.getElementById(this.name + "img" + "_pan_NE_H");
            panNEH.style.left = width - panBackCornerWidth_Height - panHorizWidth + 2 + "px";
            panNEH.style.top = "0px";
            panNEH.style.width = panHorizWidth + "px";
            panNEH.style.height = panHorizHeight + "px";
            this.addEventHandler(panNEH, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNEH, "mouseout", this.swapImgOut.bind(this));
            
            var panNEV = document.getElementById(this.name + "img" + "_pan_NE_V");
            panNEV.style.left = width - panVertWidth + 2 + "px";
            panNEV.style.top = panBackCornerWidth_Height + "px";
            panNEV.style.width = panVertWidth + "px";
            panNEV.style.height = panVertHeight + "px";
            this.addEventHandler(panNEV, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNEV, "mouseout", this.swapImgOut.bind(this));
            
            var panNE = document.getElementById(this.name + "img" + "_pan_NE_");
            panNE.style.left = width - panArrowsWidth_Height + "px";
            panNE.style.top = "2px";
            panNE.style.width = panArrowsWidth_Height + "px";
            panNE.style.height = panArrowsWidth_Height + "px";
            panNE.style.zIndex = 16;
            this.addEventHandler(panNE, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panNE, "mouseout", this.swapImgOut.bind(this));
            
            var panSWBack = document.getElementById(this.name + "img" + "_pan_SW_Back");
            panSWBack.style.left = "0px";
            panSWBack.style.top = height - panBackCornerWidth_Height + 2 + "px";
            panSWBack.style.width = panBackCornerWidth_Height + "px";
            panSWBack.style.height = panBackCornerWidth_Height + "px";
            this.addEventHandler(panSWBack, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSWBack, "mouseout", this.swapImgOut.bind(this));
            
            var panSWH = document.getElementById(this.name + "img" + "_pan_SW_H");
            panSWH.style.left =  panBackCornerWidth_Height + "px";
            panSWH.style.top = height - panVertWidth + 2 + "px";
            panSWH.style.width = panHorizWidth + "px";
            panSWH.style.height = panHorizHeight + "px";
            this.addEventHandler(panSWH, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSWH, "mouseout", this.swapImgOut.bind(this));
            
            var panSWV = document.getElementById(this.name + "img" + "_pan_SW_V");
            panSWV.style.left = "0px";
            panSWV.style.top = height - panVertHeight - panBackCornerWidth_Height + 2 + "px";
            panSWV.style.width = panVertWidth + "px";
            panSWV.style.height = panVertHeight + "px";
            this.addEventHandler(panSWV, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSWV, "mouseout", this.swapImgOut.bind(this));
        
            var panSW = document.getElementById(this.name + "img" + "_pan_SW_");
            panSW.style.top = height - panArrowsWidth_Height + "px";
            panSW.style.left = "2px";
            panSW.style.width = panArrowsWidth_Height + "px";
            panSW.style.height = panArrowsWidth_Height + "px";
            panSW.style.zIndex = 16;
            this.addEventHandler(panSW, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSW, "mouseout", this.swapImgOut.bind(this));
            
            var panSEBack = document.getElementById(this.name + "img" + "_pan_SE_Back");
            panSEBack.style.left = width - panBackCornerWidth_Height + 2 + "px";
            panSEBack.style.top = height - panBackCornerWidth_Height + 2 + "px";
            panSEBack.style.width = panBackCornerWidth_Height + "px";
            panSEBack.style.height = panBackCornerWidth_Height + "px";
            this.addEventHandler(panSEBack, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSEBack, "mouseout", this.swapImgOut.bind(this));
        
            var panSEH = document.getElementById(this.name + "img" + "_pan_SE_H");
            panSEH.style.left =  width - panHorizWidth - panBackCornerWidth_Height + 2 + "px";
            panSEH.style.top = height - panVertWidth + 2 + "px";
            panSEH.style.width = panHorizWidth + "px";
            panSEH.style.height = panHorizHeight + "px";
            this.addEventHandler(panSEH, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSEH, "mouseout", this.swapImgOut.bind(this));
            
            var panSEV = document.getElementById(this.name + "img" + "_pan_SE_V");
            panSEV.style.left = width - panVertWidth + 2 + "px";
            panSEV.style.top = height - panVertHeight - panBackCornerWidth_Height + 2 + "px";
            panSEV.style.width = panVertWidth + "px";
            panSEV.style.height = panVertHeight + "px";
            this.addEventHandler(panSEV, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSEV, "mouseout", this.swapImgOut.bind(this));
            
            var panSE = document.getElementById(this.name + "img" + "_pan_SE_");
            panSE.style.top = height - panArrowsWidth_Height + "px";
            panSE.style.left = width - panArrowsWidth_Height + "px";
            panSE.style.width = panArrowsWidth_Height + "px";
            panSE.style.height = panArrowsWidth_Height + "px";
            panSE.style.zIndex = 16;
            this.addEventHandler(panSE, "mouseover", this.swapImgOver.bind(this));
            this.addEventHandler(panSE, "mouseout", this.swapImgOut.bind(this));
            
            var panBackTop = document.getElementById(this.name + "pan_N_");
            panBackTop.style.backgroundRepeat = "repeat-x";
            panBackTop.style.top = 0 +"px";
            panBackTop.style.left = panBackCornerWidth_Height + panHorizWidth + "px";
            panBackTop.style.width = width - (panBackCornerWidth_Height * 2) - (panHorizWidth * 2) + 2 +"px";
            panBackTop.style.height = panHorizHeight + "px";
            panBackTop.style.cursor = "pointer";
            panBackTop.setAttribute("alt",f_panNord);
            panBackTop.setAttribute("title",f_panNord);
            this.addEventHandler(panBackTop, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panBackTop, "mouseout", this.swapImgOutSimple.bind(this));
            this.addEventHandler(panBackTop,"click",this.mapPan.bind(this));
            
            var panBackBottom = document.getElementById(this.name + "pan_S_");
            panBackBottom.style.backgroundRepeat = "repeat-x";
            panBackBottom.style.top = height - panHorizHeight + 2 + "px";
            panBackBottom.style.left = panBackCornerWidth_Height + panHorizWidth + "px";
            panBackBottom.style.width = width - (panBackCornerWidth_Height * 2) - (panHorizWidth * 2) + 2 + "px";
            panBackBottom.style.height = panHorizHeight + "px";
            panBackBottom.style.cursor = "pointer";
            panBackBottom.setAttribute("alt",f_panSyd);
            panBackBottom.setAttribute("title",f_panSyd);
            this.addEventHandler(panBackBottom, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panBackBottom, "mouseout", this.swapImgOutSimple.bind(this));
            this.addEventHandler(panBackBottom,"click",this.mapPan.bind(this));
            
            var panBackLeft = document.getElementById(this.name + "pan_W_");
            panBackLeft.style.backgroundRepeat = "repeat-y";
            panBackLeft.style.top = panBackCornerWidth_Height + panVertHeight + "px";
            panBackLeft.style.left = "0px";
            panBackLeft.style.height = height - (panBackCornerWidth_Height * 2) - (panVertHeight * 2) + 2 + "px";
            panBackLeft.style.width = panVertWidth + "px";
            panBackLeft.style.cursor = "pointer";
            panBackLeft.setAttribute("alt",f_panVest);
            panBackLeft.setAttribute("title",f_panVest);
            this.addEventHandler(panBackLeft, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panBackLeft, "mouseout", this.swapImgOutSimple.bind(this));
            this.addEventHandler(panBackLeft,"click",this.mapPan.bind(this));
            
            var panBackRight = document.getElementById(this.name + "pan_E_");
            panBackRight.style.backgroundRepeat = "repeat-y";
            panBackRight.style.top = panBackCornerWidth_Height + panVertHeight + "px";
            panBackRight.style.left = width - panVertWidth + 2 + "px";
            panBackRight.style.width = panVertWidth + "px";
            panBackRight.style.height = height - (panBackCornerWidth_Height * 2) - (panVertHeight * 2) + 2 + "px";
            panBackRight.style.cursor = "pointer";
            panBackRight.setAttribute("alt",f_panOest);
            panBackRight.setAttribute("title",f_panOest);
            this.addEventHandler(panBackRight, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panBackRight, "mouseout", this.swapImgOutSimple.bind(this));
            this.addEventHandler(panBackRight,"click",this.mapPan.bind(this));
            
            var panN = document.getElementById(this.name + "pan_N_i");
            panN.style.position = "absolute";
            panN.style.top = "2px";
            panN.style.left = ((width - (panBackCornerWidth_Height * 2) - (panHorizWidth * 2) + 2) * 0.5) + "px";
            this.addEventHandler(panN, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panN, "mouseout", this.swapImgOutSimple.bind(this));
            
            var panE = document.getElementById(this.name + "pan_E_i");
            panE.style.position = "absolute";
            panE.style.top = ((height - (panBackCornerWidth_Height * 2) - (panVertHeight * 2) + 2) * 0.5) + "px";
            panE.style.left = "2px";
            this.addEventHandler(panE, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panE, "mouseout", this.swapImgOutSimple.bind(this));
            
            var panS = document.getElementById(this.name + "pan_S_i");
            panS.style.position = "absolute";
            panS.style.top = "2px";
            panS.style.left = ((width - (panBackCornerWidth_Height * 2) - (panHorizWidth * 2) + 2) * 0.5) + "px";
            this.addEventHandler(panS, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panS, "mouseout", this.swapImgOutSimple.bind(this));
            
            var panW = document.getElementById(this.name + "pan_W_i");
            panW.style.position = "absolute";
            panW.style.top = ((height - (panBackCornerWidth_Height * 2) - (panVertHeight * 2) + 2) * 0.5) + "px";
            panW.style.left = "2px";
            this.addEventHandler(panW, "mouseover", this.swapImgOverSimple.bind(this));
            this.addEventHandler(panW, "mouseout", this.swapImgOutSimple.bind(this));      
        }
        else {            
            //sets simple pan control style attributes when pan is in advanced mode
            var panN = document.getElementById(this.name + "simplepanN");
            panN.style.position = "absolute";
            panN.style.left = (width/2) + 1 + "px";
            panN.style.top = "-1px";
            panN.style.zIndex = 20;
            
            var panS = document.getElementById(this.name + "simplepanS");
            panS.style.position = "absolute";
            panS.style.left = (width/2) + "px";            
            panS.style.top = height - 15 + "px";
            panS.style.zIndex = 20;
            
            var panW = document.getElementById(this.name + "simplepanW");
            panW.style.position = "absolute";
            panW.style.top = height/2 +"px";
            panW.style.left = -3 +"px";
            panW.style.zIndex = 20;
            
            var panE = document.getElementById(this.name + "simplepanE");
            panE.style.position = "absolute";
            panE.style.top = height/2 +"px";
            panE.style.left = width - 13 + "px";
            panE.style.zIndex = 20;
        }

    }

    FoliaMap.prototype.swapImgOver = function(e) {
        if (!e) e = window.event;
        var elementId = e.target ?  e.target.id : e.srcElement.id;
        var ep = elementId.split(/_/);
        var basename = ep[0] + "_" + ep[1] + "_" + ep[2] + "_" + ep[3];
        var imgname = ep[2] + "_" + ep[3];
        var imgArray = ["_","_V","_H","_Back"];
        for(var c = 0; c < imgArray.length; c++) {
            document.getElementById(basename + imgArray[c]).src = gfxFolderPan + imgname + imgArray[c] + "_on.gif";
        }
    }

    FoliaMap.prototype.swapImgOut = function(e) {
        if (!e) e = window.event;
        var elementId = e.target ?  e.target.id : e.srcElement.id;
        var ep = elementId.split(/_/);
        var basename = ep[0] + "_" + ep[1] + "_" + ep[2] + "_" + ep[3];
        var imgname = ep[2] + "_" + ep[3];
        var imgArray = ["_","_V","_H","_Back"];
        for(var c = 0; c < imgArray.length; c++) {
            document.getElementById(basename + imgArray[c]).src = gfxFolderPan + imgname + imgArray[c] + ".gif";
        }
    }
    
    FoliaMap.prototype.swapImgOverSimple = function(e) {
        if (!e) e = window.event;
        var elementId = e.target ?  e.target.id : e.srcElement.id;

        var ep = elementId.split(/_/);
        var basename = ep[0] + "_" + ep[1] + "_" + ep[2];
        var imgname = ep[1] + "_" + ep[2];
        var imgArray = ["_i","_B"];
        var imgArray2 = ["_i","_"];
        for(var c = 0; c < imgArray.length; c++) {
            document.getElementById(basename + imgArray2[c]).src = gfxFolderPan + imgname + imgArray[c] + "_on.gif";
        }
        if (document.getElementsByTagName('img')) {
            elementId = ep[0] + "_" + ep[1] + "_" + ep[2] + "_";
            document.getElementById(elementId).style.backgroundImage = "url('" + gfxFolderPan + imgname + "_B_on.gif')";
        } else {
            document.getElementById(elementId).style.backgroundImage = "url('" + gfxFolderPan + imgname + "_B_on.gif')";
        }
        
    }

    FoliaMap.prototype.swapImgOutSimple = function(e) {
        if (!e) e = window.event;
        var elementId = e.target ?  e.target.id : e.srcElement.id;
        var ep = elementId.split(/_/);
        var basename = ep[0] + "_" + ep[1] + "_" + ep[2];
        var imgname = ep[1] + "_" + ep[2];
        var imgArray = ["_i","_B"];
        var imgArray2 = ["_i","_"];
        for(var c = 0; c < imgArray.length; c++) {
            document.getElementById(basename + imgArray2[c]).src = gfxFolderPan + imgname + imgArray[c] + ".gif";
        }
        if (document.getElementsByTagName('img')) {
            elementId = ep[0] + "_" + ep[1] + "_" + ep[2] + "_";
            document.getElementById(elementId).style.backgroundImage = "url('" + gfxFolderPan + imgname + "_B.gif')";
        } else {
            document.getElementById(elementId).style.backgroundImage = "url('" + gfxFolderPan + imgname + "_B.gif')";
        }
    }
    

    /*=====================================================
      Locator map utilities
      =====================================================*/

    /**
     * Adds the locator map.
     * @param width integer - the locator map width in pixels
     * @param height integer- the locator map height in pixels.
     * @param top integer   - the locator top position
     * @param left integer  - the locator left position
     * @param zlevel array  - an array that defines the zoomlevel relations between the main map and the locator
     *                      - e.g : Array(2,2,1,1,1,1,2,1,0) - if the map is at zoomlevel 1 the locater would be at zoomlevel 1 + 2
     * @return void
     **/
    FoliaMap.prototype.addLocator = function(width,height,top,left,zL) {

        if ( !this.locatorvars ) {
            this.locatorvars = {width:width,height:height,top:top,left:left};
            this.locatorvars["zLevel"] = zL;
        }

        if( this.locator ) this.mapholder.removeChild(this.locator.mapholder);

//        if ( this.locatorvars.zLevel[this.zLevel] ) {
//            var zoomLevel = this.zLevel + this.locatorvars.zLevel[this.zLevel];
//        } else {
//            var zoomLevel = this.zLevel;
//        }

//        if ( zoomLevel >= this.zLevels.length ) {
//            zoomLevel = this.zLevels.length - 1;
//        }
        //var diff = Math.round((this.zLevels[zoomLevel] - this.zLevels[this.zLevel]) / 2);
    
        this.updateBBox();

        var diffx = Math.round((((this.bbox.current.ex - this.bbox.current.ix) / this.zLevelsLocator[this.zLevel] ) * this.zLevelsLocator[this.zLevel+1]) / 2);
        var diffy = Math.round((((this.bbox.current.ey - this.bbox.current.iy) / this.zLevelsLocator[this.zLevel] ) * this.zLevelsLocator[this.zLevel+1]) / 2);

        this.locator = new FoliaMap(this.bbox.current.ix - diffx, this.bbox.current.iy - diffy, this.bbox.current.ex + diffx, this.bbox.current.ey + diffy, this.locatorvars.width, this.locatorvars.height, this.mapstyle, this.name + "locator", this.mapuser, this.mappasswd, this.language);
        this.locator.parentmap = this;

        var locator = document.body.removeChild(this.locator.mapholder);
        this.mapholder.appendChild(locator);

        this.locator.mapholder.style.position = "absolute";
        this.locator.mapholder.style.left = this.locatorvars.left + "px";
        this.locator.mapholder.style.top = this.locatorvars.top + "px";

        this.locator.addLocatorDragBox();

        //remove copyrightnotice
        this.locator.mapControls.removeChild(this.locator.copyrightDiv);
        
        //this.addEventHandler(this.locator.mapholder,"mouseup",this.locatorDragBoxMoveStopped.bind(this));
        

    }//addLocator


    /**
     * Add dragbox on locatormap
     **/
    FoliaMap.prototype.addLocatorDragBox = function() {

        this.locatorDragBox = Object();
        this.locatorDragBox.UTM = new Object();
        this.locatorDragBox.UTM.ix = this.parentmap.bbox.current.ix;
        this.locatorDragBox.UTM.iy = this.parentmap.bbox.current.iy;
        this.locatorDragBox.UTM.ex = this.parentmap.bbox.current.ex;
        this.locatorDragBox.UTM.ey = this.parentmap.bbox.current.ey;

        //debug(xmin + ', ' + ymin + ', ' + xmax + ', ' + ymax);

        var px_xmin = Math.round(( ( this.locatorDragBox.UTM.ix - this.bbox.ix ) / this.bbox.rel ));
        var px_ymin = ( this.displaySize * this.tileSize ) - Math.round(( ( this.locatorDragBox.UTM.iy - this.bbox.iy ) / this.bbox.rel ));
        var px_xmax = Math.round(( ( this.locatorDragBox.UTM.ex - this.bbox.ix ) / this.bbox.rel ));
        var px_ymax = ( this.displaySize * this.tileSize ) - Math.round(( ( this.locatorDragBox.UTM.ey - this.bbox.iy ) / this.bbox.rel ));

        this.locatorDragBox.box = document.createElement("div");
        this.locatorDragBox.box.setAttribute("id",this.name + "searchBox");
        this.locatorDragBox.box.style.position = "absolute";       
        this.locatorDragBox.box.style.top = (px_ymax + parseInt(this.mapbox.style.top)) + "px";
        this.locatorDragBox.box.style.left = (px_xmin + parseInt(this.mapbox.style.left)) + "px";
        this.locatorDragBox.box.style.height = px_ymin - px_ymax + "px";
        this.locatorDragBox.box.style.width = px_xmax - px_xmin + "px";
             
        this.locatorDragBox.box.style.border = "#000000 1px dotted";
        this.locatorDragBox.box.style.opasity = 0.5;
        this.locatorDragBox.box.style.filter =  "alpha(opacity=50)";
        this.locatorDragBox.box.style.MozOpacity = 0.5;
        this.locatorDragBox.box.style.backgroundColor = "#ffffff";
        this.locatorDragBox.box.style.zIndex = 9;
//        this.addEventHandler(this.locatorDragBox.box,"mouseover",this.disallowPan.bind(this));
//        this.addEventHandler(this.locatorDragBox.box,"mouseout",this.allowPan.bind(this));
//        this.addEventHandler(this.locatorDragBox.box,"mousedown",this.searchBoxSetHandle.bind(this));
//        this.addEventHandler(this.locatorDragBox.box,"mousemove",this.searchBoxMove.bind(this));
//        this.addEventHandler(this.locator.mapholder,"mouseup",this.locatorDragBoxMoveStopped.bind(this));
         
        //newbox.style.moz-opacity


        //NOTE
        this.searchboxLayer = document.createElement("div");
        this.searchboxLayer.style.position = "absolute";
        this.searchboxLayer.style.top = "0px";
        this.searchboxLayer.style.left = "0px";
        this.searchboxLayer.style.width = "900px";
        this.searchboxLayer.style.height = "900px";
        //this.addEventHandler(this.searchboxLayer,"mousemove",this.searchBoxScale.bind(this));
        //this.addEventHandler(this.searchboxLayer,"mouseup",this.searchBoxUnsetHandle.bind(this));
        //this.actionLayer.appendChild(this.searchboxLayer);

        
        //this.searchboxLayer.appendChild(this.locatorDragBox.box);
        
        //OBS!!! Denne kan udmarkeres for at fjerne søgeboksen i oversigtsvinduet - Jacob
        this.navbox.appendChild(this.locatorDragBox.box);

    }//addLocatorDragBox

    FoliaMap.prototype.locatorDragBoxMoveStopped = function() {
//        var xv = Math.round( (xMoveby * this.bbox.rel) / this.parentmap.bbox.rel);
//                var yv = Math.round((yMoveby * this.bbox.rel)/ this.parentmap.bbox.rel);

//                this.parentmap.xOffset = 0;
//                this.parentmap.yOffset = 0;
//                this.parentmap.display(false,xv,yv);
        //this.display();
        //alert("hey");
        //if (this.parentmap)
        //    alert("hey");
        //this.parentmap.setZoomLevel(this.zLevel, this.displayWidth/2, this.displayHeight/2);
    }
    

    
    /*=====================================================
      Boundary search box utilities
      =====================================================*/

    FoliaMap.prototype.addBSearchBox = function(xmin, ymin, xmax, ymax, addHandles) {

        if (addHandles == null) addHandles = true;
        
        this.BSBox = Object();
        this.BSBox.UTM = new Object();
        this.BSBox.UTM.ix = xmin;
        this.BSBox.UTM.iy = ymin;
        this.BSBox.UTM.ex = xmax;
        this.BSBox.UTM.ey = ymax;

        //debug(xmin + ', ' + ymin + ', ' + xmax + ', ' + ymax);

        var px_xmin = Math.round(( ( xmin - this.bbox.ix ) / this.bbox.rel ));
        var px_ymin = ( this.displaySize * this.tileSize ) - Math.round(( ( ymin - this.bbox.iy ) / this.bbox.rel ));
        var px_xmax = Math.round(( ( xmax - this.bbox.ix ) / this.bbox.rel ));
        var px_ymax = ( this.displaySize * this.tileSize ) - Math.round(( ( ymax - this.bbox.iy ) / this.bbox.rel ));

        this.BSBox.pixelDim = new Object();
        this.BSBox.pixelDim.top = (px_ymax + parseInt(this.mapbox.style.top));
        this.BSBox.pixelDim.left = (px_xmin + parseInt(this.mapbox.style.left));
        this.BSBox.pixelDim.width = px_xmax - px_xmin;
        this.BSBox.pixelDim.height = px_ymin - px_ymax;


        this.BSBox.box = document.createElement("div");
        this.BSBox.box.setAttribute("id",this.name + "searchBox");
        this.BSBox.box.style.position = "absolute";       
        this.BSBox.box.style.top = (px_ymax + parseInt(this.mapbox.style.top)) + "px";
        this.BSBox.box.style.left = (px_xmin + parseInt(this.mapbox.style.left)) + "px";
        this.BSBox.box.style.height = px_ymin - px_ymax + "px";
        this.BSBox.box.style.width = px_xmax - px_xmin + "px";
        
        this.BSBox.box.style.border = "#000000 1px dotted";
        this.BSBox.box.style.opasity = 0.5;
        this.BSBox.box.style.filter =  "alpha(opacity=50)";
        this.BSBox.box.style.MozOpacity = 0.5;
        this.BSBox.box.style.backgroundColor = "#ffffff";
        this.BSBox.box.style.zIndex = 9;
        this.addEventHandler(this.BSBox.box,"mouseover",this.disallowPan.bind(this));
        this.addEventHandler(this.BSBox.box,"mouseout",this.allowPan.bind(this));
        this.addEventHandler(this.BSBox.box,"mousedown",this.searchBoxSetHandle.bind(this));
        this.addEventHandler(this.BSBox.box,"mousemove",this.searchBoxMove.bind(this));
        //this.addEventHandler(this.BSBox.box,"mouseup",this.searchBoxMoveStopped.bind(this));
         
        //newbox.style.moz-opacity

        if (addHandles) {
            //add handles:
            var handles = {
                n:  { left:(parseInt(this.BSBox.box.style.width) /2) - 5 + "px", top:0 + "px", cursor:'n-resize'},
                ne: { right:0 + "px", top:0 + "px", cursor:'ne-resize'},
                e:  { right:0 + "px", top:(parseInt(this.BSBox.box.style.height) / 2) - 5 + "px", cursor:'e-resize'},
                se: { right:0 + "px", bottom:0 + "px", cursor:'se-resize'},
                s:  { left:(parseInt(this.BSBox.box.style.width) / 2) - 5 + "px", bottom:0 + "px", cursor:'s-resize'},
                sw: { left:0 + "px", bottom:0 + "px", cursor:'sw-resize'},
                w:  { left:0 + "px", top: (parseInt(this.BSBox.box.style.height)/2) - 5 + "px", cursor:'w-resize'},
                nw: { left:0 + "px",top:0 + "px", cursor:'nw-resize'}
            }

            for ( var handle in handles) {

                this.BSBox[handle] = document.createElement("div");
                this.BSBox[handle].setAttribute("id",this.name + handle);
                this.BSBox[handle].style.fontSize = "1px";
                this.BSBox[handle].style.width = "10px";
                this.BSBox[handle].style.height = "10px";
                this.BSBox[handle].style.backgroundColor = "#000000";
                this.BSBox[handle].style.position = "absolute";
                this.BSBox[handle].style.zIndex = 40;

                for( var pos in handles[handle] ) {
                    this.BSBox[handle].style[pos] = handles[handle][pos];
    //                this.addEventHandler(this.BSBox[handle],"mouseup",this.searchBoxUnsetHandle.bind(this));
                }//for

                this.BSBox.box.appendChild(this.BSBox[handle]);
                this.addEventHandler(this.BSBox[handle],"mouseover",this.disallowPan.bind(this));
                this.addEventHandler(this.BSBox[handle],"mousedown",this.searchBoxSetHandle.bind(this));
                this.addEventHandler(this.BSBox[handle],"mouseup",this.searchBoxUnsetHandle.bind(this));
            
            }//for
        } //if (addHandles)

        //NOTE
        this.searchboxLayer = document.createElement("div");
        this.searchboxLayer.style.position = "absolute";
        this.searchboxLayer.style.top = "0px";
        this.searchboxLayer.style.left = "0px";
        this.searchboxLayer.style.width = "900px";
        this.searchboxLayer.style.height = "900px";
        this.addEventHandler(this.searchboxLayer,"mousemove",this.searchBoxScale.bind(this));
        this.addEventHandler(this.searchboxLayer,"mouseup",this.searchBoxUnsetHandle.bind(this));
        this.actionLayer.appendChild(this.searchboxLayer);

        this.searchboxLayer.appendChild(this.BSBox.box);
    }//addBSearchBox

    FoliaMap.prototype.searchBoxSetHandle = function(e) {
        if (!e) e = window.event;
        this.searchBoxScaleOn = new Object();
        this.searchBoxScaleOn["handle"] = e.target ? e.target : e.srcElement;
        this.searchBoxScaleOn["xOffset"] = this.getMousePos(this.navbox.getAttribute("id"),e).x;
        this.searchBoxScaleOn["yOffset"] = this.getMousePos(this.navbox.getAttribute("id"),e).y;
        this.searchBoxScaleOn["width"] = parseInt(this.BSBox.box.style.width);
        this.searchBoxScaleOn["height"] = parseInt(this.BSBox.box.style.height);
        this.searchBoxScaleOn["top"] = parseInt(this.BSBox.box.style.top);
        this.searchBoxScaleOn["left"] = parseInt(this.BSBox.box.style.left);

    }//searchBoxSetHandle

    FoliaMap.prototype.searchBoxUnsetHandle = function(e) {
        delete this.searchBoxScaleOn;            
    }//searchBoxSetHandle

    FoliaMap.prototype.searchBoxMove = function(e) {

        this.BSBox.box.style.cursor = "move";
        
        if ( this.searchBoxScaleOn ) {

            if ( this.searchBoxScaleOn["handle"].getAttribute("id") == this.name + "searchBox" ) {
            
                this.BSBox.box.style.top = (this.searchBoxScaleOn["top"] + ( this.my - this.searchBoxScaleOn["yOffset"] )) + "px";
                this.BSBox.box.style.left = (this.searchBoxScaleOn["left"] + ( this.mx - this.searchBoxScaleOn["xOffset"] )) + "px";

            }//if

        }//if

        this.searchBoxUTMUpdate();

    }//searchBoxMove

    FoliaMap.prototype.searchBoxUTMUpdate = function(e) {

        //koordinater på mapbox findes er i vores nulpunkt for UTM
        var mapboxLeft = parseInt(this.mapbox.style.left);
        var mapboxTop = parseInt(this.mapbox.style.top);

        //koordinater på BSBox findes
        var BSBoxLeft = parseInt(this.BSBox.box.style.left);
        var BSBoxTop = parseInt(this.BSBox.box.style.top);


        //udregn
        var distX = ( mapboxLeft - BSBoxLeft ) * -1;
        var distY = parseInt(this.navbox.style.height) - (BSBoxTop + parseInt(this.BSBox.box.style.height));
        
        //convert to UTM
        this.BSBox.UTM = new Object();
        this.BSBox.UTM.ix = this.bbox.current.ix + ( BSBoxLeft * this.bbox.rel);
        this.BSBox.UTM.iy = this.bbox.current.iy + (distY * this.bbox.rel);
        this.BSBox.UTM.ex = this.BSBox.UTM.ix + ( parseInt(this.BSBox.box.style.width) * this.bbox.rel );
        this.BSBox.UTM.ey = this.BSBox.UTM.iy + ( parseInt(this.BSBox.box.style.height) * this.bbox.rel );

    }//searchBoxUTMUpdate


    FoliaMap.prototype.searchBoxScale = function(e) {
        var minBoxSize = 30;
        var north = function(o) {
            //change box position
            //debug(o.BSBox.box.style.height);
            try{
                o.BSBox.box.style.top = ( o.searchBoxScaleOn["top"] + ( o.my - o.searchBoxScaleOn["yOffset"])) + "px";

                o.BSBox.box.style.height = o.searchBoxScaleOn["height"] - ( o.my - o.searchBoxScaleOn["yOffset"] ) + "px";
                o.BSBox["e"].style.top = o.BSBox["w"].style.top = ((parseInt(o.BSBox.box.style.height) / 2) - 5) + "px";
            }
            catch(e){};
        }

        var south = function(o) {
            //change box position
            try{
                o.BSBox.box.style.height = o.searchBoxScaleOn["height"] + ( o.my - o.searchBoxScaleOn["yOffset"] ) + "px";
                o.BSBox["e"].style.top = o.BSBox["w"].style.top = ((parseInt(o.BSBox.box.style.height) / 2) - 5) + "px";
            }
            catch(e){};
        }

        var west = function(o) {
            //change box position
            try{
                o.BSBox.box.style.left = ( o.searchBoxScaleOn["left"] + ( o.mx - o.searchBoxScaleOn["xOffset"])) + "px";

                o.BSBox.box.style.width = o.searchBoxScaleOn["width"] - ( o.mx - o.searchBoxScaleOn["xOffset"] ) + "px";
                o.BSBox["s"].style.left = o.BSBox["n"].style.left = ((parseInt(o.BSBox.box.style.width) / 2) - 5) + "px";
            }
            catch(e){};
        }

        var east = function(o) {
            try{
                o.BSBox.box.style.width = o.searchBoxScaleOn["width"] + ( o.mx - o.searchBoxScaleOn["xOffset"] ) + "px";
                o.BSBox["s"].style.left = o.BSBox["n"].style.left = ((parseInt(o.BSBox.box.style.width) / 2) - 5) + "px";
            }
            catch(e){};
        }


        if(this.searchBoxScaleOn) {
            if (!e) e = window.event;

            switch( this.searchBoxScaleOn["handle"].getAttribute("id") ) {
                case this.name + "ne":
                    north(this);
                case this.name + "e":
                    east(this);
                    break;
                case this.name + "sw":
                    south(this);
                case this.name + "w":
                    west(this);
                    break;
                case this.name + "nw":
                    west(this);
                case this.name + "n":
                    north(this);
                    break;
                case this.name + "se":
                    east(this);
                case this.name + "s":
                    south(this);
                    break;
            }//switch
    
            this.searchBoxUTMUpdate();

        }//if
    }//searchBoxScale

    FoliaMap.prototype.FAddScaleBar = function() {
                
        this.showScalebar = true;
        
        this.scaleBar();
    }

    FoliaMap.prototype.scaleBar = function() {
        if (this.showScalebar) {
            if (document.getElementById(this.name + "scaleBar")){
                this.mapControls.removeChild(document.getElementById(this.name + "scaleBar"));
                this.mapControls.removeChild(document.getElementById(this.name + "scaleBarendleft"));
                this.mapControls.removeChild(document.getElementById(this.name + "scaleBarendright"));
                this.mapControls.removeChild(document.getElementById(this.name + "scaleBarText"));
            }

            var scaleSize;
            
            switch(this.zLevel){
                case 0:
                    scaleSize = 100;
                    break;
                case 1:
                    scaleSize = 300;
                    break;
                case 2:
                    scaleSize = 500;
                    break;
                case 3:
                    scaleSize = 1000;
                    break;
                case 4:
                    scaleSize = 5000;
                    break;
                case 5:
                    scaleSize = 25000;
                    break;
                case 6:
                    scaleSize = 50000;
                    break;
                case 7:
                    scaleSize = 100000;
                    break;
                case 8:
                    scaleSize = 500000;
                    break;
                case 9:
                    scaleSize = 1000000;
                    break;
            }

            var deltaX = this.bbox.ex-this.bbox.ix;

            var lineText = scaleSize < 1000 ? scaleSize + " M." : scaleSize/1000 + " km"
                    
            this.dist = new Object();
            this.dist.line = new Object();
            this.dist.text = new Object();
            
            this.dist.color = "#333333";
            
            this.dist.line = document.createElement("div");
       
            this.dist.line.width = scaleSize/(deltaX/this.mapwidth);
                            
            this.dist.line.height = 2;
            this.dist.line.top = this.mapheight-25;
            this.dist.line.left = 20; //this.mapheight/2)-(this.dist.line.width/2);
            
            this.dist.line.setAttribute("id", this.name + "scaleBar");
            this.dist.line.style.position = "absolute";
            this.dist.line.style.top = this.dist.line.top + "px";
            this.dist.line.style.left = this.dist.line.left + "px";
            this.dist.line.style.height = this.dist.line.height + "px";
            this.dist.line.style.width = this.dist.line.width + "px";
            this.dist.line.style.backgroundColor = this.dist.color;
            this.dist.line.style.border = "#FFFFFF 2px Solid"
            this.dist.line.style.fontSize = "1px";
            this.dist.line.style.zIndex = 10;
            this.mapControls.appendChild(this.dist.line);
            
            var topPadding;
            
            if (document.all){
                topPadding = 5;}
            else{
                topPadding = 7;}

            var ends = {
                endleft: {left:this.dist.line.left+"px", top:this.dist.line.top-topPadding+"px"},
                endright: {left:this.dist.line.left+this.dist.line.width-2+"px", top:this.dist.line.top-topPadding+"px"}
            }
            
            for (var end in ends){
                this.dist[end] = document.createElement("div");
                this.dist[end].setAttribute("id", this.name + "scaleBar" + end);
                this.dist[end].style.position = "absolute";
                this.dist[end].style.height = 16 + "px";
                this.dist[end].style.width = 2 + "px";
                this.dist[end].style.backgroundColor = this.dist.color;
                this.dist[end].style.border = "#FFFFFF 2px Solid";
                this.dist[end].style.fontSize = "1px";
                this.dist[end].innerHTML = "..";
                this.dist[end].style.zIndex = 10;
                                                                                                                                            
                for( var pos in ends[end] ) {
                    this.dist[end].style[pos] = ends[end][pos];
                }
                this.mapControls.appendChild(this.dist[end]);
            }
            
            this.dist.text = document.createElement("div");
            this.dist.text.setAttribute("id",this.name + "scaleBarText");
            this.dist.text.style.position = "absolute";
            this.dist.text.style.top = this.dist.line.top - 15 + "px";
            this.dist.text.style.left = this.dist.line.left+2 + "px";
            this.dist.text.style.height = "15px";
            this.dist.text.style.width = this.dist.line.width + "px";
            this.dist.text.style.zIndex = 10;
            this.dist.text.style.fontFamily = "Verdana, Arial";
            this.dist.text.style.fontSize = "10px";
            this.dist.text.style.fontWeight = "bold";
            this.dist.text.style.color = this.dist.color;
            this.dist.text.align = "center";
            this.dist.text.innerHTML = lineText;
            this.mapControls.appendChild(this.dist.text);   
        }
    }//insertDistanceMeasurer



    /*************************************************************************/
    /* FAddCopyrightLabel                                                    */
    /*************************************************************************/
    FoliaMap.prototype.FAddCopyrightLabel = function(targetDiv,left,bottom) {
    
        this.copyrightDiv = document.createElement("div");
        this.copyrightDiv.setAttribute("id", this.name + "copyright");
        this.copyrightDiv.style.position = "absolute";
        this.copyrightDiv.style.left = left + "px";
        this.copyrightDiv.style.bottom = bottom + "px";
        this.copyrightDiv.style.zIndex = "15";
        this.copyrightDiv.style.fontFamily = "verdana";
        this.copyrightDiv.style.fontSize = "8px";
        
        this.setCopyrightText();

        targetDiv.appendChild(this.copyrightDiv);
        
    }
    
    FoliaMap.prototype.changeCopyrightText = function(txt) {
    
        try {
            this.copyrightDiv.innerHTML = txt;
        }
        catch (e) {
        }
        
    }
   
    FoliaMap.prototype.setCopyrightText = function() {
 
      try {
            if (this.fMtwstyle == 30 || this.fMtwstyle == 130 || this.fMtwstyle == 230) {
                //this.copyrightDiv.style.fontColor = "#ffffff";                
                this.copyrightDiv.style.left = (this.mapwidth-105) + "px";
                this.copyrightDiv.innerHTML = "©2008 Folia, NAVTEQ";
            }
            else {
                //this.copyrightDiv.style.fontColor = "#000000";
                if (this.zLevel < 4) {
                    this.copyrightDiv.style.left = (this.mapwidth-112) + "px";
                    this.copyrightDiv.innerHTML = "©2008 Folia, Scankort";
                }
                else {
                    this.copyrightDiv.innerHTML = "©2008 Folia, TerraMetrics";
                    this.copyrightDiv.style.left = (this.mapwidth-122) + "px";
                }
            }
        }  
        catch (e) {
        } 
                         
    }
    
//    function setSize() {
//        var iframeElement = document.getElementById("iframe_info"); 
//        iframeElement.style.height = "100%";  
//        iframeElement.style.width = "100%";
//        debug("setSize");
//    }

