﻿/// <reference path="OpenLayers.js"/>

var infoPopup = null;

OpenLayers.Control.InfoBox = OpenLayers.Class(OpenLayers.Control, {
    HEADERTEXT_LOADING: "Henter information...",
    HEADERTEXT_LOADED: "<b>Info om:</b>",
    HEADERTEXT_INFO_ABOUT: "Info om: ",
    HEADERTEXT_BACKLINK: "Gå tilbage",
    HEADERTEXT_ROUTEPLANNING1: "Nærmeste adresse til udpegede sted er:",
    HEADERTEXT_ROUTEPLANNING2: "",

    TEXT_NO_DATA: " (ingen data)",
    TEXT_NO_DATA_LONGTEXT: "Ingen information på udpegede sted",

    defaultHandlerOptions: {
        'single': true,
        'double': false,
        'pixelTolerance': 0,
        'stopSingle': false,
        'stopDouble': false
    },

    infoContainerDiv: null,

    ignoreMapClickOnce: false,

    selectList: null,

    selectListHeader: null,

    linkContainer: null,

    layerInfoBody: null,

    layerInfoHeader: null,

    info: null,

    infoCount: 0,

    infoLoadedCount: 0,

    linkGenerators: null,

    infoBoxArea: null,

    infoBoxSettings: null,

    initialize: function(options, infoBoxArea, linkGenerators, infoBoxSettings) {
        this.infoBoxArea = infoBoxArea;
        this.linkGenerators = linkGenerators;
        this.infoBoxSettings = infoBoxSettings;
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
    },

    activate: function() {
        this.handlerOptions = OpenLayers.Util.extend(
                        {}, this.defaultHandlerOptions
                    );
        if (this.infoBoxSettings && this.infoBoxSettings.InfoBox.Advanced) {
            this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.advancedTrigger
                        }, this.handlerOptions
                    );
        }
        else {
            this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.trigger
                        }, this.handlerOptions
                    );
        }
        OpenLayers.Control.prototype.activate.apply(this, arguments);
    },

    /* Event: trigger
    * Event that's triggeret when the map is clicked
    * Creates a default infobox with info for the activelayers
    * and an address and routelink from this point.
    */
    trigger: function(e) {

        /* Close infoPopup if created */
        if (infoPopup != null)
            this.onPopupClose();

        /* Get clicked lonlat */
        var xy = e.xy;
        var lonlat = this.map.getLonLatFromViewPortPx(xy);

        // Used for info marker on print page
        var info_icon = document.getElementById("print_info_icon");
        if (info_icon) {
            info_icon.innerHTML = lonlat.lon + ":" + lonlat.lat;
        }

        /* Check for point inside clickable area*/
        var lonlatPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
        if (this.infoBoxArea && (!this.infoBoxArea.intersects(lonlatPoint)))
            return;

        var layers = this.map.layers;

        this.info = new Array(layers.length);
        this.infoCount = 0;
        this.infoLoadedCount = 0;

        this.infoContainerDiv = document.createElement("div");
        this.infoContainerDiv.className = this.displayClass + "_container";

        this.selectListHeader = document.createElement("div");
        this.selectListHeader.className = this.displayClass + "_header";
        this.selectListHeader.innerHTML = this.HEADERTEXT_LOADING;

        this.selectList = document.createElement("div");
        this.selectList.className = this.displayClass + "_list";

        this.layerInfoHeader = document.createElement("div");
        this.layerInfoHeader.className = this.displayClass + "_header";

        this.layerInfoBody = document.createElement("div");
        this.layerInfoBody.className = this.displayClass + "_detail";

        this.linkContainer = document.createElement("div");
        this.linkContainer.className = this.displayClass + "_linkContainer";

        this.infoContainerDiv.appendChild(this.linkContainer);

        this.infoContainerDiv.appendChild(this.layerInfoHeader);
        this.infoContainerDiv.appendChild(this.layerInfoBody);

        // Should be uncommitted 
        if (this.linkGenerators) {
            var services = new VisKort.Utils.Services();
            services.reverseGeocodeLonlat(lonlat, this.addRouteplanningLinks.bind(this));
        }

        this.layerInfoHeader.style.display = "none";
        this.layerInfoBody.style.display = "none";

        for (var i = 0; i < layers.length; i++) {
            if (layers[i].visibility && ((layers[i].CLASS_NAME == "OpenLayers.Layer.WMS") || (layers[i].CLASS_NAME == "OpenLayers.Layer.WMS.Untiled")) &&
                    layers[i].options.extra != null && layers[i].options.extra.infoBoxLayout != null) {
                var url = layers[i].getFullRequestString({
                    REQUEST: "GetFeatureInfo",
                    BBOX: this.map.getExtent().toBBOX(),
                    X: Math.round(xy.x),
                    Y: Math.round(xy.y),
                    QUERY_LAYERS: layers[i].params.LAYERS,
                    INFO_FORMAT: 'text/plain',
                    FEATURE_COUNT: 1,
                    WIDTH: this.map.size.w,
                    HEIGHT: this.map.size.h
                });

                var layerInfoLink = document.createElement("div");
                layerInfoLink.className = this.displayClass + "_listElement";
                layerInfoLink.innerHTML = layers[i].name;

                this.info[this.infoCount] = { layer: layers[i], infoUrl: url, infoHtml: 'Loading...', parentLink: layerInfoLink };
                this.infoCount++;
                this.selectList.appendChild(layerInfoLink);
            }
        }

        var containerHeight = 90;
        if (this.infoCount > 0) {
            this.infoContainerDiv.appendChild(this.selectListHeader);
            this.infoContainerDiv.appendChild(this.selectList);

            containerHeight += 16;
            containerHeight += Math.min(this.infoCount, 3) * 20;
        }

        this.infoContainerDiv.style.height = containerHeight + "px";

        var tempContainer = document.createElement("div");
        tempContainer.appendChild(this.infoContainerDiv);
        infoPopup = new OpenLayers.Popup.FramedCloud("Info",
                           lonlat,
                           new OpenLayers.Size(200, 200),
                           tempContainer.innerHTML,
                           null, true, this.onPopupClose.bind(this));
        infoPopup.imageSrc = OpenLayers.Util.getImagesLocation() + 'cloud-popup-relative.gif';

        this.map.addPopup(infoPopup);

        infoPopup.contentDiv.replaceChild(tempContainer, infoPopup.contentDiv.firstChild);

        if (this.infoCount > 0) {
            for (var i = 0; i < this.infoCount; i++) {
                var request = new OpenLayers.Ajax.Request(this.info[i].infoUrl,
                                    { method: 'get', parameters: { InfoIdx: i },
                                        onComplete: this.onInfoResponse.bind(this), onFailure: OpenLayers.nullHandler
                                    });
            }
        }
        else
            this.selectListHeader.innerHTML = "";
    },

    /**
    * Event: advancedTrigger 
    *
    */
    advancedTrigger: function(e) {
        /* Close infoPopup if created */
        if (infoPopup != null)
            this.onPopupClose();

        /* Get clicked lonlat */
        var xy = e.xy;
        var lonlat = this.map.getLonLatFromViewPortPx(xy);

        // Used for info marker on print page
        var info_icon = document.getElementById("print_info_icon");
        if (info_icon) {
            info_icon.innerHTML = lonlat.lon + ":" + lonlat.lat;
        }

        /* Check for point inside clickable area*/
        var lonlatPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
        if (this.infoBoxArea && (!this.infoBoxArea.intersects(lonlatPoint))) {
            return;
        }

        var layers = this.map.layers;
        this.info = new Array(layers.length);
        this.infoCount = 0;
        this.infoLoadedCount = 0;

        this.infoContainerDiv = document.createElement("div");
        this.infoContainerDiv.className = this.displayClass + "_Advancedcontainer";

        this.layerInfoHeader = document.createElement("div");
        this.layerInfoHeader.className = this.displayClass + "_Advancedheader";
        this.layerInfoHeader.innerHTML = this.HEADERTEXT_LOADING;
        this.layerInfoBody = document.createElement("div");
        this.layerInfoBody.className = this.displayClass + "_Advanceddetail";

        this.infoContainerDiv.appendChild(this.layerInfoHeader);
        this.infoContainerDiv.appendChild(this.layerInfoBody);

        // Init adresse and travelplan
        if (this.infoBoxSettings.InfoBox.Address) {
            if (this.linkGenerators) {
                var services = new VisKort.Utils.Services();
                services.reverseGeocodeLonlat(lonlat, this.addRouteplanningLinks.bind(this));
            }
        }

        // default featureCount 1 
        var featureCount = 1;
        if (this.infoBoxSettings.InfoBox.GetFeaturesCount) {
            featureCount = this.infoBoxSettings.InfoBox.GetFeaturesCount;
        }

        for (var i = 0; i < layers.length; i++) {
            if (layers[i].visibility && ((layers[i].CLASS_NAME == "OpenLayers.Layer.WMS") || (layers[i].CLASS_NAME == "OpenLayers.Layer.WMS.Untiled")) &&
                    layers[i].options.extra != null && layers[i].options.extra.infoBoxLayout != null) {
                var url = layers[i].getFullRequestString({
                    REQUEST: "GetFeatureInfo",
                    BBOX: this.map.getExtent().toBBOX(),
                    X: Math.round(xy.x),
                    Y: Math.round(xy.y),
                    QUERY_LAYERS: layers[i].params.LAYERS,
                    INFO_FORMAT: 'text/plain',
                    FEATURE_COUNT: featureCount,
                    WIDTH: this.map.size.w,
                    HEIGHT: this.map.size.h
                });

                var layerInfoLink = document.createElement("div");
                layerInfoLink.className = this.displayClass + "_AdvancedlistElement";
                layerInfoLink.innerHTML = layers[i].name;

                this.info[this.infoCount] = { layer: layers[i], infoUrl: url, infoHtml: 'Loading...', parentLink: layerInfoLink };
                this.infoCount++;

            }
        }

        var tempContainer = document.createElement("div");
        tempContainer.appendChild(this.infoContainerDiv);
        infoPopup = new OpenLayers.Popup.FramedCloud("Info",
                           lonlat,
                           new OpenLayers.Size(200, 200),
                           tempContainer.innerHTML,
                           null, true, this.onPopupClose.bind(this));
        infoPopup.imageSrc = OpenLayers.Util.getImagesLocation() + 'cloud-popup-relative.gif';
        this.adjustInfoPopupBounds(infoPopup);
        this.map.addPopup(infoPopup);

        infoPopup.contentDiv.replaceChild(tempContainer, infoPopup.contentDiv.firstChild);

        if (this.infoCount > 0) {
            for (var i = 0; i < this.infoCount; i++) {
                var request = new OpenLayers.Ajax.Request(this.info[i].infoUrl,
                                    { method: 'get', parameters: { InfoIdx: i },
                                        onComplete: this.onAdvancedInfoResponse.bind(this), onFailure: OpenLayers.nullHandler
                                    });
            }
        }
        else {
            this.onPopupClose(infoPopup);
        }
    },

    onAdvancedInfoResponse: function(response) {
        var idx = response.request.options.parameters.InfoIdx;
        var parentLink = this.info[idx].parentLink;

        var infoHtml;
        var listdata = "";
        if (response.responseText.indexOf('no features were found') != 0 && response.responseText != "" &&
            response.responseText.indexOf('Search returned no results') == -1) {
            var infoBoxLayout = this.info[idx].layer.options.extra.infoBoxLayout;
            if (infoBoxLayout["#cdata-section"] != null) {
                infoHtml = infoBoxLayout["#cdata-section"];
                var responseText = response.responseText;
                var lines = responseText.split('\n');
                var count = 0;
                for (lcv = 0; lcv < (lines.length); lcv++) {
                    var vals = lines[lcv].replace(/^\s*/, '').replace(/\s*$/, '').replace(/ = /, "=").replace(/=/, ":").replace(/'/g, '').split(':');
                    if (vals[0] != null && vals[0].length >= 1) {
                        var r = new RegExp("<!--#" + vals[0] + "#-->", 'gi');
                        var vl = vals[1];
                        if (vals.length > 2) {
                            for (var t = 2; t < vals.length; t++)
                                vl += ":" + vals[t];
                        }
                        infoHtml = infoHtml.replace(null, "");
                        infoHtml = infoHtml.replace(r, vl);

                        if (vals[0].indexOf("--------") != -1 && lcv != 1 && count == 0) {
                            listdata += infoHtml + "<br />";
                            infoHtml = infoBoxLayout["#cdata-section"];
                            count = 1;
                        } else {
                            count = 0;
                        }
                    }
                }
            }
            else {
                infoHtml = response.responseText;
            }
            OpenLayers.Event.observe(parentLink, "click",
                OpenLayers.Function.bindAsEventListener(this.onShowLayerInfo,
                                                        { infoBox: this, infoIdx: idx }));

            parentLink.className = this.displayClass + "_listElement_loaded";
        }
        else {
            // No data for this clicked location
            infoHtml = this.TEXT_NO_DATA_LONGTEXT;
            parentLink.className = this.displayClass + "_listElement_nodata";
            parentLink.innerHTML += this.TEXT_NO_DATA;
        }

        this.info[idx].infoHtml = listdata;

        // Set print info
        if (infoHtml != this.TEXT_NO_DATA_LONGTEXT) {
            var printinfo = "<br />" + infoHtml + "<br />";
            var util_instance = new VisKort.Utils();
            util_instance.AddToPrintdetail_infobox(printinfo);
        }

        this.infoLoadedCount++;

        if (this.infoLoadedCount == this.infoCount) {
            this.layerInfoHeader.innerHTML = " ";
            for (var i = 0; i < this.infoCount; i++) {

                if (this.info[i].infoHtml != "") {
                    if (this.info[i].infoHtml.toLowerCase().indexOf("ejer:") > -1) {
                        var ids = new Array();
                        var lines = this.info[i].infoHtml.split('\n');

                        for (lcv = 0; lcv < (lines.length); lcv++) {
                            if (lines[lcv].toLowerCase().indexOf("ejer:") > -1) {
                                var list = lines[lcv].split(":");
                                if (list.length > 1) {
                                    ids[ids.length] = list[1].replace(/^\s+|\s+$/g, '');
                                }
                            }
                        }
                        var services = new VisKort.Utils.Services();
                        services.getdata(ids, this.responseDataSearch.bind(this));
                    }
                    this.layerInfoBody.innerHTML += "<span style='font-size:larger;'><b>" + this.info[i].layer.name + ":</b></span><br /><br />";
                    this.layerInfoBody.innerHTML += this.info[i].infoHtml;
                }
            }

            if (this.layerInfoBody.innerHTML == "") {
                this.layerInfoBody.innerHTML = this.TEXT_NO_DATA_LONGTEXT;
            }
            this.layerInfoHeader.scrollTop = "0px";

            if (navigator.appName.toLowerCase().match("microsoft internet explorer") && navigator.appVersion.toLowerCase().match("msie 7.0")) {
                this.infoContainerDiv.style.pixelHeight = "110px";
            }
        }
    },


    onInfoResponse: function(response) {
        var idx = response.request.options.parameters.InfoIdx;
        var parentLink = this.info[idx].parentLink;
        //Search returned no results
        var infoHtml;
        if (response.responseText.indexOf('no features were found') != 0 && response.responseText != "" &&
        response.responseText.indexOf('Search returned no results') == -1) {
            var infoBoxLayout = this.info[idx].layer.options.extra.infoBoxLayout;
            if (infoBoxLayout["#cdata-section"] != null) {
                infoHtml = infoBoxLayout["#cdata-section"];
                var responseText = response.responseText;
                var lines = responseText.split('\n');
                for (lcv = 0; lcv < (lines.length); lcv++) {
                    var vals = lines[lcv].replace(/^\s*/, '').replace(/\s*$/, '').replace(/ = /, "=").replace(/=/, ":").replace(/'/g, '').split(':');
                    if (vals[0] != null && vals[0].length >= 1) {
                        var r = new RegExp("<!--#" + vals[0] + "#-->", 'gi');
                        var vl = vals[1];
                        if (vals.length > 2) {
                            for (var t = 2; t < vals.length; t++)
                                vl += ":" + vals[t];
                        }
                        infoHtml = infoHtml.replace(r, vl);
                    }
                }
            }
            else
                infoHtml = response.responseText;

            OpenLayers.Event.observe(parentLink, "click",
            OpenLayers.Function.bindAsEventListener(this.onShowLayerInfo,
            { infoBox: this, infoIdx: idx })
            );
            parentLink.className = this.displayClass + "_listElement_loaded";
        }
        else {
            infoHtml = this.TEXT_NO_DATA_LONGTEXT;
            parentLink.className = this.displayClass + "_listElement_nodata";
            parentLink.innerHTML += this.TEXT_NO_DATA;
        }

        this.info[idx].infoHtml = infoHtml;

        // Set print info
        if (infoHtml != this.TEXT_NO_DATA_LONGTEXT) {
            var printinfo = "<br />" + infoHtml + "<br />";
            var util_instance = new VisKort.Utils();
            util_instance.AddToPrintdetail_infobox(printinfo);

        }

        this.infoLoadedCount++;

        if (this.infoLoadedCount == this.infoCount) {
            this.selectListHeader.innerHTML = this.HEADERTEXT_LOADED;
            //            if (this.infoCount == 1)
            //                this.showLayerInfo(0, false);
        }
    },

    responseDataSearch: function(data) {
        if (data) {
            for (var i = 0; i < data.length; i++) {
                var val = data[i].split("#");
                var replaceStr = "Ejer:" + val[1] + "&nbsp;";
                this.layerInfoBody.innerHTML = this.layerInfoBody.innerHTML.replace(replaceStr, "<b>Ejer</b>: " + val[0] + "<br />");
            }
        }
    },

    addRouteplanningLinks: function(address) {
        var addressTextDiv = document.createElement("div");
        addressTextDiv.className = this.displayClass + "_address";
        addressTextDiv.innerHTML = this.HEADERTEXT_ROUTEPLANNING1 + "<br/><b>" + address + "</b>"; // "<br/>" + this.HEADERTEXT_ROUTEPLANNING2 + "<br/>";
        this.linkContainer.appendChild(addressTextDiv);

        var styleClass;
        for (var i = 0; i < this.linkGenerators.length; i++) {
            styleClass = this.displayClass + "_linkGeneratorsStd";
            var linkGenerator = this.linkGenerators[i].getDivElement({ address: address }, styleClass);
            this.linkContainer.appendChild(linkGenerator);
        }
    },

    addRouteplanningLinksNoText: function(address) {
        var styleClass;
        for (var i = 0; i < this.linkGenerators.length; i++) {
            styleClass = this.displayClass + "_linkGeneratorsStd";
            var linkGenerator = this.linkGenerators[i].getDivElement({ address: address }, styleClass);
            this.linkContainer.appendChild(linkGenerator);
        }
    },

    showLayerInfo: function(infoIdx, includeBackLink) {
        this.selectList.style.display = "none";
        this.selectListHeader.style.display = "none";
        this.linkContainer.style.display = "none";

        this.layerInfoHeader.innerHTML = "";
        if (includeBackLink) {
            var backToListLink = document.createElement("a");
            backToListLink.setAttribute("title", "Tilbage");
            //backToListLink.innerHTML = this.HEADERTEXT_BACKLINK;
            OpenLayers.Event.observe(backToListLink, "click",
                        OpenLayers.Function.bindAsEventListener(this.onShowList,
                                                                { infoBox: this })
                    );
            this.layerInfoHeader.appendChild(backToListLink);
        }

        var layerInfoHeadline = document.createElement("b");
        layerInfoHeadline.innerHTML = this.info[infoIdx].layer.name;
        this.layerInfoHeader.appendChild(layerInfoHeadline);

        this.layerInfoBody.innerHTML = this.info[infoIdx].infoHtml;
        this.layerInfoBody.scrollTop = "0px";

        this.layerInfoHeader.style.display = "";
        this.layerInfoBody.style.display = "";
    },

    showList: function() {
        this.layerInfoHeader.style.display = "none";
        this.layerInfoBody.style.display = "none";

        this.selectListHeader.style.display = "";
        this.selectList.style.display = "";
        this.linkContainer.style.display = "";
    },

    onShowLayerInfo: function(e) {
        this.infoBox.showLayerInfo(this.infoIdx, true);
    },

    onShowList: function(e) {
        this.infoBox.showList();
    },

    showCustomInfo: function(lonlat, infoHtml) {
        if (infoPopup != null)
            this.onPopupClose();

        var customInfoDiv = document.createElement("div");
        customInfoDiv.className = this.displayClass + "_customInfo";
        customInfoDiv.innerHTML = infoHtml;

        var tempContainer = document.createElement("div");
        tempContainer.appendChild(customInfoDiv);

        infoPopup = new OpenLayers.Popup.FramedCloud("Info",
                       lonlat,
                       new OpenLayers.Size(200, 200),
                       tempContainer.innerHTML,
                       null, true, this.onPopupClose.bind(this));
        infoPopup.imageSrc = OpenLayers.Util.getImagesLocation() + 'cloud-popup-relative.gif';

        this.map.addPopup(infoPopup);
    },

    onPopupClose: function(feature) {
        if (infoPopup) {
            this.map.removePopup(infoPopup);
            infoPopup.destroy();
            infoPopup = null;

            // Reset print detailinfo div
            var util_instance = new VisKort.Utils();
            util_instance.ResetPrintDetailInfobox();
        }
        try {
            OpenLayers.Event.stop(feature);
        }
        catch (e) {
        }
        // ensure a new popup does not appear immidiately after/on popup close
        // - not necessary in IE
        /*if (OpenLayers.Util.getBrowserName() != "msie")
        this.ignoreMapClickOnce = true;*/
    },

    showCombinedInfo: function(evtInfo) {

        /* Close infoPopup if created */
        if (infoPopup != null)
            this.onPopupClose();

        var lonlat = evtInfo.lonlat;
        var features = evtInfo.features;
        var tempContainer = document.createElement("div");
        this.linkContainer = document.createElement("div");
        this.linkContainer.className = this.displayClass + "_combinedContainer";
        tempContainer.appendChild(this.linkContainer);

        for (var i = 0; i < features.length; i++) {
            var html = "<hr /><p class='" + this.CLASS_NAME.replace(/\./g, "") + "Item" + "'><b>" + features[i].layer.extra.infoBoxTitle + "</b><br /><br />" + features[i].data.name + "<br />" + features[i].data.description + "</p>";
            var customInfoDiv = document.createElement("div");
            customInfoDiv.className = this.displayClass + "_combinedInfo";
            //if (i != features.length - 1) html += "<hr />";
            customInfoDiv.innerHTML = html;
            tempContainer.appendChild(customInfoDiv);
        }

        // Route info
        var lonlatPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
        if (this.infoBoxArea && (!this.infoBoxArea.intersects(lonlatPoint)))
            return;

        if (this.linkGenerators) {
            var services = new VisKort.Utils.Services();
            services.reverseGeocodeLonlat(lonlat, this.addRouteplanningLinks.bind(this));
        }

        infoPopup = new OpenLayers.Popup.FramedCloud("Info",
                           lonlat,
                           new OpenLayers.Size(200, 200),
                           tempContainer.innerHTML,
                           null, true, this.onPopupClose.bind(this));
        infoPopup.imageSrc = OpenLayers.Util.getImagesLocation() + 'cloud-popup-relative.gif';
        this.adjustInfoPopupBounds(infoPopup);

        this.map.addPopup(infoPopup);

        // Empty childNodes
        for (var i = 0; i < infoPopup.contentDiv.childNodes.length; i++)
            infoPopup.contentDiv.childNodes[i].innerHTML = "";

        infoPopup.contentDiv.replaceChild(tempContainer, infoPopup.contentDiv.firstChild);
    },

    adjustInfoPopupBounds: function(infoPopupControl) {
        infoPopupControl.imageSize = new OpenLayers.Size(676, 736);
        infoPopupControl.positionBlocks.tl.blocks[1].position = new OpenLayers.Pixel(-638, 0);
        infoPopupControl.positionBlocks.tl.blocks[3].position = new OpenLayers.Pixel(-638, -632);
        infoPopupControl.positionBlocks.tr.blocks[1].position = new OpenLayers.Pixel(-638, 0);
        infoPopupControl.positionBlocks.tr.blocks[3].position = new OpenLayers.Pixel(-638, -631);
        infoPopupControl.positionBlocks.bl.blocks[1].position = new OpenLayers.Pixel(-638, 0);
        infoPopupControl.positionBlocks.bl.blocks[3].position = new OpenLayers.Pixel(-638, -629);
        infoPopupControl.positionBlocks.br.blocks[1].position = new OpenLayers.Pixel(-638, 0);
        infoPopupControl.positionBlocks.br.blocks[3].position = new OpenLayers.Pixel(-638, -627);

        infoPopupControl.contentDiv.style.overflowX = 'hidden';
        infoPopupControl.contentDiv.style.overflowY = 'auto';
    },

    CLASS_NAME: "OpenLayers.Control.InfoBox"
});
