Ext.namespace('Ext.ux');


Ext.ux.BottomFlap = function(el, config, content)
{
    if (config.autoScroll == undefined)
    {
        config.autoScroll = true;
    }

    Ext.ux.BottomFlap.superclass.constructor.call(this, el, config);

    this.contentBoxMaxHeight = 500;
    this.duration = 0.30;
    this.showPinOff = false;
    this.showCloseIcon = true;
    this.closeIconTooltip = "Box schließen";
    this.useShadow = false;
    this.draggable = false;
    this.resizable = false;
    this.config = config;
    this.pinOffTooltip = "Box ausklinken";
    this.disabled=false;
    if (config.pinOffTooltip != undefined)
    {
        this.pinOffTooltip = this.config.pinOffTooltip;
    }
    if (config.closeIconTooltip != undefined)
    {
        this.closeIconTooltip = this.config.closeIconTooltip;
    }
    if (config.showCloseIcon != undefined)
    {
        this.showCloseIcon = config.showCloseIcon;
    }
    if (config.showPinOff != undefined)
    {
        this.showPinOff = config.showPinOff;
    }

    this.showFlapState();

    this.el.on('click', function(e, target)
    {
        Ext.ux.BottomFlap.prototype.setTopFlap(this);
        if (!Ext.ux.BottomFlap.prototype.useExclusiveMode)
        {
            Ext.ux.BottomFlap.prototype.reorderFlaps();
        }
    }, this);

    this.on("collapse", function()
    {
        this.showFlapState();
    })
    this.on("expand", function()
    {
        this.showFlapState();
    })
    this.on("beforeexpand", function()
    {
        if (Ext.ux.BottomFlap.prototype.useExclusiveMode)
        {
            Ext.ux.BottomFlap.prototype.closeAllFlaps();
        }
    })

    /*
    var elContent = this.getFlapContentElement();
    if (elContent != undefined)
    {
        var elPinOff = elContent.select("/[@class='pinoff']");
        if (elPinOff != undefined)
        {
            var elPinOffDom = Ext.get(elPinOff.item(0)).dom;
            if (elPinOffDom != undefined)
            {
                elPinOffDom.title = this.pinOffTooltip;
            }
            elPinOff.on("click", function(e)
            {
                this.pinOffToEast();
                this.collapse();
            }, this);
        }
    }
    */

    var flapContent = this.el.select(".flap-content");
    if (flapContent != undefined)
    {
        if (flapContent.item(0) != undefined)
        {
            var t = new Ext.Template('<div class="{cls}"></div>');
            var elToolbar = t.insertFirst(flapContent.item(0), {cls: 'toolbar'}, true);

            if (this.showPinOff)
            {
                var t = new Ext.Template('<div class="{cls}" title="{tt}"></div>');
                var elPinOff = t.append(elToolbar, {cls: 'pinoff',tt: this.pinOffTooltip}, true);
                elPinOff.on("click", function()
                {
                    this.pinOffToEast();
                    //todo: vereinheitlichen
                    this.collapse();
                }, this)
            }
            if (this.showCloseIcon)
            {
                var t = new Ext.Template('<div class="{cls}" title="{tt}"></div>');
                var elCloseIcon = t.append(elToolbar, {cls: 'closeIcon', tt: this.closeIconTooltip}, true);
                elCloseIcon.on("click", function()
                {
                    this.collapse();
                }, this)
            }
        }
    }
};


Ext.extend(Ext.ux.BottomFlap, Ext.ux.InfoPanel, {

    getFlapContentElement: function()
    {
        return Ext.get(this.el.id + "-content");
    },
    pinOffToEast: function()
    {
        var reg = this.config.pinlayout.getRegion("east");
                
        var src=Ext.get("legendInFlap").dom;
        if(src.firstChild && src.firstChild.id=="legend")
        {        
			var trg=Ext.get("legendInPanel").dom;
			Ext.DomHelper.relocateNode(src.firstChild, trg);
		}
		RegioGisMain.getLegendeFlap().disabled=true;
        
        reg.pinOff();
    },

    expand: function()
    {
        if(this.disabled)
			return; //nico
        
        // do nothing if already expanded
        if (!this.collapsed)
        {
            return this;
        }

        // fire beforeexpand event
        if (false === this.fireEvent('beforeexpand', this))
        {
            return this;
        }

        // reset collapsed flag
        this.collapsed = false;

        // hide shadow
        if (!this.docked)
        {
            this.setShadow(false);
        }

        // enable resizing
        if (this.resizer && !this.docked)
        {
            this.setResizable(true);
        }
        //this.el.setStyle("z-index", 20000);

        // animate expand
        if (this.animate)
        {
            //this.body.setStyle("z-index", 200001);
            this.body.show();

            /*  var _y = this.titleTextEl.getY() - this.body.getHeight();
            //alert(_y);
            var box = this.body.getBox()
            box.y = _y;
            this.body.setBox(box);*/

            this.updateContentBox();

            this.body.slideIn('b', {
                easing: this.easingExpand || null
                , scope: this
                , duration: this.duration
                , callback: this.updateVisuals
            });
        }
        // don't animate, just show
        else
        {
            this.updateContentBox();
            this.body.show();
            this.updateVisuals();
            this.fireEvent('animationcompleted', this);
        }

        // fire expand event
        this.fireEvent('expand', this);
        return this;

    },

    updateContentBox: function()
    {
        var _y = this.titleTextEl.getY() - this.body.getHeight();
        var box = this.body.getBox()
        box.y = _y;
        this.body.setBox(box);
    }
    ,
    calcYForHeight: function(height)
    {
        //var _y = this.titleTextEl.getY() - this.body.getHeight();
        var _y = this.titleTextEl.getY() - height;
        return _y;
    }
    ,

//el, animate, duration, onComplete, easing
    calcAutoHeight : function(el, config)
    {
        var oldHeight = el.getHeight();
        el.clip();
        el.setHeight(1);
        // force clipping
        setTimeout(function()
        {
            var height = parseInt(el.dom.scrollHeight, 10);
            // parseInt for Safari
            //alert("oldHeight=" + oldHeight);
            //alert("height=" + height);
            el.setHeight(oldHeight);
            // el.unclip();

            if (typeof config.onComplete == "function")
            {
                config.onComplete(height);
            }
        }.createDelegate(el), 0);
        return el;
    },

/**
 * config.onComplete
 * config.scope
 */
    scaleContentBoxAutomatically: function(config)
    {
        /*  if (Ext.isIE)
        {
            this.body.clip();
        }*/

        this.body.clip();

        this.calcAutoHeight(this.body,
        {
            onComplete: function(height)
            {
                if (config == null)
                {
                    config = {};
                }

                if (height > this.contentBoxMaxHeight)
                {
                    height = this.contentBoxMaxHeight;
                    this.body.setStyle("max-height", this.contentBoxMaxHeight);
                }
                config.height = height;

                if (Ext.isIE)
                {
                    config.height = config.height + this.body.getBorderWidth("t") + this.body.getBorderWidth("b");
                }
                this.scaleContentBox(config);
            }.createDelegate(this)
        });
    }
    ,

/**
 * vergrößert die Weite und Höhe der Content-Box, ohne die Position am Flap zu verändern
 * config.onComplete: function called when scaling is completed  
 */
    scaleContentBox: function(config)
    {
        if (config == null)
        {
            config = {};
        }

        if (config.easing == undefined)
        {
            config.easing = "easeOut";
        }
        if (config.width == undefined)
        {
            //config.width = this.body.getWidth();
        }
        if (config.height == undefined)
        {
            // config.height = this.body.getComputedHeight(true);
        }
        if (config.duration == undefined)
        {
            config.duration = .35;
        }

        if (config.scope == undefined)
        {
            config.scope = this;
        }

        config.callback = function()
        {
            /* if (Ext.isIE)
            {
               this.body.unclip();
            }*/
            this.body.unclip();

            if (config.onComplete != undefined)
            {
                config.onComplete();
            }
        };


        config.x = this.body.x;
        if (config.height != undefined)
        {
            config.y = this.calcYForHeight(config.height);
        }

        this.body.shift(config);
        this.body.syncFx();

    }
    ,
    updateIcon: function(_icon)
    {
        if (_icon)
        {
            this.icon = _icon;

            this.titleTextEl.set({
                style:
                        'background-image:url('
                                + this.icon
                                + ');background-repeat:no-repeat;background-position:center 0;padding:0px;'
            });
        }
    }

    ,
    collapse: function()
    {

        // do nothing if already collapsed or pinned
        if (this.collapsed || this.pinned)
        {
            return this;
        }

        // fire beforecollapse event
        if (false === this.fireEvent('beforecollapse', this))
        {
            return this;
        }

        if (this.bodyScroll /*&& !Ext.isIE*/)
        {
            this.body.setStyle('overflow', 'hidden');
        }

        // set collapsed flag
        this.collapsed = true;

        // hide shadow
        this.setShadow(false);

        // disable resizing of collapsed panel
        if (this.resizer)
        {
            this.setResizable(false);
        }

        // animate collapse
        if (this.animate)
        {
            this.body.slideOut('b', {
                easing: this.easingCollapse || null
                , scope: this
                , duration: this.duration
                , callback: this.updateVisuals
            });
        }

        // don't animate, just hide
        else
        {
            this.body.hide();
            this.updateVisuals();
            this.fireEvent('animationcompleted', this);
        }

        // fire collapse event
        this.fireEvent('collapse', this);

        return this;
    }
    ,
    showFlapState: function()
    {
        if (this.collapsed)
        {
            this.updateIcon(this.icon2 + "_closed.png");
        }
        else
        {
            this.updateIcon(this.icon2 + "_open.png");
        }
    }
    ,

    test: function()
    {
        alert("test");
    }
});


/**
 * static attribues and methods
 *
 */
Ext.ux.BottomFlap.prototype.useExclusiveMode = true;
Ext.ux.BottomFlap.prototype.initialZIndex = 120004;
Ext.ux.BottomFlap.prototype.flaps = null;

Ext.ux.BottomFlap.prototype.setTopFlap = function(flap)
{
    if (Ext.ux.BottomFlap.prototype.flaps == null)
    {
        Ext.ux.BottomFlap.prototype.flaps = new Array();
    }
    var arr = Ext.ux.BottomFlap.prototype.flaps;

    if (arr.length > 0)
    {
        if (arr[0] == flap)
        {
            return;
        }
        arr.remove(flap);
    }
    arr.unshift(flap);
    Ext.ux.BottomFlap.prototype.reorderFlaps();
}

Ext.ux.BottomFlap.prototype.reorderFlaps = function()
{
    var arr = Ext.ux.BottomFlap.prototype.flaps;
    var arrL = arr.length;

    for (var i = 0; i < arrL; i++)
    {
        var e = arr[i];
        var zi = Ext.ux.BottomFlap.prototype.initialZIndex;
        zi = zi + (arrL - 1 - i);
        e.el.setStyle("z-index", zi)
    }
}

Ext.ux.BottomFlap.prototype.closeAllFlaps = function()
{
    var arr = Ext.ux.BottomFlap.prototype.flaps;
    if (arr == null) return;
    var arrL = arr.length;

    for (var i = 0; i < arrL; i++)
    {
        var e = arr[i];
        e.collapse();
    }
}



Ext.namespace('Ext.ux');


Ext.ux.MyTabPanel = function(el, config, content)
{
    Ext.ux.MyTabPanel.superclass.constructor.call(this, el, config);

}

Ext.extend(Ext.ux.MyTabPanel, Ext.TabPanel, {

    addTab : function(id, text, content, closable)
    {
        if (id == "map-center-search") //todo: Tobi: hart rein codiert erstmal!
        {
            return this.addSearchTab(id, text, content, closable);
        }
        else
        {
            return Ext.ux.MyTabPanel.superclass.addTab.call(this, id, text, content, closable);
        }
    },

    addSearchTab : function(id, text, content, closable)
    {
        try
        {
            var item = new Ext.ux.MyTabPanelItem(this, id, text, closable, true);
            this.addTabItem(item);
            if (content)
            {
                item.setContent(content);
            }
        }
        catch(e)
        {
            alert(e);
        }
        return item;
    }
});


/** @private */
Ext.ux.MyTabPanel.prototype.createStripElements = function(stripEl, text, closable, enableSearch)
{
    if (enableSearch == undefined)
    {
        enableSearch = false;
    }
    var td = document.createElement("td");
    stripEl.appendChild(td);

    if (closable)
    {
        td.className = "x-tabs-closable";
        if (!this.closeTpl)
        {
            this.closeTpl = new Ext.Template(
                    '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
                    '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') + ' class="x-tabs-text">{text}' + (enableSearch ? '<div class="tabs-content">{text}<input class="tabs-searchfield" type="text" value="" ><input class="tabs-button" type="button" value="Suchen"></div>' : '') + '</span>' +
                    //'<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
                    '<div unselectable="on" class="close-icon">&#1mm60;</div></em></span></a>'
                    );
        }
        var el = this.closeTpl.overwrite(td, {"text": text});
        var close = el.getElementsByTagName("div")[0];
        var inner = el.getElementsByTagName("em")[0];
        return {"el": el, "close": close, "inner": inner};
    }
    else
    {
        //if(!this.tabTpl){
        if (enableSearch)
        {
            this.tabTpl = new Ext.Template(
                    '<a href="#" class="x-tabs-right"><span class="x-tabs-left" ><em ' + 'class="x-tabs-inner" >' + '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') + ' class="x-tabs-text" ><div class="tabs-content">{text}<input class="tabs-searchfield" type="text" value="" ><input class="tabs-button" type="button" value="Suchen"></div></span></em></span></a>'
                    );
        }
        else
        {
            this.tabTpl = new Ext.Template(
            //'<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em ' + (enableSearch ? 'style="padding-bottom: 0px;padding-top:0px;"' : '') + 'class="x-tabs-inner">' +
            //'<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em ' + 'class="x-tabs-inner">' + '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') + ' class="x-tabs-text"><div style="float:left;">{text}</div>' + (enableSearch ? '<div class="tabs-searchfield"><input type="text" value="" class="tab-textfield"><input type="submit"  value="OK" onclick="alert(\'Suche\');"></div> ' : '') + '</span></em></span></a>'
                    '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em ' + 'class="x-tabs-inner">' + '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') + ' class="x-tabs-text">{text}</span></em></span></a>'
                    //'<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
                    );
        }
        //}
        var el = this.tabTpl.overwrite(td, {"text": text});
        var inner = el.getElementsByTagName("em")[0];

        if (enableSearch)
        {
            var searchButton = el.getElementsByTagName("input")[1];
            var textfield = el.getElementsByTagName("input")[0];
            return {"el": el, "inner": inner,"searchbutton":searchButton, "textfield": textfield};
        }
        else
        {
            return {"el": el, "inner": inner};
        }


    }
};
Ext.namespace('Ext.ux');

Ext.ux.MyTabPanelItem = function(tabPanel, id, text, closable, enableSearch)
{
    /**
     * The TabPanel this TabPanelItem belongs to
     * @type Ext.TabPanel
     */
    this.tabPanel = tabPanel;
    /**
     * The id for this TabPanelItem
     * @type String
     */
    this.id = id;
    /** @private */
    this.disabled = false;
    /** @private */
    this.text = text;
    /** @private */
    this.loaded = false;
    this.closable = closable;
    this.enableSearch = enableSearch;

    /**
     * The body element for this TabPanelItem
     * @type Ext.Element
     */
    this.bodyEl = Ext.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
    this.bodyEl.setVisibilityMode(Ext.Element.VISIBILITY);
    this.bodyEl.setStyle("display", "block");
    this.bodyEl.setStyle("zoom", "1");
    this.hideAction();

    var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable, enableSearch);
    /** @private */
    this.el = Ext.get(els.el, true);
    this.inner = Ext.get(els.inner, true);
    if (enableSearch)
    {
        this.searchButton = Ext.get(els.searchbutton, true);
        this.textfield = Ext.get(els.textfield, true);
        if (this.textfield != null)
        {
            this.textfield.on("click", function(e)
            {
                e.stopEvent();
            }, this);
        }


        if (this.searchButton != null)
        {
            this.searchButton.on("click", function(evt)
            {
                this.fireEvent("searchButtonClick", this.textfield.dom.value);
            }, this);
        }
    }
    this.textEl = Ext.get(this.el.dom.firstChild.firstChild.firstChild, true);
    this.pnode = Ext.get(els.el.parentNode, true);

    /*if (!enableSearch) {
        this.el.on("mousedown", this.onTabMouseDown, this);
    }*/
    this.el.on("click", this.onTabClick, this);

    /** @private */
    if (closable)
    {
        var c = Ext.get(els.close, true);
        c.dom.title = this.closeText;
        c.addClassOnOver("close-over");
        c.on("click", this.closeClick, this);
    }

    this.addEvents({
    /**
     * @event activate
     * Fires when this tab becomes the active tab
     * @param {Ext.TabPanel} tabPanel
     * @param {Ext.TabPanelItem} this
     */
        "activate": true,
    /**
     * @event beforeclose
     * Fires before this tab is closed. To cancal the close, set cancel to true on e. (e.cancel = true)
     * @param {Ext.TabPanelItem} this
     * @param {Object} e Set cancel to true on this object to cancel the close.
     */
        "beforeclose": true,
    /**
     * @event close
     * Fires when this tab is closed
     * @param {Ext.TabPanelItem} this
     */
        "close": true,
    /**
     * @event deactivate
     * Fires when this tab is no longer the active tab
     * @param {Ext.TabPanel} tabPanel
     * @param {Ext.TabPanelItem} this
     */
        "deactivate" : true,

        "searchButtonClick": true
    });
    this.hidden = false;

    Ext.TabPanelItem.superclass.constructor.call(this);
}

Ext.extend(Ext.ux.MyTabPanelItem, Ext.TabPanelItem, {

});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');

Ext.ux.MySplitLayoutRegion = function(mgr, config, pos, cursor)
{
    Ext.ux.MySplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos, cursor);

    //alert(this.split.el.id);

   // this.split.el.dom.innerHMTL = "hallo";
}

Ext.extend(Ext.ux.MySplitLayoutRegion, Ext.SplitLayoutRegion, {

    

});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');


/**
 *
 * @param mgr
 */
Ext.ux.MyLayoutRegion = function(mgr, config, pos)
{
    Ext.ux.MyLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
}

Ext.extend(Ext.ux.MyLayoutRegion, Ext.CenterLayoutRegion, {

    initTabs : function()
    {
        this.bodyEl.setStyle("overflow", "hidden");
        var ts = new Ext.ux.MyTabPanel(this.bodyEl.dom, {
            tabPosition: this.bottomTabs ? 'bottom' : 'top',
            disableTooltips: this.config.disableTabTips
        });
        if (this.config.hideTabs)
        {
            ts.stripWrap.setDisplayed(false);
        }
        this.tabs = ts;
        ts.resizeTabs = this.config.resizeTabs === true;
        ts.minTabWidth = this.config.minTabWidth || 40;
        ts.maxTabWidth = this.config.maxTabWidth || 250;
        ts.preferredTabWidth = this.config.preferredTabWidth || 150;
        ts.monitorResize = false;
        ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
        ts.bodyEl.addClass('x-layout-tabs-body');
        this.panels.each(this.initPanelAsTab, this);
    }

});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');


/**
 *
 * @param mgr
 */
Ext.ux.MyCenterLayoutRegion = function(mgr, config)
{
    Ext.ux.MyCenterLayoutRegion.superclass.constructor.call(this, mgr, config, "center");
    this.visible = true;
    this.minWidth = config.minWidth || 20;
    this.minHeight = config.minHeight || 20;
}

Ext.extend(Ext.ux.MyCenterLayoutRegion, Ext.ux.MyLayoutRegion, {

});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');


/**
 *
 * @param mgr
 * @param config: outside: false
 */
Ext.ux.MyWestLayoutRegion = function(mgr, config)
{
    //this.outside = config.outside || false;
    this.expanded = false;
    this.pinnedOff = true;
    this.showPinOffBtn = true;
    this.showCollapseBtn = true;
    this.showPinOffBtnWhenPinnedOff = this.showPinOffBtn;


    /**
     * der zuletzt geöffnete Boxen-Flap
     */
    this.lastBarHandle = null;

    if (config.maxHeight == undefined)
    {
        config.maxHeight = 9999;
    }
    if (config.maxHeightPinned == undefined)
    {
        config.maxHeightPinned = 9999;
    }
    if (config.offsetY == undefined)
    {
        config.offsetY = 0;
    }
    if (config.offsetYPinned == undefined)
    {
        config.offsetYPinned = 0;
    }
    if (config.offsetYBottom == undefined)
    {
        config.offsetYBottom = 0;
    }
    if (config.offsetYBottomPinned == undefined)
    {
        config.offsetYBottomPinned = 0;
    }
    if (config.cmargins == undefined)
    {
        config.cmargins = {top: 0, left: 0, right:0, bottom: 0};
    }
    if (config.bar != undefined)
    {
        this.barEl = Ext.get(config.bar);
    }
    if (config.barHandle != undefined)
    {
        this.barHandleEl = Ext.get(config.barHandle);
    }
    if (config.barHandleOpenTooltip != undefined)
    {
        this.barHandleOpenTooltip = config.barHandleOpenTooltip;
    }
    else
    {
        this.barHandleOpenTooltip = "Box schließen";
    }
    if (config.barHandleCloseTooltip != undefined)
    {
        this.barHandleCloseTooltip = config.barHandleCloseTooltip;
    }
    else
    {
        this.barHandleCloseTooltip = "Box öffnen";
    }
    if (config.collapseBtnTooltip != undefined)
    {
        this.collapseBtnTooltip = config.collapseBtnTooltip;
    }
    else
    {
        this.collapseBtnTooltip = "Box schließen";
    }
    if (config.pinOffBtnTooltip != undefined)
    {
        this.pinOffBtnTooltip = config.pinOffBtnTooltip;
    }
    else
    {
        this.pinOffBtnTooltip = "Box ausklinken";
    }
    if (config.pinOnBtnTooltip != undefined)
    {
        this.pinOnBtnTooltip = config.pinOnBtnTooltip;
    }
    else
    {
        this.pinOnBtnTooltip = "Box einklinken";
    }
    if (config.showPinOffBtn != undefined)
    {
        this.showPinOffBtn = config.showPinOffBtn;
    }
    if (config.showPinOffBtnWhenPinnedOff != undefined)
    {
        this.showPinOffBtnWhenPinnedOff = config.showPinOffBtnWhenPinnedOff;
    }
    if (config.showCollapseBtn != undefined)
    {
        this.showCollapseBtn = config.showCollapseBtn;
    }

    this.showPin = this.showPinOffBtn;


    this.maxHeight = config.maxHeight;
    this.maxHeightPinned = config.maxHeightPinned;
    this.offsetY = config.offsetY;
    this.offsetYPinned = config.offsetYPinned;
    this.offsetYBottom = config.offsetYBottom;
    this.offsetYBottomPinned = config.offsetYBottomPinned;

    Ext.ux.MyWestLayoutRegion.superclass.constructor.call(this, mgr, config, "west", "w-resize");
    // Ext.WestLayoutRegion.superclass.constructor.call(this, mgr, config, "west", "w-resize");

    if (this.split)
    {
        this.split.placement = Ext.SplitBar.LEFT;
        this.split.orientation = Ext.SplitBar.HORIZONTAL;
        this.split.el.addClass("x-layout-split-h");
    }
    var size = config.initialSize || config.width;

    if (typeof size != "undefined")
    {
        this.el.setWidth(size);
        this.bodyEl.setWidth(size);
    }


    var co = Ext.get(this.collapsedEl);
    if (this.barEl != null)
    {
        co.dom.innerHTML = this.barEl.dom.innerHTML;
    }


    if (this.barHandleEl != null)
    {
        this.on("slideshow", function(e)
        {
            this.showOpenBarHandle();
            Ext.get(this.barHandleEl).removeClass("close");
            Ext.get(this.barHandleEl).addClass("open");
        });

        this.on("slidehide", function(e)
        {
            this.showCloseBarHandle();
        });

        Ext.get(this.barHandleEl).on("click", function(e)
        {
            if (this.expanded)
            {
                Ext.get(this.barHandleEl).removeClass("open");
                Ext.get(this.barHandleEl).addClass("close");
            }
            else
            {
                Ext.get(this.barHandleEl).removeClass("close");
                Ext.get(this.barHandleEl).addClass("open");
            }
        }, this);
    }

    this.on("expanded", function()
    {
        this.enableBoxPinnedOffState();
    }, this);

    this.on("collapsed", function()
    {
        this.enableBoxFlapOpendedState();
    }, this);

    if (this.stickBtn != undefined)
    {
        this.stickBtn.removeAllListeners();
        this.stickBtn.on("click", function (e)
        {
            e.stopPropagation();

            if (this.pinnedOff)
            {
                this.collapsed = false;
                this.collapse(true);
                this.slideOut();
            }
            else
            {
                this.expand();
            }

        }, this);
    }

    this.collapseBtn.removeAllListeners();
    this.collapseBtn.on("click", function (e)
    {
        e.stopPropagation();

        if (this.pinnedOff)
        {
            this.collapsed = false;
            this.collapse();
        }
        else
        {
            this.slideIn();
        }

    }, this);

    this.on("resized", function()
    {
        this.bodyEl.clip();
        this.bodyEl.setWidth(this.el.getWidth());
        //this.bodyEl.unclip();
    }, this);


    this.showCloseBarHandle();
}

Ext.extend(Ext.ux.MyWestLayoutRegion, Ext.WestLayoutRegion, {

    checkForSameFlap: function(flap)
    {
        return ((this.lastBarHandle == null) || (this.lastBarHandle == flap) );
    },

/*
Zustand, wenn box ausgeklinkt ist.
Buttons dann: stickBtn: icon_as_west_flap, collapseBtn: icon_close
*/
    enableBoxPinnedOffState: function()
    {
        this.stickBtn.removeClass("collapse");
        this.stickBtn.addClass("expand");
        this.pinnedOff = true;


        this.stickBtn.dom.title = this.pinOnBtnTooltip;
        this.collapseBtn.dom.title = this.collapseBtnTooltip;


        if (this.showCollapseBtn)
        {
            this.collapseBtn.show();
        }
        if (this.showPinOffBtnWhenPinnedOff)
        {
            this.stickBtn.show();
        }
    },

    enableBoxFlapOpendedState: function()
    {
        this.stickBtn.removeClass("expand");
        this.stickBtn.addClass("collapse");
        this.pinnedOff = false;

        this.stickBtn.dom.title = this.pinOffBtnTooltip;
        this.collapseBtn.dom.title = this.collapseBtnTooltip;

        if (this.showCollapseBtn)
        {
            this.collapseBtn.show();
        }
        if (this.showPinOffBtn)
        {
            this.stickBtn.show();
        }
    },

    showOpenBarHandle: function()
    {
        var el = Ext.get(this.barHandleEl);
        el.removeClass("close");
        el.addClass("open");
        el.dom.title = this.barHandleOpenTooltip;
    },

    showCloseBarHandle: function()
    {
        var el = Ext.get(this.barHandleEl);
        el.removeClass("open");
        el.addClass("close");
        el.dom.title = this.barHandleCloseTooltip;
    },

    slideIn : function(cb)
    {
        if (!this.isSlid || this.el.hasActiveFx())
        {
            Ext.callback(cb);
            return;
        }
        this.isSlid = false;

        this.beforeSlide();
        this.el.slideOut(this.getSlideAnchor(), {
            callback: function()
            {
                this.el.setLeftTop(-10000, -10000);
                this.expanded = false;
                this.afterSlide();
                this.afterSlideIn();
                Ext.callback(cb);
            },
            scope: this,
            block: true
        });

    },

    slideOut : function()
    {

        if (this.isSlid || this.el.hasActiveFx())
        {
            return;
        }
        this.isSlid = true;

        this.closeBtnState = this.closeBtn.getStyle('display');

        if (this.stickBtn)
        {
            this.stickBtn.show();
        }

        this.el.show();
        this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
        this.beforeSlide();

        this.el.setStyle("z-index", 20000);

        if (this.outside)
        {
            var targetY = this.collapsedEl.getTop() - this.el.getHeight() ;
            this.el.setY(targetY);
            this.el.setX(this.collapsedEl.getX());
        }

        this.el.slideIn(this.getSlideAnchor(), {

            callback: function()
            {
                this.expanded = true;
                this.afterSlide();
                this.el.clip();
                this.bodyEl.clip();
                this.initAutoHide();
                Ext.get(document).on("click", this.slideInIf, this);
                this.fireEvent("slideshow", this);

            },
            scope: this,
            block: true
        });


    },
    getSlideAnchor: function()
    {
        if (this.outside)
        {
            return "r";
        }
        else
        {
            return "l";
            //r
        }

    },

    expand : function(e, skipAnim)
    {
        Ext.ux.MyWestLayoutRegion.superclass.expand.call(this, e, skipAnim);
        this.expanded = true;
    },

    collapse : function(skipAnim)
    {
        Ext.ux.MyWestLayoutRegion.superclass.collapse.call(this, skipAnim);
        this.expanded = false;
    }
});

/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');


/**
 *
 * @param mgr
 * @param config: outside: false
 */
Ext.ux.MyEastLayoutRegion = function(mgr, config)
{
    //this.outside = config.outside || false;
    this.expanded = false;
    this.pinnedOff = true;
    this.showPinOffBtn = true;
    this.showCollapseBtn = true;

    /**
     * der zuletzt geöffnete Boxen-Flap
     */
    this.lastFlap = null;

    /**
     * der zuletzt geöffnete Boxen-Flap
     */
    this.lastBarHandle = null;


    if (config.maxHeight == undefined)
    {
        config.maxHeight = 9999;
    }
    if (config.maxHeightPinned == undefined)
    {
        config.maxHeightPinned = 9999;
    }
    if (config.offsetY == undefined)
    {
        config.offsetY = 0;
    }
    if (config.offsetYPinned == undefined)
    {
        config.offsetYPinned = 0;
    }
    if (config.offsetYBottom == undefined)
    {
        config.offsetYBottom = 0;
    }
    if (config.offsetYBottomPinned == undefined)
    {
        config.offsetYBottomPinned = 0;
    }
    if (config.cmargins == undefined)
    {
        config.cmargins = {top: 0, left: 0, right:0, bottom: 0};
    }
    if (config.bar != undefined)
    {
        this.barEl = Ext.get(config.bar);
    }
    if (config.barHandle != undefined)
    {
        this.barHandleEl = Ext.get(config.barHandle);
    }
    if (config.barHandleOpenTooltip != undefined)
    {
        this.barHandleOpenTooltip = config.barHandleOpenTooltip;
    }
    else
    {
        this.barHandleOpenTooltip = "Schließen";
    }
    if (config.barHandleCloseTooltip != undefined)
    {
        this.barHandleCloseTooltip = config.barHandleCloseTooltip;
    }
    else
    {
        this.barHandleCloseTooltip = "Öffnen";
    }
    if (config.collapseBtnTooltip != undefined)
    {
        this.collapseBtnTooltip = config.collapseBtnTooltip;
    }
    else
    {
        this.collapseBtnTooltip = "Box schließen";
    }
    if (config.pinOffBtnTooltip != undefined)
    {
        this.pinOffBtnTooltip = config.pinOffBtnTooltip;
    }
    else
    {
        this.pinOffBtnTooltip = "Box ausklinken";
    }
    if (config.pinOnBtnTooltip != undefined)
    {
        this.pinOnBtnTooltip = config.pinOnBtnTooltip;
    }
    else
    {
        this.pinOnBtnTooltip = "Box einklinken";
    }
    if (config.showPinOffBtn != undefined)
    {
        this.showPinOffBtn = config.showPinOffBtn;
    }
    if (config.showCollapseBtn != undefined)
    {
        this.showCollapseBtn = config.showCollapseBtn;
    }

    this.showPin = this.showPinOffBtn;

    this.maxHeight = config.maxHeight;
    this.maxHeightPinned = config.maxHeightPinned;
    this.offsetY = config.offsetY;
    this.offsetYPinned = config.offsetYPinned;
    this.offsetYBottom = config.offsetYBottom;
    this.offsetYBottomPinned = config.offsetYBottomPinned;

    Ext.ux.MyEastLayoutRegion.superclass.constructor.call(this, mgr, config, "east", "e-resize");

    if (this.split)
    {
        this.split.placement = Ext.SplitBar.RIGHT;
        this.split.orientation = Ext.SplitBar.HORIZONTAL;
        this.split.el.addClass("x-layout-split-h");
    }
    var size = config.initialSize || config.width;
    if (typeof size != "undefined")
    {
        this.el.setWidth(size);
    }

    //"closeBtn"
    this.closeBtn.dom.title = config.closeBtnTooltip;
    this.stickBtn.dom.title = config.stickBtnTooltip;
    this.collapseBtn.dom.title = config.collapseBtnTooltip;

    var co = Ext.get(this.collapsedEl);
    if (this.barEl != null)
    {
        co.dom.innerHTML = this.barEl.dom.innerHTML;
    }

    if (this.barHandleEl != null)
    {
        this.on("slideshow", function(e)
        {
            this.showOpenBarHandle();
            Ext.get(this.barHandleEl).removeClass("close");
            Ext.get(this.barHandleEl).addClass("open");
        });

        this.on("slidehide", function(e)
        {
            this.showCloseBarHandle();
        });

        Ext.get(this.barHandleEl).on("click", function(e)
        {
            if (this.expanded)
            {
                Ext.get(this.barHandleEl).removeClass("open");
                Ext.get(this.barHandleEl).addClass("close");
            }
            else
            {
                Ext.get(this.barHandleEl).removeClass("close");
                Ext.get(this.barHandleEl).addClass("open");
            }
        }, this);
    }

    this.on("expanded", function()
    {
        this.enableBoxPinnedOffState();
    }, this);


    this.on("resized", function()
    {
        this.bodyEl.clip();
        this.bodyEl.setWidth(this.el.getWidth());
        //this.bodyEl.unclip();
    }, this);

    this.showCloseBarHandle();

}

Ext.extend(Ext.ux.MyEastLayoutRegion, Ext.EastLayoutRegion, {


    checkForSameFlap: function(flap)
    {
        return ((this.lastBarHandle == null) || (this.lastBarHandle == flap) );
    },

/*
Zustand, wenn box ausgeklinkt ist.
Buttons dann: stickBtn: icon_as_west_flap, collapseBtn: icon_close
*/
    enableBoxPinnedOffState: function()
    {
        this.stickBtn.removeClass("collapse");
        this.stickBtn.addClass("expand");
        this.pinnedOff = true;

        this.stickBtn.dom.title = this.pinOnBtnTooltip;
        this.collapseBtn.dom.title = this.collapseBtnTooltip;

        if (this.showCollapseBtn)
        {
            this.collapseBtn.show();
        }
        if (this.showPinOffBtn)
        {
            this.stickBtn.show();
        }
    },

    enableBoxFlapOpendedState: function()
    {
        this.stickBtn.removeClass("expand");
        this.stickBtn.addClass("collapse");
        this.pinnedOff = false;

        this.stickBtn.dom.title = this.pinOffBtnTooltip;
        this.collapseBtn.dom.title = this.collapseBtnTooltip;

        if (this.showCollapseBtn)
        {
            this.collapseBtn.show();
        }
        if (this.showPinOffBtn)
        {
            this.stickBtn.show();
        }
    },

    showOpenBarHandle: function()
    {
        var el = Ext.get(this.barHandleEl);
        el.removeClass("close");
        el.addClass("open");
        el.dom.title = this.barHandleOpenTooltip;
    },

    showCloseBarHandle: function()
    {
        var el = Ext.get(this.barHandleEl);
        el.removeClass("open");
        el.addClass("close");
        el.dom.title = this.barHandleCloseTooltip;
    },

    slideIn : function(cb)
    {
        if (!this.isSlid || this.el.hasActiveFx())
        {
            Ext.callback(cb);
            return;
        }
        this.isSlid = false;

        this.beforeSlide();
        this.el.slideOut(this.getSlideAnchor(), {
            callback: function()
            {
                this.el.setLeftTop(-10000, -10000);
                this.expanded = false;
                this.afterSlide();
                this.afterSlideIn();
                Ext.callback(cb);
            },
            scope: this,
            block: true
        });

    },

    slideOut : function()
    {

        if (this.isSlid || this.el.hasActiveFx())
        {
            return;
        }
        this.isSlid = true;

        this.closeBtnState = this.closeBtn.getStyle('display');

        if (this.stickBtn)
        {
            this.stickBtn.show();
        }

        this.el.show();
        this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
        this.beforeSlide();

        this.el.setStyle("z-index", 20000);

        if (this.outside)
        {
            var targetY = this.collapsedEl.getTop() - this.el.getHeight() ;
            this.el.setY(targetY);
            this.el.setX(this.collapsedEl.getX());
        }

        this.el.slideIn(this.getSlideAnchor(), {

            callback: function()
            {
                this.expanded = true;
                this.afterSlide();
                this.el.clip();
                this.bodyEl.clip();
                this.initAutoHide();
                Ext.get(document).on("click", this.slideInIf, this);
                this.fireEvent("slideshow", this);

            },
            scope: this,
            block: true
        });


    },
    getSlideAnchor: function()
    {
        if (this.outside)
        {
            return "r";
        }
        else
        {
            return "l";
            //r
        }

    },

    expand : function(e, skipAnim)
    {
        Ext.ux.MyEastLayoutRegion.superclass.expand.call(this, e, skipAnim);
        this.expanded = true;
    },

    collapse : function(skipAnim)
    {
        Ext.ux.MyEastLayoutRegion.superclass.collapse.call(this, skipAnim);
        this.expanded = false;
    }


});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');


/**
 *
 * @param mgr
 * @param config: outside: false
 */
Ext.ux.LegendeLayoutRegion = function(mgr, config)
{
    Ext.ux.LegendeLayoutRegion.superclass.constructor.call(this, mgr, config, "east", "e-resize");

    if (this.collapseBtn != undefined)
    {
        this.collapseBtn.removeAllListeners();
        this.collapseBtn.on("click", function (e)
        {
            e.stopPropagation();

            if (this.pinnedOff)
            {
                this.pinOnAndHide();
            }
            else
            {
                this.isSlid = true;
                this.slideIn();
            }

        }, this);
    }

    if (this.stickBtn != undefined)
    {
        this.stickBtn.removeAllListeners();
        this.stickBtn.on("click", function (e)
        {
            //box schließen und flap-legende öffnen
            e.stopPropagation();

            if (this.pinnedOff)
            {
                this.pinOnAndHide();
                this.fireEvent("unpinned");
            }
            else
            {
                this.expand();
            }

        }, this);
    }


}


Ext.extend(Ext.ux.LegendeLayoutRegion, Ext.ux.MyEastLayoutRegion, {
    pinOff: function()
    {
        this.collapsed = true
        this.show();
        this.expand(null, true);

    },

    pinOnAndHide: function()
    {
        this.collapsed = false;
        this.collapse(true);
        this.hide();
    }
});/**
 * created by: Tobias Bley (UsabilityAgent)
 * http://www.usabilityagent.com
 */

Ext.namespace('Ext.ux');

Ext.ux.MyBorderLayout = function(container, config)
{
    config.factory = Ext.ux.MyBorderLayout.RegionFactory;
    Ext.ux.MyBorderLayout.superclass.constructor.call(this, container, config);
};

Ext.extend(Ext.ux.MyBorderLayout, Ext.BorderLayout, {


/**
 * Performs a layout update.
 */
/**
 * Performs a layout update.
 */
    layout : function()
    {
        if (this.updating) return;
        var size = this.getViewSize();
        var w = size.width, h = size.height;
        var centerW = w, centerH = h, centerY = 0, centerX = 0;
        //var x = 0, y = 0;

        var rs = this.regions;
        var n = rs["north"], s = rs["south"], west = rs["west"], e = rs["east"], c = rs["center"];
        //if(this.hideOnLayout){ // not supported anymore
        //c.el.setStyle("display", "none");
        //}
        if (n && n.isVisible())
        {
            var b = n.getBox();
            var m = n.getMargins();
            b.width = w - (m.left + m.right);
            b.x = m.left;
            b.y = m.top;
            centerY = b.height + b.y + m.bottom;
            centerH -= centerY;
            n.updateBox(this.safeBox(b));
        }
        if (s && s.isVisible())
        {
            var b = s.getBox();
            var m = s.getMargins();
            b.width = w - (m.left + m.right);
            b.x = m.left;
            var totalHeight = (b.height + m.top + m.bottom);
            b.y = h - totalHeight + m.top;
            centerH -= totalHeight;
            s.updateBox(this.safeBox(b));
        }
        if (west && west.isVisible())
        {
            var b = west.getBox();
            var m = west.getMargins();

            b.x = m.left;
            b.y = centerY + m.top;

            if (west.collapsed)
            {
                b.y += west.offsetY;
                b.height = centerH - (m.top + m.bottom) - (west.offsetY) - (west.offsetYBottom);

                // alert(west.offsetYBottom);
                if (b.height > west.maxHeight)
                {
                    b.height = west.maxHeight;
                }
            }
            else
            {
                b.y += west.offsetYPinned;
                b.height = centerH - (m.top + m.bottom) - west.offsetYPinned - west.offsetYBottomPinned;
                if (b.height > west.maxHeightPinned)
                {
                    b.height = west.maxHeightPinned;
                }

            }

            var totalWidth = (b.width + m.left + m.right);
            //alert(totalWidth);

            centerX += totalWidth;
            centerW -= totalWidth;
            west.updateBox(this.safeBox(b));
        }
        if (e && e.isVisible())
        {
            var b = e.getBox();
            var m = e.getMargins();
            var totalWidth = (b.width + m.left + m.right);
            b.x = w - totalWidth + m.left;
            b.y = centerY + m.top;

            if (e.collapsed)
            {
                b.y += e.offsetY;
                b.height = centerH - (m.top + m.bottom) - west.offsetY - west.offsetYBottom;
                if (b.height > e.maxHeight)
                {
                    b.height = e.maxHeight;
                }
            }
            else
            {
                b.y += e.offsetYPinned;
                b.height = centerH - (m.top + m.bottom) - west.offsetYPinned - west.offsetYBottomPinned;
                if (b.height > e.maxHeightPinned)
                {
                    b.height = e.maxHeightPinned;
                }
            }


            centerW -= totalWidth;
            e.updateBox(this.safeBox(b));
        }
        if (c)
        {
            var m = c.getMargins();
            var centerBox = {
                x: centerX + m.left,
                y: centerY + m.top,
                width: centerW - (m.left + m.right),
                height: centerH - (m.top + m.bottom)
            };
            //if(this.hideOnLayout){
            //c.el.setStyle("display", "block");
            //}
            c.updateBox(this.safeBox(centerBox));
        }


        this.el.repaint();
        this.fireEvent("layout", this);
    },

    safeBox : function(box)
    {
        //alert("safebox = " + box.height);
        box.width = Math.max(0, box.width);
        box.height = Math.max(0, box.height);

        //alert(this.target);
        //box.height = 300;
        return box;
    }


});

/*Ext.ux.MyBorderLayout.create = function(config, targetEl)
{
    var layout = new Ext.ux.MyBorderLayout(targetEl || document.body, config);
    layout.beginUpdate();
    var regions = Ext.ux.MyBorderLayout.RegionFactory.validRegions;
    for (var j = 0, jlen = regions.length; j < jlen; j++)
    {
        var lr = regions[j];
        if (layout.regions[lr] && config[lr].panels)
        {
            var r = layout.regions[lr];
            var ps = config[lr].panels;
            layout.addTypedPanels(r, ps);
        }
    }
    layout.endUpdate();
    return layout;
};*/

Ext.ux.MyBorderLayout.RegionFactory = {
    validRegions : ["north","south","east","west","center"],

    create : function(target, mgr, config)
    {
        target = target.toLowerCase();

        if (config.lightweight || config.basic)
        {
            return new Ext.BasicLayoutRegion(mgr, config, target);
        }
        switch (target)
                {
            case "north":
                return new Ext.NorthLayoutRegion(mgr, config);
            case "south":
                return new Ext.SouthLayoutRegion(mgr, config);
            case "east":
            //return new Ext.ux.MyEastLayoutRegion(mgr, config);
                return new Ext.ux.LegendeLayoutRegion(mgr, config);
            case "west":
                return new Ext.ux.MyWestLayoutRegion(mgr, config);
            case "center":
                return new Ext.ux.MyCenterLayoutRegion(mgr, config);
        }
        throw 'Layout region "' + target + '" not supported.';
    }

};

ï»¿Ext.BLANK_IMAGE_URL = 'images/pixel_blank.gif';

var searchFlap=null;

function test()
{
	/*
	var args={
				x:50,
				y:50,
				content:Ext.get("testDlg").dom.innerHTML,
				isFullBubble:true
			 };
	
	glbMap.showInfoDiv(args);
	*/
}


RegioGisMain = new function()
{
    var flap_addresssearch,flap_config,flap_functions,flap_legende = null;
    var tabs = null;
    var unmask;
    var mainCenterLayout = null;
    var cpCenterMap = null;
    var dummyHeight=30;
    var _impressumDialog=null;
    var _layoutReady=false;
	
    return {
        init : function()
        {
            initLoadingMask();


            // initialize state manager, we will use cookies
            Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

            // initialize QuickTips
            Ext.QuickTips.init();
            Ext.apply(Ext.QuickTips, {interceptTitles: false});

            initMainLayout();

            initMap();
            initTabs();

            // remove the loading mask
            unmask.defer(300);
        },
        
        openLegendeFlap: function()
        {
            //flap_legende.expand();
        },
        
        getLegendeFlap: function()
        {
			return flap_legende;
        },

        closeLegendeFlap: function()
        {
            //flap_legende.collapse();
        },

        setMapTabTitle: function(title)
        {
            var succ = false;
            var tabs = mainCenterLayout.getRegion("center").getTabs()
            if (tabs != undefined)
            {
                var tabMap = tabs.getTab("map-center-map");
                if (tabMap != undefined)
                {
                    tabMap.setText(Ext.util.Format.ellipsis(title, 100));
                    tabMap.setTooltip("In " + title + " navigieren");
                    succ = true;
                }
            }

            return succ;
        },

    
        getMapLayout : function()
        {
			return mainCenterLayout;
        },
        
        isLayoutReady : function()
        {
			return _layoutReady;
        },
        
        disableMapWestPanelAutoHide : function()
        {
			var west=mainCenterLayout.getRegion("west");
			if(!west.collapsed)
				return;
			if(!west.isSlid) // ist schon eingefahren - nix mehr zu retten ;-)
				return;
			
			west.clearAutoHide();
			west.clearMonitor();
			west.autoHideDisabled=true;
        },
        
        enableMapWestPanelAutoHide : function()
        {
			var west=mainCenterLayout.getRegion("west");
			if(!west.collapsed)
				return;
			if(!west.autoHideDisabled)
				return;
			if(!west.isSlid) // wurde in der Zwischenzeit absichtlich geschlossen
				west.autoHideDisabled=false;
			
			west.initAutoHide();
			Ext.get(document).on("click", west.slideInIf, west);
			west.autoHideDisabled=false;
        },
        
        focusMap : function()
        {
			var center=mainCenterLayout.getRegion("center");
			center.getTabs().getTab("map-center-map").activate();
        },
        
        showImpressum : function()
        {
			if(!_impressumDialog) // lazy initialize the dialog and only create it once
			{ 
				//var dlgElem=Ext.DomHelper.append(document.body, {tag:'div', id:'rgImpressum'});
				_impressumDialog = new Ext.BasicDialog("impressumDialog",
					{ 
						resizeHandles:'se',
						modal:true,
						collapsible:false,
						animateTarget:"impressumButton",
						width:400,
						height:400,
						shadow:"drop",
						minWidth:360,
						minHeight:260,
						proxyDrag: true
					});
				_impressumDialog.addKeyListener(27, _impressumDialog.hide, _impressumDialog);
				_impressumDialog.addButton('SchlieÃŸen', _impressumDialog.hide, _impressumDialog);
			}
			_impressumDialog.show();
		},
		
		adjustLegendFlapHeight : function()
		{
			if(flap_legende && !flap_legende.collapsed)
				flap_legende.scaleContentBoxAutomatically();
		}
    };
	
    function initMainLayout()
    {
        var layout = new Ext.ux.MyBorderLayout("maincontainer", {

            north: {
                outside: true,
                split:false,
                titlebar: false,
                collapsible:false,
                initialSize: 57,
                maxSize: 57,
                minSize: 57
            },
            west: {
                split:true,
                initialSize: 231,
                minSize: 175,
                maxSize: 600,
                collapsible: true,
                collapsed:false,
                animate: true,
                title: "Willkommen!",
                titlebar: true,
                pinOffBtnTooltip: "Kartenauswahl neben der Karte anzeigen",
                pinOnBtnTooltip: "Kartenauswahl Ã¼ber der Karte anzeigen",
                showPinOffBtn: true,
                showPinOffBtnWhenPinnedOff: false,
                showCollapseBtn: true,
                collapseBtnTooltip: "Kartenauswahl einklappen",
                autoScroll: true,
                closable: false,
                offsetY: 0,
                offsetYPinned: 0,
                bar: "main-west-bar",
                cmargins : {top: 0, left: 0, right:18, bottom: 0},
                margins : {top: 0, left: 0, right:0, bottom: 0},
                barHandle: "main-west-bar-handle"

            },
        /* east: {
            split:true,
            initialSize: 20,
            titlebar: true,
            collapsible: false,
            animate: true,
            title: 'Formulare',
            showPin:false,
            closable: false,
            offsetY: 0,
            offsetYPinned: 0,
            bar: "main-east-bar",
            cmargins : {top: 0, left: 45, right:0, bottom: 0} ,
           barHandle: "main-east-bar-handle"
        },*/
        /*  south: {
            split:true,
            initialSize: 100,
            minSize: 100,
            maxSize: 200,
            titlebar: true,
            collapsible: true,
            animate: true,
            title: "Legende"
        },*/
            center: {
                titlebar: false,
                autoScroll:false,
                closeOnTab: false,
                cmargins : {top: 0, left: 0, right:50, bottom: 0}

            }
        });

        layout.beginUpdate();


        var cpNorth = new Ext.ContentPanel('main-header', {title: 'North', closable: false, resizable: true, fitToFrame:true});
        layout.add('north', cpNorth);

        var cpWest = new Ext.ContentPanel('main-west', {title: 'West', closable: false, resizable: true, fitToFrame:true});
        layout.add('west', cpWest);

        /* var cpEast = new Ext.ContentPanel('main-east', {title: 'East', closable: false, resizable: true, animate: true, fitToFrame:true});
       layout.add('east', cpEast);*/

        initMapBoxLayout();
        layout.add('center', new Ext.NestedLayoutPanel(mainCenterLayout));


        //layout.getRegion('east').collapse();
		layout.getRegion('west').collapse();
        //layout.getRegion('north').hide();
        //layout.getRegion('south').hide();

        layout.endUpdate();
        
        _layoutReady=true;
    }


    function initMapBoxLayout()
    {
        mainCenterLayout = new Ext.ux.MyBorderLayout("main-center", {

            west: {
                split:true,
                initialSize: 260,
                width:240,
                minSize: 175,
                maxSize: 400,
                collapsible: true,
                animate: true,
                title: "Karteninhalt",
                titlebar: true,
                pinOffBtnTooltip: "Karteninhalt links neben der Karte anzeigen",
                pinOnBtnTooltip: "Karteninhalt als Box innerhalb der Karte anzeigen",
                collapseBtnTooltip: "Karteninhalt schlieÃŸen",
                barHandleOpenTooltip: "Karteninhalt schlieÃŸen",
                barHandleCloseTooltip: "Karteninhalt Ã¶ffnen",
                autoScroll: true,
                showPin:true,
                useSplitTips:true,
                closable: false,
                offsetY: 50,
                offsetYBottom:47,
                offsetYPinned: 15,
                offsetYBottomPinned: 32,
                bar: "map-west-bar",
                barHandle: "map-west-bar-handle",
                cmargins : {top: 0, left: 0, right:0, bottom: 0},
                margins : {top: 0, left: 0, right:0, bottom: 0}

            },
            east: {
                split:true,
                initialSize: 202,
                minSize: 100,
                maxSize: 400,
                titlebar: true,
                collapseBtnTooltip: "Legende am unteren Kartenrand anzeigen",
                collapsible: true,
                pinOffBtnTooltip: "Legende rechts neben der Karte anzeigen",
                pinOnBtnTooltip: "Legende als Box am unteren Kartenrand anzeigen",
                animate: true,
                title: 'Legende',
                showPin:true,
                autoScroll: true,
                closable: false,
                offsetY: 50,
                offsetYBottom:47,
                offsetYPinned: 15,
                offsetYBottomPinned: 33,
                bar: "map-east-bar",
                barHandle: "map-east-bar-handle",
                cmargins : {top: 0, left: 0, right:0, bottom: 0},
                margins : {top: 0, left: 0, right:0, bottom: 0}
            },
            center: {
                titlebar: false,
                autoScroll:false,
                closeOnTab: false,
                tabPosition:"top",
                alwaysShowTabs:true
            } ,
            south: {
                split:true,
                minSize: 10
            }
        });

        mainCenterLayout.beginUpdate();

        var cpWest = new Ext.ContentPanel('map-west', {title: 'West', closable: false, resizable: true, fitToFrame:true});
        mainCenterLayout.add('west', cpWest);
        //mainCenterLayout.getRegion("west").bodyEl.setStyle("overflow", "auto");

        var cpEast = new Ext.ContentPanel('map-east', {title: 'East', closable: false, resizable: true, fitToFrame:true, animate: true});
        mainCenterLayout.add('east', cpEast);

        /*   var cpSouth = new Ext.ContentPanel('map-legende', {title: 'Legende', closable: false});
       mainCenterLayout.add('south', cpSouth);*/


        cpCenterMap = new Ext.ContentPanel('map-center-map', {title: 'Karte', closable: false, toolbar: false, fitToFrame:true});

        cpCenterMap.on("resize", function(contentPanel, width, height)
        {
            //alert(contentPanel);
            //alert("resize event. width = " + width);

            // if (true) return;


            // alert("resize to " + this.getEl().getWidth() + "/" + this.getEl().getHeight());
      
      
            var border = 2;

            var aH = height - Ext.get("map-flaps-bottom").getHeight();
            var aW = width;

            //var elSearch = Ext.get("map-center-search");
            var elMapMap = Ext.get("map-map");
            
/*      
			var elMapMapBorder = Ext.get("map-map-border");
            var elMapMapMap = Ext.get("map-map-map");
            

	   
            elMapMap.setHeight(aH);
            elMapMap.setWidth(aW);
*/
/*
            elMapMapBorder.setHeight(aH);
            //elMapMapBorder.setWidth(aW);

            elMapMapMap.setHeight(aH - (border * 2));
            elMapMapMap.setWidth(aW - border * 2);
*/
          //  alert(contentPanel.getEl().isBorderBox());
            
            
            var mapContainer=Ext.get("mapContainer");
            mapContainer.setWidth(aW);
            mapContainer.setHeight(aH);
            glbEventObject.fireEvent("mapPanelResize", {width:aW-2*border, height:aH-2*border})
            
            //elSearch.setHeight(height);
            //elSearch.setWidth(aW-50);
			
			// nur das veranlasst FireFox die bereits verrutschten Flaps tatsÃ¤chlich auch an der
			// neuen Position zu zeichnen
			dummyHeight=dummyHeight<31 ? 31 : 30;
			Ext.get("map-flaps-bottom").setHeight(dummyHeight);
			
            //this.getEl().setWidth(aW);

            //alert(Ext.DomQuery.select("div[@class='tab-content']"));
        })

        mainCenterLayout.add('center', cpCenterMap);

        //var cpCenterSearch = new Ext.ContentPanel('map-center-search', {title: 'Suche', closable: false, toolbar: false, fitToFrame:true});
        //mainCenterLayout.add('center', cpCenterSearch);
        


        mainCenterLayout.getRegion('center').showPanel('map-center-map');
        //layout.getRegion('west').showPanel('west');

        var regionEast = mainCenterLayout.getRegion('east');
        
        regionEast.on("unpinned", function(e)
        {
            RegioGisMain.getLegendeFlap().disabled=false;
            var src=Ext.get("legendInPanel").dom;
			if(src.firstChild && src.firstChild.id=="legend")
			{        
				var trg=Ext.get("legendInFlap").dom;
				Ext.DomHelper.relocateNode(src.firstChild, trg);
			}
			RegioGisMain.openLegendeFlap();
        });

        regionEast.hide=regionEast.hide.createSequence(function()
        {
			if(!RegioGisMain.getLegendeFlap())
				return;
			RegioGisMain.getLegendeFlap().disabled=false;
			var src=Ext.get("legendInPanel").dom;
			if(src.firstChild && src.firstChild.id=="legend")
			{        
				var trg=Ext.get("legendInFlap").dom;
				Ext.DomHelper.relocateNode(src.firstChild, trg);
			}
        });
        
        regionEast.hide();


        var regionWest = mainCenterLayout.getRegion('west');
        //regionWest.collapse();

        mainCenterLayout.getRegion('south').hide();


        mainCenterLayout.endUpdate();


    }


    function initMap()
    {
        initFlaps();
       // initMapOverview();
    }

    function initMapOverview()
    {
        var mapOverview = new Ext.ux.MapOverview(cpCenterMap, "map-map-border");

    }

    function initTabs()
    {
        var tabPanel = mainCenterLayout.getRegion('center').tabs;

        var mapTab = tabPanel.getTab("map-center-map");
        mapTab.setTooltip('In Karte navigieren');

     /* var searchTab = tabPanel.getTab("map-center-search");
        searchTab.on("searchButtonClick", function(searchString)
        {
            startSearch(searchString);
        }, this);
        searchTab.on("activate", function()
        {
            showBoxLayoutForSearchTab();

        }, this);
        searchTab.on("deactivate", function()
        {
            showBoxLayoutForMapTab();
        }, this);

        searchTab.setTooltip('Kartensuche verwenden');
	*/
        //tabs.activate('map-center-map');
    }

    function initTabsOld()
    {
        tabs = new Ext.ux.MyTabPanel('map-center');
        var mapTab = tabs.addTab('map-center-map', "Karte");
        mapTab.setTooltip('In Karte navigieren');

        var searchTab = tabs.addSearchTab('map-center-search', "Suche");
        //, "Hier die Suche", false);
        searchTab.on("searchButtonClick", function(searchString)
        {
            startSearch(searchString);
        }, this);

        searchTab.on("activate", function()
        {
            showBoxLayoutForSearchTab();

        }, this);

        searchTab.on("deactivate", function()
        {
            showBoxLayoutForMapTab();
        }, this);


        //tabs.getTab('tabSearch').setTooltip('Kartensuche verwenden');
        searchTab.setTooltip('Kartensuche verwenden');

        tabs.activate('map-center-map');
    }


    function showBoxLayoutForSearchTab()
    {
        mainCenterLayout.getRegion("west").hide();
        mainCenterLayout.getRegion("east").hide();
    }

    function showBoxLayoutForMapTab()
    {
        var regionWest = mainCenterLayout.getRegion("west");
        regionWest.show();

        var regionEast = mainCenterLayout.getRegion("east");
        if (regionEast.expanded)
        {
            regionEast.show();
        }
    }

    function startSearch(searchString)
    {
        if(searchString.length<1)
			return alert("Bitte geben Sie bitte einen Suchbegriff ein.");
        searchString="%"+searchString+"%";
        Ext.get("RegioGisSearchFrame").dom.src="search.aspx?query="+escape(searchString);
    }

    function initFlaps()
    {
    
//        flap_legende = new Ext.ux.BottomFlap('flap-legend', {icon2: 'layoutImages/flap_legend',  showPinOff: true, pinlayout: mainCenterLayout, pinOffTooltip:'Legende rechts neben der Karte anzeigen'});
		searchFlap = flap_addresssearch = new Ext.ux.BottomFlap('flap-addresssearch', {icon2: 'layoutImages/flap_addresssearch'});
//        flap_functions = new Ext.ux.BottomFlap('flap-functions', {icon2: 'layoutImages/flap_functions'});
//        flap_config = new Ext.ux.BottomFlap('flap-config', {icon2: 'layoutImages/flap_config'});
    }

    function initLoadingMask()
    {
        unmask = function()
        {
            var mask = Ext.get('loading-mask');
            var msg = Ext.get('loading-msg');
            
	        if (mask && msg)
            {
                mask.fadeOut({
                    //xy:msg.getXY()
                    //, width:msg.getWidth()
                    //, height:msg.getHeight()
                     remove: true
                    , duration: 0.5
                    //, opacity: 0.7
                    //, easing: 'easeOut'
                    , callback: function()
                {
                    msg.fadeOut({duration:.2,remove:true});
                    
                    //Ext.fly(msg).remove();
                }
                });
            }
        };
    }

}();


function delayedInitMap()
{
	//glbEventObject.attachEvent("mapPanelResize", glbMap.resizeMap, null, glbMap);
}


function registerUserLayer(iwanName, title, switchedOn)
{
	themeTree_Main.registerUserLayer(iwanName, title, switchedOn);
}
/*
Ext.EventManager.onDocumentReady(delayedInitMap);
Ext.EventManager.onDocumentReady(RegioGisMain.init, RegioGisMain, true);
*/
function onBodyLoaded()
{
	delayedInitMap();
	RegioGisMain.init();
/*	
	var handle=glbEventObject.attachEvent("onMapImageLoaded", 
											function()
											{
												glbEventObject.releaseEvent(handle);
												glbMap.showMapTipWithDot=false;
												
												var content="<div style='padding:12px; font-size:11px;'>"+Ext.get("MapHelp").dom.innerHTML+"</div>";
												
												var args={x:(glbMap.mapSize.width-50), y:(glbMap.mapSize.height-50), isFullBubble:true}
												var tempDiv=document.createElement("div");
												var w=200;
												var h=300;
												_mapTipTemplate.append(tempDiv, {title:"Karte nutzen", content:content, w1:w, w2:(w-4), hMax:h})
												args.content=tempDiv.innerHTML;
												glbMap.showInfoDiv(args);
												glbMap.showMapTipWithDot=true;
											}
										  );
*/
}

