function AJAXMAP(v, cJ, eq, bH) {
    this.v = v;
    this.aQ = $(v);
    this.bf = null;
    this.eL = [];
    this.ad = 256;
    this.H = 0;
    this.C = 0;
    this.eG = 265960;
    this.eI = 6647720;
    this.cg = 265960;
    this.bW = 6647720;
    this.an = {
        'bottom': 0,
        'left': 0,
        'top': 0,
        'right': 0
    };
    this.o = {
        'bottom': 0,
        'left': 0,
        'top': 0,
        'right': 0
    };
    this.aY = {
        'bottom': 0,
        'left': 0,
        'top': 0,
        'right': 0
    };
    this.af = 0;
    this.ae = 0;
    this.cS = eq;
    this.l = 4;
    this.be = 19;
    this.bw = 1;
    this.cJ = cJ;
    this.webatlasTileServerLowerBound = 11;
    this.webatlasTileServerUpperBound = 14;
    this.bS = 1;
    this.aR = 0;
    this.aB = null;
    this.cF = false;
    this.P = {
        'x': 0,
        'y': 0
    };
    this.B = {
        'x': 0,
        'y': 0
    };
    this.aq = null;
    this.ct = null;
    this.dx = 0;
    this.ab = null;
    this.bD = 0;
    this.ak = {
        'x': 0,
        'y': 0
    };
    this.dL = 4326;
    this.aO = 'EPSG:4326';
    this.bk = false;
    this.bb = null;
    this.cI = null;
    this.U = null;
    this.aa = null;
    this.ca = false;
    this.K = [];
    this.eY = 0;
    this.aP = null;
    this.bH = bH ? bH : 'test';
    this.am = {};
    this.am['blank'] = new Image();
    this.am['loading'] = this.am['blank'];
    this.bs = [];
    this.bz = [];
    this.ay = [];
    this.ce = null;
    this.fc = null;
    this.trackCoords = null;
    this.bY = true;
    this.bF = WAAnnotationOpenBehaviour.Hover;
    this.dC = WAAnnotationCloseBehaviour.IconMouseOut;
    this.bR = false;
    this.dH = 0;
    this.dE = 0;
    this.by = true;
    this.aj = null;
    this.eV = {
        'x': 0,
        'y': 0
    };
    this.dF = true;
    this.cd = false;
    this.G = [];
    this.zoomCounter = 0;
    this.zoomTimerId = null;
    this.wmsLayerTimerId = null;
    this.bQ = 'default';
    this.dG = false;
};
AJAXMAP.ZOOMLEVELS = [56, 128, 256, 512, 1024, 2048, 5120, 10240, 20480, 40960, 81920, 131072, 262144, 524288, 1000000];
var WAAnnotationOpenBehaviour = {
    Disable: 1,
    Hover: 2,
    Click: 4,
    Manual: 8
};
var WAAnnotationCloseBehaviour = {
    IconMouseOut: 16,
    Manual: 32
};
AJAXMAP.prototype = {
    init: function(L, av, dg) {
        if (L) L = this.bv(L);
        if (av) {
            this.l = parseInt(av);
        }
        var latlon = L.transform('EPSG:4326');
        var pX = NGTools.LatLongToPixelXY(latlon.y, latlon.x, av)[0];
        var pY = NGTools.LatLongToPixelXY(latlon.y, latlon.x, av)[1];
        if (dg) {
            this.aR = dg;
        }
        this.bD = AJAXMAP.ZOOMLEVELS[this.l] / 256;
        if (L) {
            var eE = new Coordinate(L.x, L.y, L.srs);
        }
        this.dR();
        tileLayer = new Layer({
            'type': 'webatlastile',
            'visible': true,
            'name': 'Tile Webatlas'
        });
        this.addLayer(tileLayer);
        Event.observe(this.v + 'mouselayer', 'mousemove', this.ey.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'click', this.cG.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'mousedown', this.cD.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'mouseup', this.cr.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'mouseout', this.cn.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'mouseover', this.ck.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'dblclick', this.ew.bindAsEventListener(this));
        Event.observe(this.v + 'mouselayer', 'contextmenu', this.ee.bindAsEventListener(this));
        if (this.cS) {
            Event.observe(window, 'resize', this.resizeEventHandler.bindAsEventListener(this));
        }
        Event.observe($(this.v), "mousewheel", this.cQ.bindAsEventListener(this));
        Event.observe($(this.v), "DOMMouseScroll", this.cQ.bindAsEventListener(this));
        Event.observe(this.v, 'map:resized', this.hideAnnotationPopup.bindAsEventListener(this));
        Event.observe(this.v, 'map:moved', this.hideAnnotationPopup.bindAsEventListener(this));
        Event.observe(this.v, 'map:dragBegin', this.hideAnnotationPopup.bindAsEventListener(this));
        if (this.H == 0 && this.C == 0) {
            this.H = this.aQ.offsetWidth;
            this.C = this.aQ.offsetHeight;
        }
        if (this.H == 0 && this.C == 0) {
            this.dS();
        }
        this.o = {
            'bottom': pY + this.C / 2,
            'left': pX - this.H / 2,
            'top': pY - this.C / 2,
            'right': pX + this.H / 2
        };
        if (this.cS) {
            this.dQ(false);
            this.o = {
                'bottom': pY + this.C / 2,
                'left': pX - this.H / 2,
                'top': pY - this.C / 2,
                'right': pX + this.H / 2
            };
        } else { } if (L) this.bq(eE);
        this.dG = true;
    }, bq: function(L) {
        var latlon = L.transform('EPSG:4326');
        var pX = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[0];
        var pY = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[1];
        this.o = {
            'bottom': pY + this.C / 2,
            'left': pX - this.H / 2,
            'top': pY - this.C / 2,
            'right': pX + this.H / 2
        };
        this.bp(false);
        this.bi(L, false);
        this.updateBB();
        if (this.wmsLayerTimerId != null)
            clearTimeout(this.wmsLayerTimerId);
        this.flickWMSLayers();
        this.wmsLayerTimerId = setTimeout(this.updateWMSLayers.bind(this), 20);
    }, cD: function(J) {
        this.P = this.cL(J);
        this.ct = new Coordinate(this.an.left + (this.bD * this.P.x), this.an.top - (this.bD * this.P.y), this.aO);
        var lat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
        var lon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
        this.ct = new Coordinate(lon, lat, 'EPSG:4326');
        this.cF = true;
        if (this.cK(J) == "MIDDLE" && !this.bR) {
            this.ce.style.zIndex = '2';
            this.ca = true;
            this.U.style.display = 'block';
            this.U.style.top = this.B.y + "px";
            this.U.style.left = this.B.x + "px";
            this.U.style.width = "0px";
            this.U.style.height = "0px";
        }
        if (this.bQ == 'DrawBoundingBox') {
            this.ce.style.zIndex = '2';
            this.U.style.display = 'block';
            this.U.style.top = this.B.y + "px";
            this.U.style.left = this.B.x + "px";
            this.U.style.width = "0px";
            this.U.style.height = "0px";
        }
        $(this.v).fire("map:grabbed", {
            'mouseMapCoords': this.aq,
            'mouseCoords': this.B
        });
        J.stop();
    }, cG: function(J) {
        $(this.v).fire("map:mouseClicked", {
            'mouseMapCoords': this.aq,
            'mouseCoords': this.B
        });
    }, ee: function(J) { }, ew: function(J) {
        if (this.by) if (!this.bR) this.zoomIn(new Coordinate(this.aq.x, this.aq.y, 'EPSG:4326'));
    }, cr: function(J) {
        this.release(this.ak);
        this.U.style.display = 'none';
        var lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
        var lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
        this.ab = new Coordinate(lon, lat, 'EPSG:4326');
        if (this.ca && this.aa != null) {
            this.zoomOnBoundingBox(this.aa);
            this.aa = null;
            this.ca = false;
        }
        if (this.bQ == 'DrawBoundingBox' && this.aa != null) {
            var dY = {
                'bottom': this.aa.y1,
                'left': this.aa.x1,
                'top': this.aa.y2,
                'right': this.aa.x2
            };
            $(this.v).fire("map:boundingboxSelected", {
                'boundingbox': dY
            });
            this.aa = null;
        }
        $(this.v).fire("map:mouseUp", {
            'button': this.cK(J),
            'mouseMapCoords': this.aq,
            'mouseCoords': this.B
        });
    }, cn: function(J) {
        this.release(this.ak);
        $(this.v).fire("map:mouseOut");
    }, ck: function(J) {
        $(this.v).fire("map:mouseOver");
    }, ey: function(J) {
        this.B = this.cL(J);
        if (this.by) {
            if (this.cF) {
                this.dx++;
                if (this.dx % 3 == 0) {
                    if (this.ca) {
                        this.aa = {
                            'x1': 0,
                            'y1': 0,
                            'x2': 0,
                            'y2': 0
                        };
                        if (this.B.y < this.P.y) {
                            this.U.style.top = this.B.y + "px";
                            this.U.style.height = this.P.y - this.B.y + "px";
                            this.aa.y1 = NGTools.ytolatitudeatzoom(this.o.top + this.P.y, this.l);
                            this.aa.y2 = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                        } else {
                            this.U.style.top = this.P.y + "px";
                            this.U.style.height = this.B.y - this.P.y + "px";
                            this.aa.y1 = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                            this.aa.y2 = NGTools.ytolatitudeatzoom(this.o.top + this.P.y, this.l);
                        }
                        if (this.B.x < this.P.x) {
                            this.U.style.left = this.B.x + "px";
                            this.U.style.width = this.P.x - this.B.x + "px";
                            this.aa.x1 = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                            this.aa.x2 = NGTools.xtolongitudeatzoom(this.o.left + this.P.x, this.l);
                        } else {
                            this.U.style.left = this.P.x + "px";
                            this.U.style.width = this.B.x - this.P.x + "px";
                            this.aa.x2 = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                            this.aa.x1 = NGTools.xtolongitudeatzoom(this.o.left + this.P.x, this.l);
                        }
                    } else {
                        this.ak = {
                            'x': this.B.x - this.P.x,
                            'y': this.B.y - this.P.y
                        };
                        this.bh(this.ak, true);
                        $(this.v).fire("map:dragging", {
                            'offsetCoords': this.ak
                        });
                        if (!this.cd) {
                            $(this.v).fire("map:dragBegin", {
                                'mouseMapCoords': this.aq,
                                'mouseCoords': this.B,
                                'boundingBox': this.an
                            });
                            this.cd = true;
                        }
                    }
                }
            } else {
                var mouseLat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                var mouseLon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                this.aq = new Coordinate(mouseLon, mouseLat, this.aO);
            }
        }
        if (this.bQ == 'DrawBoundingBox') {
            this.aa = {
                'x1': 0,
                'y1': 0,
                'x2': 0,
                'y2': 0
            };
            if (this.B.y < this.P.y) {
                this.U.style.top = this.B.y + "px";
                this.U.style.height = this.P.y - this.B.y + "px";
                this.aa.y1 = NGTools.ytolatitudeatzoom(this.o.top + this.P.y, this.l);
                this.aa.y2 = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
            } else {
                this.U.style.top = this.P.y + "px";
                this.U.style.height = this.B.y - this.P.y + "px";
                this.aa.y1 = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                this.aa.y2 = NGTools.ytolatitudeatzoom(this.o.top + this.P.y, this.l);
            }
            if (this.B.x < this.P.x) {
                this.U.style.left = this.B.x + "px";
                this.U.style.width = this.P.x - this.B.x + "px";
                this.aa.x1 = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                this.aa.x2 = NGTools.xtolongitudeatzoom(this.o.left + this.P.x, this.l);
            } else {
                this.U.style.left = this.P.x + "px";
                this.U.style.width = this.B.x - this.P.x + "px";
                this.aa.x2 = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                this.aa.x1 = NGTools.xtolongitudeatzoom(this.o.left + this.P.x, this.l);
            }
        }
        $(this.v).fire("map:mouseMoved", {
            'mouseMapCoords': this.aq,
            'mouseCoords': this.B
        });
        var mouseLat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
        var mouseLon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
        this.aq = new Coordinate(mouseLon, mouseLat, this.aO);
        return false;
    }, setState: function(dB) {
        this.bQ = dB;
        if (dB == 'DrawBoundingBox') {
            this.disallowMouseNavigation();
        } else {
            this.allowMouseNavigation();
        }
    }, getState: function() {
        return this.bQ;
    }, move: function(ak, cT) {
        this.ak = ak;
        this.bh(this.ak, true);
        this.release(ak, cT);
    }, resizeEventHandler: function(e) {
        this.resize();
    }, resize: function(C, H) {
        this.aF();
        var user = false;
        if (C != null) {
            var M = H;
            var O = C;
            user = true;
        } else {
            var M = 0;
            var O = 0;
            if (window.innerWidth) {
                M = window.innerWidth;
                O = window.innerHeight;
            } else {
                M = document.compatMode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth;
                O = document.compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight;
            }
            if (M % 2) {
                M--;
            }
            if (O % 2) {
                O--;
            }
        }
        this.H = M;
        this.C = O;
        if (user) {
            $(this.v).style.width = M + "px";
            $(this.v).style.height = O + "px";
            if (this.aj != null) {
                this.aj.element.width = M;
                this.aj.element.height = O;
            }
        } else {
            aA = this.bZ($(this.v));
            aC = this.bU($(this.v));
            $(this.v).style.width = M - aC + "px";
            $(this.v).style.height = O - aA + "px";
            if (this.aj != null) {
                this.aj.element.width = M - aC;
                this.aj.element.height = O - aA;
            }
        }
        if (C == null) {
            this.H = M - aC;
            this.C = O - aA;
        }
        this.bp(true);
        this.updateBB();
        $(this.v).fire("map:resized");
    }, dS: function() {
        var M = 0;
        var O = 0;
        if (window.innerWidth) {
            M = window.innerWidth;
            O = window.innerHeight;
        } else {
            M = document.compatMode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth;
            O = document.compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight;
        }
        if (M % 2) {
            M--;
        }
        if (O % 2) {
            O--;
        }
        aA = this.bZ($(this.v));
        aC = this.bU($(this.v));
        this.H = M - aC;
        this.C = O - aA;
    }, dQ: function(load, C, H) {
        this.aF();
        var user = false;
        if (C != null) {
            var M = H;
            var O = C;
            user = true;
        } else {
            var M = 0;
            var O = 0;
            if (window.innerWidth) {
                M = window.innerWidth;
                O = window.innerHeight;
            } else {
                M = document.compatMode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth;
                O = document.compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight;
            }
            if (M % 2) {
                M--;
            }
            if (O % 2) {
                O--;
            }
        }
        this.H = M;
        this.C = O;
        aA = this.bZ($(this.v));
        aC = this.bU($(this.v));
        if (user) {
            $(this.v).style.width = M + "px";
            $(this.v).style.height = O + "px";
            if (this.aj != null) {
                this.aj.element.width = M - aC;
                this.aj.element.height = O - aA;
            }
        } else {
            $(this.v).style.width = M - aC + "px";
            $(this.v).style.height = O - aA + "px";
            if (this.aj != null) {
                this.aj.element.width = M - aC;
                this.aj.element.height = O - aA;
            }
        }
        if (C == null) {
            this.H = M - aC;
            this.C = O - aA;
        }
        this.bp(false);
        $(this.v).fire("map:resized");
    }, cs: function() {
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].type != 'wmsoverlay') {
                for (var c = 0; c < this.G[i].tiles.length; c++) {
                    for (var r = 0; r < this.G[i].tiles[c].length; r++) {
                        var A = this.G[i].tiles[c][r];
                        this.cU(A);
                    }
                }
            }
        }
    }, cL: function(J) {
        return {
            'x': Event.pointerX(J) - this.bU($(this.v)),
            'y': Event.pointerY(J) - this.bZ($(this.v))
        };
    }, bp: function(cB) {
        if (this.C == 0) this.C = 200;
        if (this.H == 0) this.H = 200;
        var rows = Math.ceil(this.C / this.ad) + 1;
        var cols = Math.ceil(this.H / this.ad) + 1;
        this.ff = rows;
        this.fg = cols;
        for (var i = 0; i < this.G.length; i++) {
            this.G[i].tiles = [];
            if (this.G[i].visible == true) {
                for (var c = 0; c < cols; c++) {
                    var dk = [];
                    var tX = NGTools.PixelXYToTileXY(this.o.left, this.o.top)[0];
                    var tY = NGTools.PixelXYToTileXY(this.o.left, this.o.top)[1];
                    var remX = NGTools.PixelXYToTileXYOffset(this.o.left, this.o.top)[0];
                    var remY = NGTools.PixelXYToTileXYOffset(this.o.left, this.o.top)[1];
                    this.af = -remX;
                    this.ae = -remY;
                    for (var r = 0; r < rows; r++) {
                        this.bS = this.bS == this.webatlasTileServerUpperBound ? this.bS = this.webatlasTileServerLowerBound : this.bS + 1;
                        var A = {
                            'element': null,
                            'qk': 0,
                            'posx': 256 * c,
                            'posy': 256 * r,
                            'tx': tX + c,
                            'ty': tY + r,
                            'xIndex': c,
                            'yIndex': r,
                            'host': this.bS,
                            'layer': this.G[i]
                        };
                        dk.push(A);
                    }
                    this.G[i].tiles.push(dk);
                }
            }
        }
        this.bh({
            'x': 0,
            'y': 0
        }, cB);
    }, bh: function(Q, cB) {
        if (!Q) {
            Q = {
                'x': 0,
                'y': 0
            };
        }
        this.bb.style.top = Q.y + "px";
        this.bb.style.left = Q.x + "px";
        for (i = 0; i < this.bs.length; i++) {
            var overlay = this.bs[i];
        }
        for (i = 0; i < this.bz.length; i++) {
            var overlay = this.bz[i];
            overlay.style.left = Q.x + 'px';
            overlay.style.top = Q.y + 'px';
        }
        this.aP.style.top = this.dH + Q.y + 'px';
        this.aP.style.left = this.dE + Q.x + 'px';
        for (i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            k.element.style.left = k.x + Q.x + 'px';
            k.element.style.top = k.y + Q.y + 'px';
        }
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].type != 'wmsoverlay') {
                for (var c = 0; c < this.G[i].tiles.length; c++) {
                    for (var r = 0; r < this.G[i].tiles[c].length; r++) {
                        var A = this.G[i].tiles[c][r];
                        A.posx = (A.xIndex * this.ad) + this.af + Q.x;
                        A.posy = (A.yIndex * this.ad) + this.ae + Q.y;
                        var bO = true;
                        if (A.posx > this.H) {
                            do {
                                A.xIndex -= this.G[i].tiles.length;
                                A.tx -= this.G[i].tiles.length;
                                A.posx = (A.xIndex * this.ad) + this.af + Q.x;
                            } while (A.posx > this.H);
                            if (A.posx + this.ad < 0) {
                                bO = false;
                            }
                        } else {
                            while (A.posx < -this.ad) {
                                A.xIndex += this.G[i].tiles.length;
                                A.tx += this.G[i].tiles.length;
                                A.posx = (A.xIndex * this.ad) + this.af + Q.x;
                            }
                            if (A.posx > this.H) {
                                bO = false;
                            }
                        }
                        if (A.posy > this.C) {
                            do {
                                A.yIndex -= this.G[i].tiles[c].length;
                                A.ty -= this.G[i].tiles[c].length;
                                A.posy = (A.yIndex * this.ad) + this.ae + Q.y;
                            } while (A.posy > this.C);
                            if (A.posy + this.ad < 0) {
                                bO = false;
                            }
                        } else {
                            while (A.posy < -this.ad) {
                                A.yIndex += this.G[i].tiles[c].length;
                                A.ty += this.G[i].tiles[c].length;
                                A.posy = (A.yIndex * this.ad) + this.ae + Q.y;
                            }
                            if (A.posy > this.C) {
                                bO = false;
                            }
                        }
                        if (cB && bO) {
                            this.cU(A);
                        }
                        if (A.element) {
                            A.element.style.top = A.posy + 'px';
                            A.element.style.left = A.posx + 'px';
                        }
                    }
                }
            }
        }
    }, addNavigationGUI: function(gui) {
        gui.mapControl = this;
        this.aB.appendChild(gui.element);
        gui.element.style.zIndex = 2;
    }, addDrawCanvas: function(canvasIn) {
        this.aj = canvasIn;
        this.aj.parent = this;
        var ao = this.v + 'canvas';
        this.aj.element.setAttribute('id', ao);
        this.bb.appendChild(this.aj.element);
        var M = 0;
        var O = 0;
        if (window.innerWidth) {
            M = window.innerWidth;
            O = window.innerHeight;
        } else {
            M = document.compatMode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth;
            O = document.compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight;
        }
        this.aj.element.width = this.H;
        this.aj.element.height = this.C;
        if (/msie/i.test(navigator.userAgent)) {
            var hack = G_vmlCanvasManager.initElement(this.getDrawCanvas().element);
            this.getDrawCanvas().element = hack;
            this.getDrawCanvas().useex = true;
        }
        canvas = this.aj.element;
        this.aj.surface = canvas.getContext("2d");
    }, getDrawCanvas: function() {
        return this.aj;
    }, centerOnCoords: function(T, mouse, eS) {
        T = this.bv(T);
        var coordsperpixel = 256 / AJAXMAP.ZOOMLEVELS[this.l];
        if (mouse) {
            var Q = {
                'x': Math.floor(((T.x - this.cg) * -coordsperpixel) + (this.B.x)),
                'y': Math.floor(((T.y - this.bW) * coordsperpixel) + (this.B.y))
            };
        } else {
            var Q = {
                'x': Math.floor(((T.x - this.cg) * -coordsperpixel) + (this.H / 2)),
                'y': Math.floor(((T.y - this.bW) * coordsperpixel) + (this.C / 2))
            };
        }
        this.dJ();
        this.bh(Q, true);
        if (eS) this.release(Q, true);
        else this.release(Q, false);
        var lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
        var lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
        this.ab = new Coordinate(lon, lat, 'EPSG:4326');
    }, bi: function(T, mouse) {
        T = this.bv(T);
        screenCoords = this.llToScreen(T);
        if (mouse) {
            var diffX = this.B.x;
            var diffY = this.B.y;
            var Q = {
                'x': Math.floor((diffX - screenCoords.x)),
                'y': Math.floor(diffY - screenCoords.y)
            };
        } else {
            var diffX = this.H / 2;
            var diffY = this.C / 2;
            var Q = {
                'x': Math.floor((diffX - screenCoords.x)),
                'y': Math.floor(diffY - screenCoords.y)
            };
        }
        this.dJ();
        this.bh(Q, true);
        this.release(Q, false);
    }, addAnnotation: function(k) {
        screenCoords = this.llToScreen(k.coordinate);
        var div = document.createElement('div');
        div.setAttribute('id', k.id);
        var img = document.createElement('img');
        $(img).addClassName("annotationIcon");
        k.element = div;
        k.parent = this;
        Event.observe(k.element, 'click', k.cG.bindAsEventListener(k));
        Event.observe(k.element, 'mouseover', k.ck.bindAsEventListener(k));
        Event.observe(k.element, 'mouseout', k.cn.bindAsEventListener(k));
        Event.observe(k.element, 'mouseup', k.cr.bindAsEventListener(k));
        Event.observe(k.element, 'mousedown', k.cD.bindAsEventListener(k));
        img.src = k.iconURL;
        div.style.position = "absolute";
        div.style.left = screenCoords.x + k.xOffset + 'px';
        div.style.top = screenCoords.y + k.yOffset + 'px';
        k.x = screenCoords.x + k.xOffset;
        k.y = screenCoords.y + k.yOffset;
        div.appendChild(img);
        k.img = img;
        div.appendChild(img);
        this.aB.appendChild(k.element);
        k.element.style.zIndex = 1;
        this.K.push(k);
        return k.id;
    }, llToScreen: function(L) {
        var latlon = L.transform('EPSG:4326');
        var pX = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[0];
        var pY = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[1];
        pX = pX - this.o.left;
        pY = pY - this.o.top;
        return new Coordinate(pX, pY);
    }, removeAnnotation: function(id) {
        for (var i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            if (k.id == id) {
                this.aB.removeChild(k.element);
                this.K.splice(i, 1);
                return;
            }
        }
    }, removeAnnotationGroup: function(eg) {
        var removed = 0;
        do {
            removed = 0;
            for (var i = 0; i < this.K.length; i++) {
                var k = this.K[i];
                if (k.group == eg) {
                    this.aB.removeChild(k.element);
                    this.K.splice(i, 1);
                    removed = 1;
                    break;
                }
            }
        } while (removed == 1);
    }, getAnnotation: function(id) {
        for (i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            if (k.id == id) {
                return k;
            }
        }
    }, getAnnotations: function() {
        return this.K;
    }, hasValue: function(bX) {
        return (typeof bX != "undefined") && bX != null && (typeof bX == "string" ? bX != "" : true);
    }, showAnnotationPopup: function(k) {
        if ((this.bY && this.bF != WAAnnotationOpenBehaviour.Disable) && (this.hasValue(k.title) || this.hasValue(k.description))) {
            this.aP.innerHTML = k.title + '<p>' + k.description + '</p>';
            var bn = 0;
            var bl = 0;
            if (k.x > this.H - 250) {
                bn = -275;
            } else {
                bn = 25;
            }
            if (k.y < 150) {
                bl = 0;
            } else {
                bl = -150;
            }
            this.aP.style.top = k.y + bl + 'px';
            this.aP.style.left = k.x + bn + 'px';
            this.dE = k.x + bn;
            this.dH = k.y + bl;
            if (this.bF == WAAnnotationOpenBehaviour.Hover) {
                this.popupTimerId = setTimeout((function() {
                    $(this.v + 'annotation_popup').style.display = 'block';
                    $(this.v).fire("map:annotationOpened", {
                        'annotation': k,
                        'element': this.aP
                    });
                }).bind(this), 700);
            } else {
                this.aP.style.display = "block";
                $(this.v).fire("map:annotationOpened", {
                    'annotation': k,
                    'element': this.aP
                });
            }
        }
    }, hideAnnotationPopup: function(k) {
        clearTimeout(this.popupTimerId);
        $(this.v + 'annotation_popup').style.display = 'none';
    }, addLayer: function(bu) {
        bu.id = "layer_" + this.G.length;
        this.G.push(bu);
        if (this.dG == true) {
            this.aF();
            this.bp(true);
            if (bu.type == "wmsoverlay") this.cW();
        }
        return bu.id;
    }, removeLayer: function(eQ) {
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].id == eQ) {
                this.G.splice(i, 1);
                return;
            }
        }
    }, showLayer: function(id, zindex) {
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].id == id) {
                if (zindex) {
                    this.G[i].zindex = zindex;
                }
                if (this.G[i].visible == false) {
                    this.G[i].visible = true;
                    this.aF();
                    this.bp(true);
                }
            }
        }
    }, hideLayer: function(id) {
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].id == id) if (this.G[i].visible == true) {
                this.G[i].visible = false;
                this.aF();
                this.bp(true);
            }
        }
        this.cs();
    }, getLayers: function() {
        return this.G;
    }, dT: function(Q) {
        for (i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            k.x = k.x + Q.x;
            k.y = k.y + Q.y;
        }
    }, dJ: function() {
        for (var i = 0; i < this.K.length; i++) {
            k = this.K[i];
            screenCoords = this.llToScreen(k.coordinate);
            k.x = screenCoords.x + k.xOffset;
            k.y = screenCoords.y + k.yOffset;
            k.element.style.left = k.x + 'px';
            k.element.style.top = k.y + 'px';
        }
    }, refreshAnnotations: function() {
        for (var i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            if (k.upperbound < this.l || k.lowerbound > this.l) {
                k.element.style.display = 'none';
            } else {
                k.element.style.display = 'block';
            }
            var screenCoords = this.llToScreen(k.coordinate);
            k.x = screenCoords.x + k.xOffset;
            k.y = screenCoords.y + k.yOffset;
            k.element.style.left = k.x + 'px';
            k.element.style.top = k.y + 'px';
        }
    }, fe: function(annotation) {
        var k = annotation;
        if (k.upperbound < this.l || k.lowerbound > this.l) {
            k.element.style.display = 'none';
        } else {
            k.element.style.display = 'block';
        }
        var screenCoords = this.geoToScreenCoordinates(k.coordinate);
        k.x = screenCoords.x + k.xOffset;
        k.y = screenCoords.y + k.yOffset;
        k.element.style.left = k.x + 'px';
        k.element.style.top = k.y + 'px';
    }, clearAnnotations: function() {
        for (var i = 0; i < this.K.length; i++) {
            var k = this.K[i];
            this.aB.removeChild(k.element);
        }
        this.K = [];
    }, disableZoom: function() {
        this.bR = true;
    }, enableZoom: function() {
        this.bR = false;
    }, zoomIn: function(L) {
        if (this.l < this.be) {
            this.aF();
            if (!this.ab) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
                this.ab = new Coordinate(lon, lat, 'EPSG:4326');
            }
            if (L) {
                L = this.bv(L);
                this.ab = L;
            }
            this.af = 0;
            this.ae = 0;
            this.l = parseInt(this.l) + 1;
            this.bq(this.ab);
            this.bi(this.ab, false);
            $(this.v).fire("map:zoomedIn", {
                'boundingBox': this.an
            });
            $(this.v).fire("map:zoomed", {
                "zoomLevel": this.getZoomLevel()
            });
        }
    }, zoomOut: function(L) {
        if (this.l > this.bw) {
            this.aF();
            if (!this.ab) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
                this.ab = new Coordinate(lon, lat, 'EPSG:4326');
            }
            if (L) {
                L = this.bv(L);
                this.ab = L;
            }
            this.af = 0;
            this.ae = 0;
            this.l = parseInt(this.l) - 1;
            this.bq(this.ab);
            this.bi(this.ab, false);
            $(this.v).fire("map:zoomedOut", {
                'boundingBox': this.an
            });
            $(this.v).fire("map:zoomed", {
                "zoomLevel": this.getZoomLevel()
            });
        }
    }, mouseZoomIn: function() {
        if (this.l < this.be) {
            this.aF();
            var ar = null;
            var lat;
            var lon;
            if (!this.ab && !this.bk) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
                ar = new Coordinate(lon, lat, 'EPSG:4326');
            }
            if (this.bk) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                ar = new Coordinate(lon, lat, 'EPSG:4326');
            }
            this.af = 0;
            this.ae = 0;
            if (ar != null) {
                this.ab = ar;
            }
            this.l = parseInt(this.l) + 1;
            this.bq(this.ab);
            this.bi(this.ab, this.bk);
            $(this.v).fire("map:zoomedIn", {
                'boundingBox': this.an
            });
            $(this.v).fire("map:zoomed", {
                "zoomLevel": this.getZoomLevel()
            });
        }
    }, mouseZoomOut: function() {
        if (this.l > this.bw) {
            this.aF();
            var ar = null;
            var lat;
            var lon;
            if (!this.ab && !this.bk) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
                ar = new Coordinate(lon, lat, 'EPSG:4326');
            }
            if (this.bk) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
                ar = new Coordinate(lon, lat, 'EPSG:4326');
            }
            this.af = 0;
            this.ae = 0;
            if (ar != null) {
                this.ab = ar;
            }
            this.l = parseInt(this.l) - 1;
            this.bq(this.ab);
            this.bi(this.ab, this.bk);
            $(this.v).fire("map:zoomedIn", {
                'boundingBox': this.an
            });
            $(this.v).fire("map:zoomed", {
                "zoomLevel": this.getZoomLevel()
            });
        }
    }, zoom: function(level, L) {
        if (level >= this.bw && level <= this.be) {
            this.aF();
            if (!this.ab) {
                lat = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
                lon = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
                this.ab = new Coordinate(lon, lat, 'EPSG:4326');
            }
            if (L) {
                L = this.bv(L);
                this.ab = L;
            }
            this.af = 0;
            this.ae = 0;
            this.l = parseInt(level);
            this.bq(this.ab);
            this.bi(this.ab, false);
            $(this.v).fire("map:zoomed", {
                "zoomLevel": this.getZoomLevel()
            });
        }
    }, centerAndZoom: function(ar, level) {
        if (level == this.l) this.bi(ar, false);
        else this.zoom(level, ar);
    }, zoomOnBoundingBox: function(T, center, dm) {
        var eu = T.x2 - T.x1;
        var et = T.y2 - T.y1;
        var eW = this.H / 2;
        var eZ = this.C / 2;
        var ba = new Coordinate(T.x1 + (eu / 2), T.y1 + (et / 2), 'EPSG:4326');
        for (var i = this.be; i >= this.bw; i--) {
            var pX = NGTools.LatLongToPixelXY(ba.y, ba.x, i)[0];
            var pY = NGTools.LatLongToPixelXY(ba.y, ba.x, i)[1];
            var da = {
                'bottom': pY + this.C / 2,
                'left': pX - this.H / 2,
                'top': pY - this.C / 2,
                'right': pX + this.H / 2
            };
            var bottomLeft = NGTools.LatLongToPixelXY(T.y1, T.x1, i);
            var upperRight = NGTools.LatLongToPixelXY(T.y2, T.x2, i);
            var dc = {
                'bottom': bottomLeft[1],
                'left': bottomLeft[0],
                'top': upperRight[1],
                'right': upperRight[0]
            };
            if (da.left < dc.left && da.bottom > dc.bottom) {
                if (this.l == i && !center) {
                    return {
                        'zoom': i,
                        'coordinate': ba
                    };
                }
                if (!dm && this.l < this.be) {
                    this.zoom(i, ba);
                }
                return {
                    'zoom': i,
                    'coordinate': ba
                };
            }
        }
        if (!dm) {
            this.zoom(i, ba);
        }
        return {
            'zoom': i,
            'coordinate': ba
        };
    }, zoomOnAnnotations: function() {
        if (this.K.length == 0) {
            return;
        }
        var x1 = this.K[0].coordinate.x;
        var y1 = this.K[0].coordinate.y;
        var x2 = this.K[0].coordinate.x;
        var y2 = this.K[0].coordinate.y;
        for (i = 0; i < this.K.length; i++) {
            if (this.K[i].coordinate.x > x2) {
                x2 = this.K[i].coordinate.x;
            }
            if (this.K[i].coordinate.x < x1) {
                x1 = this.K[i].coordinate.x;
            }
            if (this.K[i].coordinate.y > y2) {
                y2 = this.K[i].coordinate.y;
            }
            if (this.K[i].coordinate.y < y1) {
                y1 = this.K[i].coordinate.y;
            }
        }
        this.zoomOnBoundingBox({
            'x1': x1,
            'y1': y1,
            'x2': x2,
            'y2': y2
        }, true);
    }, dR: function() {
        this.aQ.style.position = "absolute";
        this.aQ.style.zIndex = 10;
        this.aQ.style.overflow = "hidden";
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'tilelayer';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        this.aQ.appendChild(m);
        m.style.position = "absolute";
        m.style.top = "0px";
        m.style.left = "0px";
        m.style.width = "100%";
        m.style.height = "100%";
        m.style.overflow = "hidden";
        this.bf = m;
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'staticdrawlayer';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        m.style.position = "absolute";
        m.style.top = "0px";
        m.style.left = "0px";
        m.style.width = "100%";
        m.style.height = "100%";
        m.style.zIndex = 1000;
        this.aQ.appendChild(m);
        this.cI = m;
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'drawlayer';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        m.style.position = "absolute";
        m.style.top = "0px";
        m.style.left = "0px";
        m.style.width = "100%";
        m.style.height = "100%";
        m.style.zIndex = 1000;
        this.aQ.appendChild(m);
        this.bb = m;
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'mouselayer';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        m.style.position = "absolute";
        m.style.top = "0px";
        m.style.left = "0px";
        m.style.width = "100%";
        m.style.height = "100%";
        m.style.zIndex = 1000;
        m.style.overflow = "hidden";
        this.aQ.appendChild(m);
        this.aB = m;
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'zoomBox';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        this.aB.appendChild(m);
        m.style.position = "absolute";
        m.style.border = "solid 1px";
        m.style.width = "0px";
        m.style.height = "0px";
        m.style.top = "0px";
        m.style.left = "10px";
        m.style.display = 'none';
        m.style.zIndex = 2;
        this.U = m;
        var m = document.createElement('div');
        var ao = this.v + 'surface';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        m.style.position = "absolute";
        m.style.top = "0px";
        m.style.left = "0px";
        m.style.width = "100%";
        m.style.height = "100%";
        m.style.zIndex = 0;
        m.style.background = "url(http://tsadm.webatlas.no/sh/2/v/090602/media/interface/default/blank_1px.gif)";
        this.aB.appendChild(m);
        this.ce = m;
        var bC = document.getElementById(this.v);
        var m = document.createElement('div');
        var ao = this.v + 'annotation_popup';
        m.innerHTML = '<!-- -->';
        m.setAttribute('id', ao);
        this.aB.appendChild(m);
        m.style.position = "absolute";
        m.style.width = "250px";
        m.style.height = "150px";
        m.style.top = "29px";
        m.style.left = "130px";
        m.style.display = 'none';
        m.style.padding = '10px';
        m.style.zIndex = 1000;
        m.style.backgroundColor = 'white';
        m.style.border = 'solid 1px';
        this.aP = m;
    }, cU: function(A) {
        if (A.layer.lowerBound > this.l || A.layer.upperBound < this.l) return;
        var bL, bd;
        if (A.layer.type == 'webatlastile') {
            var qK = NGTools.TileXYToQuadKey(A.tx, A.ty, this.l);
            A.qk = qK;
            var tsAddress = parseInt(qK.charAt(qK.length - 1));
            bL = bd = 'http://cache' + (tsAddress + 1) + '.webatlas.no/qt_1881/' + A.qk + '.png?s=' + this.aR;
        }
        if (A.layer.type == 'osmtile') {
            bL = bd = 'http://b.tile.openstreetmap.org/' + this.l + '/' + A.tx + '/' + A.ty + '.png';
        } else if (A.layer.type == 'wms') {
            var x1 = NGTools.xtolongitudeatzoom(A.tx * 256, this.l);
            var x2 = NGTools.xtolongitudeatzoom(A.tx * 256 + 256, this.l);
            var y1 = NGTools.ytolatitudeatzoom(A.ty * 256 + 256, this.l);
            var y2 = NGTools.ytolatitudeatzoom(A.ty * 256, this.l);
            var m1 = this.toMercatorMeters(y1, x1);
            var m2 = this.toMercatorMeters(y2, x2);
            bL = bd = A.layer.wmsRequest.url + '?REQUEST=GetMap&SERVICE=' + A.layer.wmsRequest.service + '&SRS=EPSG:54004' + '&VERSION=' + A.layer.wmsRequest.version + '&FORMAT=' + A.layer.wmsRequest.format + '&LAYERS=' + A.layer.wmsRequest.layers + '&STYLES=' + A.layer.wmsRequest.styles + '&TRANSPARENT=' + A.layer.wmsRequest.transparent + '&BGCOLOR=' + A.layer.wmsRequest.bgColor + '&BBOX=' + m1.x + ',' + m1.y + ',' + m2.x + ',' + m2.y + '&WIDTH=256&HEIGHT=256&zoomlevel=' + this.l;
        }
        if (A.element != null && A.element.parentNode != null && A.element.relativeSrc != bd) {
            this.bf.removeChild(A.element);
        }
        var bj = this.am[bL];
        if (!bj) {
            bj = this.am[bL] = this.cE(bd);
        }
        bj.onload = null;
        if (bj.image) {
            bj.image.onload = null;
        }
        if (!bj.parentNode) {
            A.element = this.bf.appendChild(bj);
        }
        if (A.element != null) {
            A.element.style.zIndex = A.layer.zIndex;
        }
    }, toMercatorMeters: function(lat, lon) {
        a = 6378137.0;
        f = 1 / 298.257223563;
        e = Math.sqrt(2 * f - Math.pow(f, 2));
        ctrmerid = 0.0;
        px = lon * Math.PI / 180;
        py = lat * Math.PI / 180;
        pc = ctrmerid * Math.PI / 180;
        x = a * (px - pc);
        y = a * (Math.log(Math.tan((45.0 * Math.PI / 180) + py / 2.0) * Math.pow((1.0 - e * Math.sin(py)) / (1.0 + e * Math.sin(py)), e / 2.0)));
        return new Coordinate(x, y, "EPSG:54004");
    }, fd: function(tile, forceBlankImage) {
        var tileImgId, src;
        var useBlankImage = false;
        var dq = this.eG + (tile.xIndex * AJAXMAP.ZOOMLEVELS[this.l]);
        var dr = this.eI - (tile.yIndex * AJAXMAP.ZOOMLEVELS[this.l]) - AJAXMAP.ZOOMLEVELS[this.l];
        if (tile.layer.type == 'webatlastile') {
            tileImgId = src = 'http://ts' + tile.host + '.webatlas.no/?x1=' + dq + '&y1=' + dr + '&z=' + AJAXMAP.ZOOMLEVELS[this.l] + '&s=' + this.aR + '&l=1';
        }
        if (tile.element != null && tile.element.parentNode != null && tile.element.relativeSrc != src) {
            this.bf.removeChild(tile.element);
        }
        var tileImg = this.am[tileImgId];
        if (!tileImg) {
            tileImg = this.am[tileImgId] = this.cE(src);
        }
        var loadingImgId = 'loading:' + dq + ':' + dr;
        var loadingImg = this.am[loadingImgId];
        if (!loadingImg) {
            loadingImg = this.am[loadingImgId] = this.cE(this.am['loading'].src);
        }
        loadingImg.targetSrc = tileImgId;
        var well = this.bf;
        tile.element = well.appendChild(loadingImg);
        tileImg.onload = function() {
            if (loadingImg.parentNode && loadingImg.targetSrc == tileImgId) {
                tileImg.style.top = loadingImg.style.top;
                tileImg.style.left = loadingImg.style.left;
                well.replaceChild(tileImg, loadingImg);
                tile.element = tileImg;
            }
            tileImg.onload = null;
            return false;
        };
        if (tile.element != null) {
            tile.element.style.zIndex = tile.layer.zIndex - 1000;
        }
    }, toggleMapStyle: function() {
        if (this.aR == 0) {
            this.aR = 1;
        } else {
            this.aR = 0;
        }
        this.cs();
        this.bh({
            'x': 0,
            'y': 0
        });
    }, cE: function(bd) {
        var ai = document.createElement('img');
        ai.src = bd;
        ai.alt = "Loading Tile...";
        ai.relativeSrc = bd;
        ai.className = 'tile';
        ai.style.width = this.ad + 'px';
        ai.style.height = this.ad + 'px';
        ai.style.top = "-256px";
        ai.style.left = "-256px";
        ai.style.position = 'absolute';
        return ai;
    }, aF: function() {
        this.hideAnnotationPopup();
        this.eL = null;
        for (eF in this.am) {
            var ai = this.am[eF];
            ai.onload = null;
            ai.src = 'http://tsadm.webatlas.no/sh/2/v/090602/media/interface/blank.png';
            if (ai.image) {
                ai.image.onload = null;
            }
            if (ai.parentNode != null) {
                this.bf.removeChild(ai);
            }
        }
        this.am = {};
        this.am['blank'] = new Image();
        this.am['loading'] = this.am['blank'];
    }, release: function(ac, cT) {
        if (!(ac.x + ac.y) == 0) {
            this.bb.style.top = 0 + "px";
            this.bb.style.left = 0 + "px";
            this.af += ac.x;
            this.ae += ac.y;
            this.dT(ac);
            this.ak = {
                'x': 0,
                'y': 0
            };
            this.o.left -= ac.x;
            this.o.right -= ac.x;
            this.o.top -= ac.y;
            this.o.bottom -= ac.y;
            var mouseLat = NGTools.ytolatitudeatzoom(this.o.top + this.B.y, this.l);
            var mouseLon = NGTools.xtolongitudeatzoom(this.o.left + this.B.x, this.l);
            this.aq = new Coordinate(mouseLon, mouseLat, this.aO);
            this.updateBB();
            $(this.v).fire("map:moved", {
                'mouseMapCoords': this.aq,
                'mouseCoords': this.B,
                'boundingBox': this.an,
                'move': ac
            });
            if (this.cd == true) $(this.v).fire("map:dragEnd", {
                'mouseMapCoords': this.aq,
                'mouseCoords': this.B,
                'boundingBox': this.an
            });

            this.cd = false;
            if (this.wmsLayerTimerId != null)
                clearTimeout(this.wmsLayerTimerId);
            this.flickWMSLayers();
            this.wmsLayerTimerId = setTimeout(this.updateWMSLayers.bind(this), 20);
            this.es();
        }
        this.cF = false;
        this.ce.style.zIndex = '0';
    }, updateBB: function() {
        var ef = this.bW - this.C * this.bD;
        var dU = this.cg + this.H * this.bD;
        this.an = {
            'bottom': ef,
            'left': this.cg,
            'top': this.bW,
            'right': dU
        };
        var bottom = NGTools.ytolatitudeatzoom(this.o.bottom, this.l);
        var top = NGTools.ytolatitudeatzoom(this.o.top, this.l);
        var left = NGTools.xtolongitudeatzoom(this.o.left, this.l);
        var right = NGTools.xtolongitudeatzoom(this.o.right, this.l);
        var ll = new Coordinate(left, bottom, 'EPSG:4326');
        var ur = new Coordinate(right, top, 'EPSG:4326');
        this.an = {
            'bottom': ll.y,
            'left': ll.x,
            'top': ur.y,
            'right': ur.x
        };
        var m1 = this.toMercatorMeters(ll.y, ll.x);
        var m2 = this.toMercatorMeters(ur.y, ur.x);
        this.aY = {
            'bottom': m1.y,
            'left': m1.x,
            'top': m2.y,
            'right': m2.x
        };
    }, es: function() {
        if (this.dF == true) {
            var ai = document.createElement('img');
            ai.src = "http://services.webatlas.no/weblog/Log2.aspx?" + "WMS-REQUEST=BBOX=" + this.an.left + "," + this.an.bottom + "," + this.an.right + "," + this.an.top + "&MAPSTYLE=" + this.aR + "&ZOOMLEVEL=" + AJAXMAP.ZOOMLEVELS[this.l] + "&PROVIDER=" + this.bH + "&CUSTOMER=" + this.bH + "&SERVER=";
            for (var i = this.webatlasTileServerLowerBound; i <= this.webatlasTileServerUpperBound; i++) {
                ai.src += 'ts' + i + ',';
            }
            ai = null;
        }
    }, disableLogging: function() {
        this.dF = false;
    }, getOSMName: function(cH, er, av) {
        var ed = parseInt(Math.floor((er + 180) / 360 * (Math.pow(2, av))));
        var eb = parseInt(Math.floor((1 - Math.log(Math.tan(cH * Math.PI / 180) + 1 / Math.cos(cH * Math.PI / 180)) / Math.PI) / 2 * (Math.pow(2, av))));
        return ("" + av + "/" + ed + "/" + eb);
    }, addWMSLayer: function(aH, cP, cV) {
        if (aH.id == null) {
            aH.id = this.ay.length;
        }
        eP = cP ? cP : 0;
        dV = cV ? cV : 99;
        aH.lb = eP;
        aH.ub = dV;
        for (var i = 0; i < this.ay.length; i++) {
            if (aH.id == this.ay[i].id) {
                this.ay[i] = aH;
                if (this.wmsLayerTimerId != null)
                    clearTimeout(this.wmsLayerTimerId);
                this.flickWMSLayers();
                this.wmsLayerTimerId = setTimeout(this.updateWMSLayers.bind(this), 20);
                return aH.id;
            }
        }
        this.ay.push(aH);
        if (this.wmsLayerTimerId != null)
            clearTimeout(this.wmsLayerTimerId);
        this.flickWMSLayers();
        wmsLayerTimerId = setTimeout(this.updateWMSLayers.bind(this), 20);
        return aH.id;
    }, removeWMSLayer: function(eN) {
        for (var i = 0; i < this.ay.length; i++) {
            if (eN == this.ay[i].id) {
                this.ay.splice(i, 1);
                if (this.wmsLayerTimerId != null)
                    clearTimeout(this.wmsLayerTimerId);
                this.flickWMSLayers();
                this.wmsLayerTimerId = setTimeout(this.updateWMSLayers.bind(this), 20);
                return;
            }
        }
    },
    flickWMSLayers: function() {
        var tilelayer = this.bb;
        for (var i = 0; i < this.bs.length; i++) {
            tilelayer.removeChild(this.bs[i]);
        }
        this.bs = [];
    },
    updateWMSLayers: function() {
        var tilelayer = this.bb;
        for (var i = 0; i < this.bs.length; i++) {
            tilelayer.removeChild(this.bs[i]);
        }
        this.bs = [];
        for (var i = 0; i < this.ay.length; i++) {
            var req = this.ay[i];
            if (req.lb <= this.l && req.ub >= this.l) {
                var img = document.createElement('img');
                var url = req.url;
                var au = $H({
                    "REQUEST": "GetMap",
                    "SERVICE": req.service,
                    "VERSION": req.version,
                    "SRS": "EPSG:54004",
                    "FORMAT": req.format,
                    "LAYERS": req.layers,
                    "TRANSPARENT": "true",
                    "STYLES": req.styles,
                    "WIDTH": this.H,
                    "HEIGHT": this.C,
                    "BBOX": [this.aY.left, this.aY.bottom, this.aY.right, this.aY.top].join(',')
                });
                if (typeof (req.sendPixelValues) != 'undefined') if (req.sendPixelValues == true) {
                    au.set('ZOOMLEVEL', this.l);
                    au.set('PIXELLEFT', parseInt(this.o.left));
                    au.set('PIXELRIGHT', parseInt(this.o.right));
                    au.set('PIXELBOTTOM', parseInt(this.o.bottom));
                    au.set('PIXELTOP', parseInt(this.o.top));
                }
                var bg = "";
                if (url.indexOf("?") == -1) {
                    bg = "?";
                } else if (!(url.endsWith("?") || url.endsWith("&"))) {
                    bg = "&";
                }
                url = url + bg + au.toQueryString();
                img.src = url;
                img.alt = "Loading custom layer...";
                img.relativeSrc = this.ay[i].serverURL;
                img.className = 'overlay';
                img.style.position = 'absolute';
                img.style.top = 0 + 'px';
                img.style.left = 0 + 'px';
                tilelayer.appendChild(img);
                this.bs.push(img)
            }
        }
        this.cW();
    }, cW: function() {
        var tilelayer = this.bf;
        for (var i = 0; i < this.bz.length; i++) {
            tilelayer.removeChild(this.bz[i]);
        }
        this.bz = [];
        for (var i = 0; i < this.G.length; i++) {
            if (this.G[i].type == 'wmsoverlay') {
                var req = this.G[i].wmsRequest;
                var img = document.createElement('img');
                var url = req.url;
                var au = $H({
                    "REQUEST": "GetMap",
                    "SERVICE": req.service,
                    "VERSION": req.version,
                    "SRS": "EPSG:54004",
                    "FORMAT": req.format,
                    "LAYERS": req.layers,
                    "TRANSPARENT": "true",
                    "STYLES": req.styles,
                    "WIDTH": this.H,
                    "HEIGHT": this.C,
                    "BBOX": [this.aY.left, this.aY.bottom, this.aY.right, this.aY.top].join(',')
                });
                if (typeof (req.sendPixelValues) != 'undefined') if (req.sendPixelValues == true) {
                    au.set('ZOOMLEVEL', this.l);
                    au.set('PIXELLEFT', parseInt(this.o.left));
                    au.set('PIXELRIGHT', parseInt(this.o.right));
                    au.set('PIXELBOTTOM', parseInt(this.o.bottom));
                    au.set('PIXELTOP', parseInt(this.o.top));
                }
                var bg = "";
                if (url.indexOf("?") == -1) {
                    bg = "?";
                } else if (!(url.endsWith("?") || url.endsWith("&"))) {
                    bg = "&";
                }
                url = url + bg + au.toQueryString();
                img.src = url;
                img.alt = "Loading custom layer...";
                img.className = 'overlay';
                img.style.position = 'absolute';
                img.style.top = 0 + 'px';
                img.style.left = 0 + 'px';
                img.style.zIndex = this.G[i].zIndex;
                tilelayer.appendChild(img);
                this.bz.push(img)
            }
        }
    }, getDistancelatlon: function(T) {
        var db = 0.0;
        var R = 6371;
        for (var i = 0; i < T.length - 1; i++) {
            var point1 = T[i];
            var point2 = T[i + 1];
            point1 = this.UTMToLatLon(point1);
            point2 = this.UTMToLatLon(point2);
            var distance = Math.acos(Math.sin(point1.y * Math.PI / 180) * Math.sin(point2.y * Math.PI / 180) + Math.cos(point1.y * Math.PI / 180) * Math.cos(point2.y * Math.PI / 180) * Math.cos((point2.x - point1.x) * Math.PI / 180)) * R;
            db += distance;
        }
        return db;
    }, getHeight: function() {
        return this.C;
    }, getWidth: function() {
        return this.H;
    }, getZoomlevelMax: function() {
        return this.be;
    }, getZoomlevelMin: function() {
        return this.bw;
    }, setZoomlevelMax: function(av) {
        this.be = av;
    }, setZoomlevelMin: function(av) {
        this.bw = av;
    }, getDrawLayer: function() {
        return this.bb;
    }, getStaticDrawLayer: function() {
        return this.cI;
    }, getMouseLayer: function() {
        return this.aB;
    }, getMapContainer: function() {
        return this.v;
    }, getTrackCoords: function() {
        tmpcoord = this.trackCoords;
        this.trackCoords = null;
        return tmpcoord;
    }, getCenterCoordinate: function() {
        var cu = NGTools.ytolatitudeatzoom(this.o.top + this.C / 2, this.l);
        var ej = NGTools.xtolongitudeatzoom(this.o.left + this.H / 2, this.l);
        var dO = new Coordinate(ej, cu, 'EPSG:4326');
        return dO;
    }, getBoundingBox: function() {
        return this.an;
    }, setEPSG: function(epsg) {
        this.dL = epsg;
    }, getEPSG: function() {
        return this.dL;
    }, setMapStyle: function(eo) {
        this.aR = eo;
        this.cs();
        this.bh({
            'x': 0,
            'y': 0
        });
    }, disableAnnotationInfo: function() {
        this.bY = false;
    }, setAnnotationPopupBehaviour: function(dp, dA) {
        this.bF = dp;
        if (dp != WAAnnotationOpenBehaviour.Disable) {
            this.bY = true;
        }
        if (typeof dA != "undefined") this.dC = dA;
    }, enableAnnotationInfo: function() {
        this.bY = true;
    }, getMapStyle: function() {
        return this.aR;
    }, getCurrentMouseCoords: function() {
        return this.B;
    }, getMouseDownCoords: function() {
        return this.P;
    }, getMouseDownMapCoords: function() {
        return this.ct.transform('EPSG:32633');
    }, getMouseMapCoords: function() {
        return this.aq.transform('EPSG:32633'); ;
    }, setMouseZoom: function(ec) {
        this.bk = ec;
    }, allowMouseNavigation: function() {
        this.by = true;
    }, disallowMouseNavigation: function() {
        this.by = false;
    }, getZoomLevel: function() {
        return this.l;
    }, bZ: function(bP) {
        bK = bP.offsetTop;
        aE = bP.offsetParent;
        while (aE != null) {
            bK += aE.offsetTop;
            if (aE != null) {
                aE = aE.offsetParent;
            }
        }
        return bK;
    }, bU: function(bP) {
        bK = bP.offsetLeft;
        aE = bP.offsetParent;
        while (aE != null) {
            bK += aE.offsetLeft;
            aE = aE.offsetParent;
        }
        return bK;
    }, cK: function(J) {
        if (J.which == null) {
            dz = (J.button < 2) ? "LEFT" : ((J.button == 4) ? "MIDDLE" : "RIGHT");
        } else {
            dz = (J.which < 2) ? "LEFT" : ((J.which == 2) ? "MIDDLE" : "RIGHT");
        }
        return dz;
    }, bv: function(L) {
        return L.transform(this.aO);
    }, geoToScreenCoordinates: function(ac) {
        var latlon = ac.transform('EPSG:4326');
        var af = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[0];
        var ae = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[1];
        return {
            'x': af,
            'y': ae
        };
    }, geoToLocalScreenCoordinates: function(ac) {
        var latlon = ac.transform('EPSG:4326');
        var af = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[0];
        var ae = NGTools.LatLongToPixelXY(latlon.y, latlon.x, this.l)[1];
        af = af - this.o.left;
        ae = ae - this.o.top;
        return {
            'x': af,
            'y': ae
        };
    }, getPixelLatLon: function(pixel) {
        var lon = NGTools.xtolongitudeatzoom(this.o.left + pixel.x, this.l);
        var lat = NGTools.ytolatitudeatzoom(this.o.top + pixel.y, this.l);
        latLon = new Coordinate(lon, lat);
        return latLon;
    }, decimalDegreesToUTM: function(ac) {
        return ac.toUTM(ac.x, ac.y, ac.epsgToZone(this.aO));
    }, UTMToLatLon: function(cy) {
        return cy.fromUTM(cy.x, cy.y, '33');
    }, getDistance: function(points) {
        var t = 0.0;
        for (var i = 0; i < points.length - 1; i++) {
            var point1 = points[i];
            var point2 = points[i + 1];
            var distance = Math.sqrt((point2.x - point1.x) * (point2.x - point1.x) + (point1.y - point2.y) * (point1.y - point2.y));
            t += distance;
        }
        return this.cl(t, 0);
    }, getCircuit: function(points) {
        var t = 0.0;
        if (points.length > 2) {
            for (var i = 0; i < points.length - 1; i++) {
                var point1 = points[i];
                var point2 = points[i + 1];
                var distance = Math.sqrt((point2.x - point1.x) * (point2.x - point1.x) + (point1.y - point2.y) * (point1.y - point2.y));
                t += distance;
            }
        }
        if (points.length > 2) {
            var distance = Math.sqrt((points[points.length - 1].x - points[0].x) * (points[points.length - 1].x - points[0].x) + (points[0].y - points[points.length - 1].y) * (points[0].y - points[points.length - 1].y));
            t += distance;
        }
        return this.cl(t, 0);
    }, getArea: function(points) {
        var t = 0.0;
        if (points.length > 2) {
            var numPoints = points.length;
            t = (points[points.length - 1].x * points[0].y) - (points[0].x * points[points.length - 1].y);
            for (var i = 0; i < numPoints - 1; i++) {
                t = t + (points[i].x * points[i + 1].y) - (points[i + 1].x * points[i].y);
            }
            t = t / 2;
        }
        if (t < 0) {
            t = -t;
        }
        return this.cl(t, 0);
    }, fa: function(ac) {
        var eJ = parseInt(ac.x / AJAXMAP.ZOOMLEVELS[this.l]);
        var eK = parseInt(ac.y / AJAXMAP.ZOOMLEVELS[this.l]);
        var dW = AJAXMAP.ZOOMLEVELS[this.l] * eJ;
        var dZ = AJAXMAP.ZOOMLEVELS[this.l] * eK;
        return new Coordinate(dW, dZ, ac.srs);
    }, cl: function(Num, Places) {
        if (Places > 0) {
            if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
                var Rounder = Math.pow(10, Places);
                return Math.round(Num * Rounder) / Rounder;
            } else return Num;
        } else return Math.round(Num);
    }, cQ: function(J) {
        var bx = 0;
        if (!J) {
            J = window.event;
        }
        if (J.wheelDelta) {
            bx = J.wheelDelta / 120;
        } else if (J.detail) {
            bx = -J.detail / 3;
        }
        if (bx) {
            this.eO(bx);
        }
        if (J.preventDefault) {
            J.preventDefault();
        }
        J.returnValue = false;
    }, eO: function(bx) {
        if (!this.bR) {
            if (bx < 0) {
                if (this.by) this.mouseZoomOut();
            } else {
                if (this.by) this.mouseZoomIn();
            }
        }
    }
};

function Annotation(ac, cZ, dv, cX, bn, bl, ds, dj, de) {
    this.parent = null;
    this.id = ++annotationStatic.annotationCount;
    this.coordinate = ac;
    this.title = cZ ? cZ : "";
    this.description = dv ? dv : "";
    this.lowerbound = ds ? ds : 0;
    this.upperbound = dj ? dj : 99;
    this.xOffset = bn ? parseInt(bn) : 0;
    this.yOffset = bl ? parseInt(bl) : 0;
    this.group = de ? de : 0;
    this.x = 0;
    this.y = 0;
    this.img = null;
    this.iconURL = cX ? cX : 'http://www.webatlas.no/webatlasapi/v/071009/media/interface/default/markers/flag_blue.gif';
    this.element = null;
};
var annotationStatic = {
    'annotationCount': 0
};
Annotation.prototype = {
    cG: function (J) {
        if (this.parent.bF == WAAnnotationOpenBehaviour.Click) {
            this.parent.showAnnotationPopup(this);
        }
        $(this.element).fire("annotation:mouseClicked", {
            'annotation': this
        });
    }, cr: function (J) {
        $(this.element).fire("annotation:mouseUp", {
            'annotation': this,
            'mouseMapCoords': this.parent.aq,
            'mouseCoords': this.parent.B
        });
    }, cD: function (J) {
        $(this.element).fire("annotation:mouseDown", {
            'annotation': this,
            'mouseMapCoords': this.parent.aq,
            'mouseCoords': this.parent.B
        });
    }, cn: function (J) {
        $(this.element).fire("annotation:mouseOut", {
            'annotation': this
        });
        if (this.parent.dC == WAAnnotationCloseBehaviour.IconMouseOut) {
            this.parent.hideAnnotationPopup();
        }
    }, ck: function (J) {
        $(this.element).fire("annotation:mouseIn", {
            'annotation': this
        });
        if (this.parent.bF == WAAnnotationOpenBehaviour.Hover) {
            this.parent.showAnnotationPopup(this);
        }
    }
};

function Layer(ap) {
    this.type = ap.type ? ap.type : 'webatlastile';
    this.name = ap.name ? ap.name : '';
    this.zIndex = ap.zIndex ? ap.zIndex : 0;
    this.wmsRequest = ap.wmsrequest ? ap.wmsrequest : null;
    if (ap.visible != 'undefined' && ap.visible != null) this.visible = ap.visible;
    else this.visible = true;
    this.lowerBound = ap.lowerBound ? ap.lowerBound : 0;
    this.upperBound = ap.upperBound ? ap.upperBound : 99;
};
Layer.prototype = {};

function Coordinate(af, ae, aO) {
    this.x = af;
    this.y = ae;
    this.lat = ae;
    this.lon = af;
    this.srs = aO ? aO : 'EPSG:32633';
};
Coordinate.prototype = {
    toUTM: function (x, y, zone) {
        var dI = parseFloat(x);
        var cu = parseFloat(y);
        var bt = Math.PI;
        var fb = bt / 4;
        var cf = bt / 180;
        var cb = 180.0 / bt;
        var bo = 6378137;
        var I = 0.00669438;
        var bI = 0.9996;
        var bE;
        var aU;
        var co;
        var aL;
        var bm;
        var ah;
        var bA;
        var ez = (dI + 180) - parseInt((dI + 180) / 360) * 360 - 180;
        var ax = cu * cf;
        var eA = ez * cf;
        var du;
        var bN;
        bN = Math.abs(zone);
        bE = (bN - 1) * 6 - 180 + 3;
        du = bE * cf;
        aU = (I) / (1 - I);
        co = bo / Math.sqrt(1 - I * Math.sin(ax) * Math.sin(ax));
        aL = Math.tan(ax) * Math.tan(ax);
        bm = aU * Math.cos(ax) * Math.cos(ax);
        ah = Math.cos(ax) * (eA - du);
        bA = bo * ((1 - I / 4 - 3 * I * I / 64 - 5 * I * I * I / 256) * ax - (3 * I / 8 + 3 * I * I / 32 + 45 * I * I * I / 1024) * Math.sin(2 * ax) + (15 * I * I / 256 + 45 * I * I * I / 1024) * Math.sin(4 * ax) - (35 * I * I * I / 3072) * Math.sin(6 * ax));
        var eh = (bI * co * (ah + (1 - aL + bm) * ah * ah * ah / 6 + (5 - 18 * aL + aL * aL + 72 * bm - 58 * aU) * ah * ah * ah * ah * ah / 120) + 500000.0);
        var di = (bI * (bA + co * Math.tan(ax) * (ah * ah / 2 + (5 - aL + 9 * bm + 4 * bm * bm) * ah * ah * ah * ah / 24 + (61 - 58 * aL + aL * aL + 600 * bm - 330 * aU) * ah * ah * ah * ah * ah * ah / 720)));
        if (zone < 0) di += 10000000.0;
        return new Coordinate(eh, di, zone >= 0 ? "EPSG:326" + zone : "EPSG:327" + (-zone));
    }, fromUTM: function (x, y, zone) {
        var bt = Math.PI;
        var cf = bt / 180;
        var cb = 180.0 / bt;
        var bI = 0.9996;
        var bo = 6378137;
        var I = 0.00669438;
        var aU = (I) / (1 - I);
        var at = (1 - Math.sqrt(1 - I)) / (1 + Math.sqrt(1 - I));
        var cp, aS, az, dK, ag, bA;
        var bE;
        var bB, el, as;
        var bN = zone;
        var y0 = 0;
        if (bN < 0) {
            y0 = 10000000.0;
        }
        bE = (bN - 1) * 6 - 180 + 3;
        bA = (y - y0) / bI;
        bB = bA / (bo * (1 - I / 4 - 3 * I * I / 64 - 5 * I * I * I / 256));
        as = bB + (3 * at / 2 - 27 * at * at * at / 32) * Math.sin(2 * bB) + (21 * at * at / 16 - 55 * at * at * at * at / 32) * Math.sin(4 * bB) + (151 * at * at * at / 96) * Math.sin(6 * bB);
        el = as * cb;
        cp = bo / Math.sqrt(1 - I * Math.sin(as) * Math.sin(as));
        aS = Math.tan(as) * Math.tan(as);
        az = aU * Math.cos(as) * Math.cos(as);
        dK = bo * (1 - I) / Math.pow(1 - I * Math.sin(as) * Math.sin(as), 1.5);
        ag = (x - 500000.0) / (cp * bI);
        Lat = as - (cp * Math.tan(as) / dK) * (ag * ag / 2 - (5 + 3 * aS + 10 * az - 4 * az * az - 9 * aU) * ag * ag * ag * ag / 24 + (61 + 90 * aS + 298 * az + 45 * aS * aS - 252 * aU - 3 * az * az) * ag * ag * ag * ag * ag * ag / 720);
        Lat = Lat * cb;
        Long = (ag - (1 + 2 * aS + az) * ag * ag * ag / 6 + (5 - 2 * az + 28 * aS - 3 * az * az + 8 * aU + 24 * aS * aS) * ag * ag * ag * ag * ag / 120) / Math.cos(as);
        Long = bE + Long * cb;
        return new Coordinate(Long, Lat, "EPSG:4326");
    }, epsgToZone: function (epsg_code) {
        if (epsg_code.indexOf("EPSG:") == 0) {
            if (epsg_code.substr(5, 3) == "326") return parseInt(epsg_code.substr(8, 3));
            if (epsg_code.substr(5, 3) == "327") return -parseInt(epsg_code.substr(8, 3));
        }
        return 0;
    }, transform: function (to_srs) {
        if (this.srs == to_srs) return new Coordinate(this.x, this.y, this.srs);
        var from_zone = this.epsgToZone(this.srs);
        var to_zone = this.epsgToZone(to_srs);
        if (from_zone == 0 && this.srs != "EPSG:4326") throw "Unknown coordinate system: " + this.srs;
        if (to_zone == 0 && to_srs != "EPSG:4326") throw "Unknown coordinate system: " + to_srs;
        if (from_zone == 0 && to_zone != 0) return this.toUTM(this.x, this.y, to_zone);
        if (from_zone != 0 && to_zone == 0) return this.fromUTM(this.x, this.y, from_zone);
        if (from_zone != 0 && to_zone != 0) {
            var geo = this.fromUTM(this.x, this.y, from_zone);
            return geo.toUTM(geo.x, geo.y, to_zone);
        }
        throw "Unable to transform between " + this.srs + " and " + to_srs;
    }
};

function Move(af, ae) {
    this.x = af;
    this.y = ae;
};
Move.prototype = {};

function WMSRequest(ep, G, dM, cO, df, dh, cY, dw) {
    this.id = ++WMSRequestStatic.WMSRequestCount;
    this.url = ep;
    this.layers = G;
    this.format = dM ? dM : 'image/png';
    this.service = cO ? cO : 'WMS';
    this.styles = df ? df : '';
    this.version = dh ? dh : '1.1';
    this.transparent = cY ? cY : 'true';
    this.bgColor = dw ? dw : '0xFFFFFF';
    this.srs = 'EPSG:32633';
};
var WMSRequestStatic = {
    'WMSRequestCount': 0
};
WMSRequest.prototype = {
    addLayer: function (bu) {
        this.layers += ',' + bu;
    }
};

function WAPICanvas() {
    var m = document.createElement('canvas');
    m.setAttribute('width', 100);
    m.setAttribute('height', 100);
    m.style.position = "absolute";
    m.style.top = "0px";
    m.style.left = "0px";
    m.style.width = "100%";
    m.style.height = "100%";
    m.style.zIndex = 1000;
    this.element = m;
    this.surface = null;
    this.lines = [];
    this.parent = null;
    this.D = {
        'X': 0,
        'Y': 0
    };
    this.F = {
        'X': 200,
        'Y': 200
    };
    this.useex = false;
    this.m_groups = new Hash();
    this.m_defaultGroupName = "_default";
    Event.observe(document, 'map:resized', this.redraw.bindAsEventListener(this));
    Event.observe(document, 'map:moved', this.redraw.bindAsEventListener(this));
    Event.observe(document, 'map:zoomed', this.redraw.bindAsEventListener(this));
};
WAPICanvas.prototype = {
    addPolyLine: function (ei, V) {
        V = this._parseOptions(V);
        var aD = this.m_groups.get(V.group);
        if (aD == null) {
            aD = [];
            this.m_groups.set(V.group, aD);
        }
        aD.push(ei);
        if (typeof!V.supressRedraw == 'undefined' || !V.supressRedraw) this.redraw();
    }, redraw: function () {
        this.surface.clearRect(0, 0, this.element.width, this.element.height);
        this.D = {
            'X': 0,
            'Y': 0
        };
        this.F = {
            'X': this.parent.getWidth(),
            'Y': this.parent.getHeight()
        };
        var dn = this.m_groups.values();
        for (var g = 0; g < dn.length; g++) {
            var aD = dn[g];
            for (var i = 0; i < aD.length; i++) {
                this.surface.beginPath();
                this.surface.strokeStyle = aD[i].rgba;
                this.surface.lineWidth = aD[i].lineWidth;
                this.surface.lineCap = 'round';
                var bM = [];
                for (var j = 0; j < aD[i].coordinates.length; j++) {
                    var cc = this.parent.geoToLocalScreenCoordinates(aD[i].coordinates[j]);
                    bM.push(cc);
                }
                for (var j = 0; j < bM.length; j++) {
                    if (j != bM.length - 1) {
                        var cc = bM[j];
                        var cN = bM[j + 1];
                        var lineSegment = {
                            'Start': {
                                'X': parseInt(cc.x),
                                'Y': parseInt(cc.y)
                            }, 'End': {
                                'X': parseInt(cN.x),
                                'Y': parseInt(cN.y)
                            }
                        };
                        lineSegment.Dy = lineSegment.End.Y - lineSegment.Start.Y;
                        lineSegment.Dx = lineSegment.End.X - lineSegment.Start.X;
                        var intersects = true;
                        var skipPoint = false;
                        if (lineSegment.Start.X == lineSegment.End.X && lineSegment.Start.Y == lineSegment.End.Y) skipPoint = true;
                        if (skipPoint == false) {
                            if (this.surface.useex) intersects = this.clipLine(lineSegment);
                            if (intersects == true) {
                                this.surface.moveTo(lineSegment.Start.X, lineSegment.Start.Y);
                                this.surface.lineTo(lineSegment.End.X, lineSegment.End.Y);
                            }
                        }
                    }
                }
                this.surface.stroke();
            }
        }
    }, clear: function (V) {
        V = this._parseOptions(V);
        if (V.group == this.m_defaultGroupName) {
            this.m_groups = new Hash();
        } else this.m_groups.unset(V.group);
        if (!V.supressRedraw) this.redraw();
    }, _parseOptions: function (V) {
        var bJ = false;
        var bV = this.m_defaultGroupName;
        var ci = typeof V;
        if (ci != "undefined") {
            if (ci == "boolean") {
                bJ = V;
            } else if (ci == "string" && (V == "true" || V == "false")) {
                bJ = V == "true";
            } else if (ci == "string") {
                bV = V;
            } else {
                var bG = V.supressRedraw;
                bJ = typeof bG == "boolean" ? bG : bJ;
                bG = V.group;
                bV = typeof bG == "string" ? bG : bV;
            }
        }
        return {
            supressRedraw: bJ,
            group: bV
        };
    }, clipStartTop: function (line) {
        line.Start.X += line.Dx * (this.D.Y - line.Start.Y) / line.Dy;
        line.Start.Y = this.D.Y;
    }, clipStartBottom: function (line) {
        line.Start.X += line.Dx * (this.F.Y - line.Start.Y) / line.Dy;
        line.Start.Y = this.F.Y;
    }, clipStartRight: function (line) {
        line.Start.Y += line.Dy * (this.F.X - line.Start.X) / line.Dx;
        line.Start.X = this.F.X;
    }, clipStartLeft: function (line) {
        line.Start.Y += line.Dy * (this.D.X - line.Start.X) / line.Dx;
        line.Start.X = this.D.X;
    }, clipEndTop: function (line) {
        line.End.X += line.Dx * (this.D.Y - line.End.Y) / line.Dy;
        line.End.Y = this.D.Y;
    }, clipEndBottom: function (line) {
        line.End.X += line.Dx * (this.F.Y - line.End.Y) / line.Dy;
        line.End.Y = this.F.Y;
    }, clipEndRight: function (line) {
        line.End.Y += line.Dy * (this.F.X - line.End.X) / line.Dx;
        line.End.X = this.F.X;
    }, clipEndLeft: function (line) {
        line.End.Y += line.Dy * (this.D.X - line.End.X) / line.Dx;
        line.End.X = this.D.X;
    }, clipLine: function (line) {
        var lineCode = 0;
        if (line.End.Y < this.D.Y) lineCode += 8;
        else if (line.End.Y > this.F.Y) lineCode += 4;
        if (line.End.X > this.F.X) lineCode += 2;
        else if (line.End.X < this.D.X) lineCode += 1;
        if (line.Start.Y < this.D.Y) lineCode += 128;
        else if (line.Start.Y > this.F.Y) lineCode += 64;
        if (line.Start.X > this.F.X) lineCode += 32;
        else if (line.Start.X < this.D.X) lineCode += 16;
        switch (lineCode) {
        case 0:
            return true;
        case 1:
            this.clipEndLeft(line);
            return true;
        case 2:
            this.clipEndRight(line);
            return true;
        case 4:
            this.clipEndBottom(line);
            return true;
        case 5:
            this.clipEndLeft(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 6:
            this.clipEndRight(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 8:
            this.clipEndTop(line);
            return true;
        case 9:
            this.clipEndLeft(line);
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            return true;
        case 10:
            this.clipEndRight(line);
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            return true;
        case 16:
            this.clipStartLeft(line);
            return true;
        case 18:
            this.clipStartLeft(line);
            this.clipEndRight(line);
            return true;
        case 20:
            this.clipStartLeft(line);
            if (line.Start.Y > this.F.Y) return false;
            this.clipEndBottom(line);
            return true;
        case 22:
            this.clipStartLeft(line);
            if (line.Start.Y > this.F.Y) return false;
            this.clipEndBottom(line);
            if (line.End.X > this.F.X) this.clipEndRight(line);
            return true;
        case 24:
            this.clipStartLeft(line);
            if (line.Start.Y < this.D.Y) return false;
            this.clipEndTop(line);
            return true;
        case 26:
            this.clipStartLeft(line);
            if (line.Start.Y < this.D.Y) return false;
            this.clipEndTop(line);
            if (line.End.X > this.F.X) this.clipEndRight(line);
            return true;
        case 32:
            this.clipStartRight(line);
            return true;
        case 33:
            this.clipStartRight(line);
            this.clipEndLeft(line);
            return true;
        case 36:
            this.clipStartRight(line);
            if (line.Start.Y > this.F.Y) return false;
            this.clipEndBottom(line);
            return true;
        case 37:
            this.clipStartRight(line);
            if (line.Start.Y > this.F.Y) return false;
            this.clipEndBottom(line);
            if (line.End.X < this.D.X) this.clipEndLeft(line);
            return true;
        case 40:
            this.clipStartRight(line);
            if (line.Start.Y < this.D.Y) return false;
            this.clipEndTop(line);
            return true;
        case 41:
            this.clipStartRight(line);
            if (line.Start.Y < this.D.Y) return false;
            this.clipEndTop(line);
            if (line.End.X < this.D.X) this.clipEndLeft(line);
            return true;
        case 64:
            this.clipStartBottom(line);
            return true;
        case 65:
            this.clipStartBottom(line);
            if (line.Start.X < this.D.X) return false;
            this.clipEndLeft(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 66:
            this.clipStartBottom(line);
            if (line.Start.X > this.F.X) return false;
            this.clipEndRight(line);
            return true;
        case 72:
            this.clipStartBottom(line);
            this.clipEndTop(line);
            return true;
        case 73:
            this.clipStartBottom(line);
            if (line.Start.X < this.D.X) return false;
            this.clipEndLeft(line);
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            return true;
        case 74:
            this.clipStartBottom(line);
            if (line.Start.X > this.F.X) return false;
            this.clipEndRight(line);
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            return true;
        case 80:
            this.clipStartLeft(line);
            if (line.Start.Y > this.F.Y) this.clipStartBottom(line);
            return true;
        case 82:
            this.clipEndRight(line);
            if (line.End.Y > this.F.Y) return false;
            this.clipStartBottom(line);
            if (line.Start.X < this.D.X) this.clipStartLeft(line);
            return true;
        case 88:
            this.clipEndTop(line);
            if (line.End.X < this.D.X) return false;
            this.clipStartBottom(line);
            if (line.Start.X < this.D.X) this.clipStartLeft(line);
            return true;
        case 90:
            this.clipStartLeft(line);
            if (line.Start.Y < this.D.Y) return false;
            this.clipEndRight(line);
            if (line.End.Y > this.F.Y) return false;
            if (line.Start.Y > this.F.Y) this.clipStartBottom(line);
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            return true;
        case 96:
            this.clipStartRight(line);
            if (line.Start.Y > this.F.Y) this.clipStartBottom(line);
            return true;
        case 97:
            this.clipEndLeft(line);
            if (line.End.Y > this.F.Y) return false;
            this.clipStartBottom(line);
            if (line.Start.X > this.F.X) this.clipStartRight(line);
            return true;
        case 104:
            this.clipEndTop(line);
            if (line.End.X > this.F.X) return false;
            this.clipStartRight(line);
            if (line.Start.Y > this.F.Y) this.clipStartBottom(line);
            return true;
        case 105:
            this.clipEndLeft(line);
            if (line.End.Y > this.F.Y) return false;
            this.clipStartRight(line);
            if (line.Start.Y < this.D.Y) return false;
            if (line.End.Y < this.D.Y) this.clipEndTop(line);
            if (line.Start.Y > this.F.Y) this.clipStartBottom(line);
            return true;
        case 128:
            this.clipStartTop(line);
            return true;
        case 129:
            this.clipStartTop(line);
            if (line.Start.X < this.D.X) return false;
            this.clipEndLeft(line);
            return true;
        case 130:
            this.clipStartTop(line);
            if (line.Start.X > this.F.X) return false;
            this.clipEndRight(line);
            return true;
        case 132:
            this.clipStartTop(line);
            this.clipEndBottom(line);
            return true;
        case 133:
            this.clipStartTop(line);
            if (line.Start.X < this.D.X) return false;
            this.clipEndLeft(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 134:
            this.clipStartTop(line);
            if (line.Start.X > this.F.X) return false;
            this.clipEndRight(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 144:
            this.clipStartLeft(line);
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            return true;
        case 146:
            this.clipEndRight(line);
            if (line.End.Y < this.D.Y) return false;
            this.clipStartTop(line);
            if (line.Start.X < this.D.X) this.clipStartLeft(line);
            return true;
        case 148:
            this.clipEndBottom(line);
            if (line.End.X < this.D.X) return false;
            this.clipStartLeft(line);
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            return true;
        case 150:
            this.clipStartLeft(line);
            if (line.Start.Y > this.F.Y) return false;
            this.clipEndRight(line);
            if (line.End.Y < this.D.Y) return false;
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            return true;
        case 160:
            this.clipStartRight(line);
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            return true;
        case 161:
            this.clipEndLeft(line);
            if (line.End.Y < this.D.Y) return false;
            this.clipStartTop(line);
            if (line.Start.X > this.F.X) this.clipStartRight(line);
            return true;
        case 164:
            this.clipEndBottom(line);
            if (line.End.X > this.F.X) return false;
            this.clipStartRight(line);
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            return true;
        case 165:
            this.clipEndLeft(line);
            if (line.End.Y < this.D.Y) return false;
            this.clipStartRight(line);
            if (line.Start.Y > this.F.Y) return false;
            if (line.End.Y > this.F.Y) this.clipEndBottom(line);
            if (line.Start.Y < this.D.Y) this.clipStartTop(line);
            return true;
        }
        return false;
    }
};

function PolyLine(T, V) {
    this.coordinates = T ? T : [];
    if (V) {
        this.rgba = V.rgba ? V.rgba : "rgba(0,0,0,1.0)";
        this.lineWidth = V.lineWidth ? V.lineWidth : 2;
    } else {
        this.rgba = "rgba(0,0,0,1.0)";
        this.lineWidth = 2;
    }
};
PolyLine.prototype = {
    addPoint: function (ar) {
        this.coordinates.push(ar);
    }
};

function GUI(aw) {
    this.aI = "http://www.webatlas.no/webatlasapi/v/latest/media/interface/default/";
    this.aw = aw ? aw : 'small';
    this.mapControl = null;
    this.element = document.createElement('div');
    divIdName = 'guibackground';
    this.element.style.position = "absolute";
    this.element.style.left = "16px";
    this.element.setAttribute('id', divIdName);
    Event.observe(this.element, 'mouseup', this.cq.bindAsEventListener(this));
    Event.observe(this.element, 'dblclick', this.cq.bindAsEventListener(this));
    Event.observe(this.element, 'mousedown', this.cq.bindAsEventListener(this));
    var aX = document.createElement('div');
    aX.style.background = "url(" + this.aI + this.aw + "/east.jpg)";
    aX.style.position = "absolute";
    aX.style.width = "16px";
    aX.style.height = "16px";
    aX.style.left = "32px";
    aX.style.top = "34px";
    aX.setAttribute('id', 'eastButton');
    this.element.appendChild(aX);
    Event.observe(aX, 'click', this.ea.bindAsEventListener(this));
    var aJ = document.createElement('div');
    aJ.style.background = "url(" + this.aI + this.aw + "/west.jpg)";
    aJ.style.position = "absolute";
    aJ.style.width = "16px";
    aJ.style.height = "16px";
    aJ.style.left = "0px";
    aJ.style.top = "34px";
    aJ.setAttribute('id', 'westButton');
    this.element.appendChild(aJ);
    Event.observe(aJ, 'click', this.dX.bindAsEventListener(this));
    var aM = document.createElement('div');
    aM.style.background = "url(" + this.aI + this.aw + "/north.jpg)";
    aM.style.position = "absolute";
    aM.style.width = "16px";
    aM.style.height = "16px";
    aM.style.left = "16px";
    aM.style.top = "17px";
    aM.setAttribute('id', 'northButton');
    this.element.appendChild(aM);
    Event.observe(aM, 'click', this.eB.bindAsEventListener(this));
    var aN = document.createElement('div');
    aN.style.background = "url(" + this.aI + this.aw + "/south.jpg)";
    aN.style.position = "absolute";
    aN.style.width = "16px";
    aN.style.height = "16px";
    aN.style.left = "16px";
    aN.style.top = "50px";
    aN.setAttribute('id', 'southButton');
    this.element.appendChild(aN);
    Event.observe(aN, 'click', this.eR.bindAsEventListener(this));
    var aK = document.createElement('div');
    aK.style.background = "url(" + this.aI + this.aw + "/normal.jpg)";
    aK.style.position = "absolute";
    aK.style.width = "48px";
    aK.style.height = "16px";
    aK.style.left = "0px";
    aK.style.top = "104px";
    aK.setAttribute('id', 'style_normalButton');
    this.element.appendChild(aK);
    Event.observe(aK, 'click', this.eU.bindAsEventListener(this));
    var aT = document.createElement('div');
    aT.style.background = "url(" + this.aI + this.aw + "/ortho.jpg)";
    aT.style.position = "absolute";
    aT.style.width = "48px";
    aT.style.height = "16px";
    aT.style.left = "0px";
    aT.style.top = "122px";
    aT.setAttribute('id', 'style_orthoButton');
    this.element.appendChild(aT);
    Event.observe(aT, 'click', this.eH.bindAsEventListener(this));
    var aG = document.createElement('div');
    aG.style.background = "url(" + this.aI + this.aw + "/hybrid.jpg)";
    aG.style.position = "absolute";
    aG.style.width = "48px";
    aG.style.height = "16px";
    aG.style.left = "0px";
    aG.style.top = "140px";
    aG.setAttribute('id', 'style_hybridButton');
    this.element.appendChild(aG);
    Event.observe(aG, 'click', this.eT.bindAsEventListener(this));
    var aZ = document.createElement('div');
    aZ.style.background = "url(" + this.aI + this.aw + "/zoom_In.jpg)";
    aZ.style.position = "absolute";
    aZ.style.width = "16px";
    aZ.style.height = "16px";
    aZ.style.left = "16px";
    aZ.style.top = "68px";
    aZ.setAttribute('id', 'zoomInButton');
    this.element.appendChild(aZ);
    Event.observe(aZ, 'click', this.dN.bindAsEventListener(this));
    var aW = document.createElement('div');
    aW.style.background = "url(" + this.aI + this.aw + "/zoom_Out.jpg)";
    aW.style.position = "absolute";
    aW.style.width = "16px";
    aW.style.height = "16px";
    aW.style.left = "16px";
    aW.style.top = "86px";
    aW.setAttribute('id', 'zoomOutButton');
    this.element.appendChild(aW);
    Event.observe(aW, 'click', this.dP.bindAsEventListener(this));
};
GUI.prototype = {
    eR: function (al) {
        ak = new Move(0, parseInt(-this.mapControl.getHeight() / 3));
        this.mapControl.move(ak);
        al.stop();
    }, eB: function (al) {
        ak = new Move(0, parseInt(this.mapControl.getHeight() / 3));
        this.mapControl.move(ak);
        al.stop();
    }, ea: function (al) {
        ak = new Move(parseInt(-this.mapControl.getWidth() / 3), 0);
        this.mapControl.move(ak);
        al.stop();
    }, dX: function (al) {
        ak = new Move(parseInt(this.mapControl.getHeight() / 3), 0);
        this.mapControl.move(ak);
        al.stop();
    }, eU: function (al) {
        this.mapControl.setMapStyle(0);
        al.stop();
    }, eH: function (al) {
        this.mapControl.setMapStyle(1);
        al.stop();
    }, eT: function (al) {
        this.mapControl.setMapStyle(2);
        al.stop();
    }, dN: function (al) {
        this.mapControl.zoomIn();
        al.stop();
    }, dP: function (al) {
        this.mapControl.zoomOut();
        al.stop();
    }, cq: function (al) {
        al.stop();
    }
};
var NGTools = Class.create();
NGTools.prototype = {
    bT: 6378137,
    cj: null,
    cx: null,
    cw: -85.05112878,
    cA: 85.05112878,
    dy: -180,
    dD: 180,
    ad: 256,
    initialize: function () {
        this.cj = this.bT * 2.0 * Math.PI;
        this.cx = this.cj / 2;
    }, latLonToPixelXY: function (L, cC) {
        var cz = L.y;
        var cv = L.x;
        cz = this.aV(cz, this.cw, this.cA);
        cv = this.aV(cv, this.dy, this.dD);
        var af = (cv + 180) / 360;
        var cR = Math.sin(cz * Math.PI / 180);
        var ae = 0.5 - Math.log((1 + cR) / (1 - cR)) / (4 * Math.PI);
        var bc = this.bc(cC);
        var en = parseInt(this.aV(af * bc + 0.5, 0, bc - 1));
        var ek = parseInt(this.aV(ae * bc + 0.5, 0, bc - 1));
        return new NGCoordinate(en, ek);
    }, aV: function (eC, ev, eD) {
        return Math.min(Math.max(eC, ev), eD);
    }, bc: function (cC) {
        return this.ad << cC;
    }, GroundResolution: function (latitude, levelOfDetail) {
        latitude = this.aV(latitude, this.cw, this.cA);
        return Math.cos(latitude * Math.PI / 180) * 2 * Math.PI * this.bT / this.bc(levelOfDetail);
    }, MapScale: function (latitude, levelOfDetail, screenDpi) {
        return GroundResolution(latitude, levelOfDetail) * screenDpi / 0.0254;
    }, LatLongToPixelXY: function (latitude, longitude, levelOfDetail) {
        var latitude = this.aV(latitude, this.cw, this.cA);
        var longitude = this.aV(longitude, this.dy, this.dD);
        var x = (longitude + 180) / 360;
        var sinLatitude = Math.sin(latitude * Math.PI / 180);
        var y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
        var mapSize = this.bc(levelOfDetail);
        var pixelX = parseInt(this.aV(x * mapSize + 0.5, 0, mapSize - 1));
        var pixelY = parseInt(this.aV(y * mapSize + 0.5, 0, mapSize - 1));
        return [pixelX, pixelY];
    }, PixelXYToTileXY: function (pixelX, pixelY) {
        var tileX = pixelX / this.ad;
        var tileY = pixelY / this.ad;
        return [parseInt(tileX), parseInt(tileY)];
    }, PixelXYToTileXYOffset: function (pixelX, pixelY) {
        var tileX = parseInt(pixelX / this.ad);
        var tileY = parseInt(pixelY / this.ad);
        var tilePX = tileX * this.ad;
        var tilePY = tileY * this.ad;
        var remX = pixelX - tilePX;
        var remY = pixelY - tilePY;
        return [parseInt(remX), parseInt(remY)];
    }, TileXYToQuadKey: function (tileX, tileY, levelOfDetail) {
        var quadKey = "";
        for (var i = levelOfDetail; i > 0; i--) {
            var digit = '0';
            var mask = 1 << (i - 1);
            if ((tileX & mask) != 0) {
                digit++;
            }
            if ((tileY & mask) != 0) {
                digit++;
                digit++;
            }
            quadKey += digit;
        }
        return quadKey;
    }, ytolatitudeatzoom: function (y, zoom) {
        var arc = this.cj / ((1 << zoom) * this.ad);
        var metersy = this.cx - (y * arc);
        var a = Math.exp(metersy * 2 / this.bT);
        var result = this.radtodeg(Math.asin((a - 1) / (a + 1)));
        return result
    }, xtolongitudeatzoom: function (x, zoom) {
        var arc = this.cj / ((1 << zoom) * this.ad);
        var metersx = (x * arc) - this.cx;
        var result = this.radtodeg(metersx / this.bT);
        return result
    }, radtodeg: function (d) {
        return d / Math.PI * 180.0;
    }
};
var NGTools = new NGTools();