var IRLayoutContainer = Class.create({
    initialize: function() {
        this.minimumWidth = -1;
        this.maximumWidth = -1;
        this.minimumHeight = -1;
        this.maximumHeight = -1;
        this.width = 0;
        this.height = 0;
        this.unitOfMeasureW = "px";
        this.unitOfMeasureH = "px";
        this.resizable = true;
        this.manageble = true;
        this.waitForChildren = false;
        this.childrenRendered = false;

        this.borders = new Array(4);
        (this.borders)[0] = 0;
        (this.borders)[1] = 0;
        (this.borders)[2] = 0;
        (this.borders)[3] = 0;

        this.paddings = new Array(4);
        (this.paddings)[0] = -1;
        (this.paddings)[1] = -1;
        (this.paddings)[2] = -1;
        (this.paddings)[3] = -1;
    },

    setLayoutManager: function(value) {
        this.layoutManager = value;
        this.layoutManager.setRootContainer(this);
    },

    setLayoutListener: function(layoutListener) {
        this.layoutListener = layoutListener;
        layoutListener.startObserving("resize");
    },

    setupElementProperties: function() {
        if (this.waitForChildren && this.childrenRendered) {
            this.setWidth(this.parentElement.getWidth());
            this.setHeight(this.parentElement.getHeight());

            if ((this.parentElement.getWidth() <= this.minimumWidth && this.minimumWidth > 0) || (this.parentElement.getWidth() >= this.maximumWidth && this.maximumWidth > 0)) {
                this.element.setStyle({
                    width: this.width + this.unitOfMeasureW
                });
                this.parentElement.setStyle({
                    overflowX: 'scroll'
                });
            }
            else {
                this.element.setStyle({
                    width: this.width + this.unitOfMeasureW
                });
                this.parentElement.setStyle({
                    overflowX: 'hidden'
                });
            }
            if ((this.parentElement.getHeight() <= this.minimumHeight && this.minimumHeight > 0) || (this.parentElement.getHeight() >= this.maximumHeight && this.maximumHeight > 0)) {
                this.element.setStyle({
                    height: this.height + this.unitOfMeasureH
                });
                this.parentElement.setStyle({
                    overflowY: 'scroll'
                });
            }
            else {
                this.element.setStyle({
                    height: this.height + this.unitOfMeasureH
                });
                this.parentElement.setStyle({
                    overflowY: 'hidden'
                });
            }
        }
        else if (this.waitForChildren && !this.childrenRendered) {
            /**/
        }
        else {
            this.setUpPaddings();
            this.element.setStyle({
                width: this.width + this.unitOfMeasureW,
                height: this.height + this.unitOfMeasureH
            });
        }
    },

    setUpPaddings: function() {
        var i = 0;
        for (i = 0; i < 4; i++) {
            if ((this.paddings)[i] > 0) {
                switch (i) {
                    case 0:
                        this.element.setStyle({
                            paddingTop: (this.paddings)[i] + this.unitOfMeasureH
                        });
                        break;
                    case 1:
                        this.element.setStyle({
                            paddingRight: (this.paddings)[i] + this.unitOfMeasureW
                        });
                        break;
                    case 2:
                        this.element.setStyle({
                            paddingBottom: (this.paddings)[i] + this.unitOfMeasureH
                        });
                        break;
                    case 3:
                        this.element.setStyle({
                            paddingLeft: (this.paddings)[i] + this.unitOfMeasureW
                        });
                        break;
                    default:
                        continue;
                }
            }
        }
    },

    renderContainer: function() {
        if (this.resizable) {
            this.setupElementProperties();
        }
        if (this.layoutManager != undefined && this.layoutManager != null) {
            this.layoutManager.doLayout();
        }
        if (this.waitForChildren) {
            this.setupElementProperties();
            this.childrenRendered = false;
        }
    },

    setDOMElement: function(elementObj) {
        this.element = elementObj;
    },

    setParentDOMElement: function(elementObj) {
        this.parentElement = elementObj;
    },

    setMinimumWidth: function(value) {
        this.minimumWidth = value;
    },

    setMaximumWidth: function(value) {
        this.maximumWidth = value;
    },

    setMinimumHeight: function(value) {
        this.minimumHeight = value;
    },

    setMaximumHeight: function(value) {
        this.maximumHeight = value;
    },

    setWidth: function(value) {
        if (value == -1) {
            return;
        }
        if (this.minimumWidth == this.maximumWidth && this.minimumWidth > 0 && this.maximumWidth > 0) {
            this.width = this.minimumWidth;
            return;
        }
        if (value < this.minimumWidth && this.minimumWidth != -1) {
            this.width = this.minimumWidth;
        }
        else if (value > this.maximumWidth && this.maximumWidth != -1) {
            this.width = this.maximumWidth;
        }
        else {
            this.width = value;
        }
        this.width -= (this.borders)[1] + (this.borders)[3];
    },

    setHeight: function(value) {
        if (value == -1) {
            return;
        }
        if (this.minimumHeight == this.maximumHeight && this.minimumHeight != -1 && this.maximumHeight != -1) {
            this.height = this.minimumHeight;
            return;
        }
        if (value < this.minimumHeight && this.minimumHeight != -1) {
            this.height = this.minimumHeight;
        }
        else if (value > this.maximumHeight && this.maximumHeight != -1) {
            this.height = this.maximumHeight;
        }
        else {
            this.height = value;
        }
        this.height -= (this.borders)[0] + (this.borders)[2];
    },

    getWidth: function() {
        return this.width;
    },

    getHeight: function() {
        return this.height;
    },

    setResizable: function(value) {
        this.resizable = value;
    },

    isResizable: function() {
        return this.resizable;
    },

    setManageble: function(value) {
        this.manageble = value;
    },

    isManageble: function() {
        return this.manageble;
    },

    getDOMElement: function() {
        return this.element;
    },

    getParentDOMElement: function() {
        return this.parentElement;
    },

    toString: function() {
        return this.element.readAttribute('id');
    },

    setUnitOfMeasureW: function(value) {
        this.unitOfMeasureW = value;
    },

    setUnitOfMeasureH: function(value) {
        this.unitOfMeasureH = value;
    },

    getUnitOfMeasureW: function(value) {
        return this.unitOfMeasureW;
    },

    getUnitOfMeasureH: function(value) {
        return this.unitOfMeasureH;
    },

    setWaitForChildren: function(value) {
        this.waitForChildren = value;
    },

    isWaitForChildren: function(value) {
        return this.waitForChildren;
    },

    setChildrenRendered: function(value) {
        this.childrenRendered = value;
    },

    isChildrenRendered: function(value) {
        return this.childrenRendered;
    },

    setBorders: function(top, right, bottom, left) {
        (this.borders)[0] = top;
        (this.borders)[1] = right;
        (this.borders)[2] = bottom;
        (this.borders)[3] = left;
    },

    setPaddings: function(top, right, bottom, left) {
        if (top != -2)
            (this.paddings)[0] = top - (this.borders)[0];
        if (right != -2)
            (this.paddings)[1] = right - (this.borders)[1];
        if (bottom != -2)
            (this.paddings)[2] = bottom - (this.borders)[2];
        if (left != -2)
            (this.paddings)[3] = left - (this.borders)[3];
    }
});

var IRBorderLayoutBuilder = Class.create({
    initialize: function(elements) {
        this.containerMap = new Array();
        (this.containerMap)["NORTH"] = new IRLayoutContainer();
        (this.containerMap)["SOUTH"] = new IRLayoutContainer();
        (this.containerMap)["CENTER"] = new IRLayoutContainer();
        (this.containerMap)["WEST"] = new IRLayoutContainer();
        (this.containerMap)["EAST"] = new IRLayoutContainer();
        this.elementMap = elements;
    },

    initContainers: function() {
        if ((this.elementMap)["NORTH"] != null) {
            (this.containerMap)["NORTH"].setDOMElement((this.elementMap)["NORTH"]);
            (this.containerMap)["NORTH"].setWidth((this.elementMap)["NORTH"].getWidth());
            (this.containerMap)["NORTH"].setHeight((this.elementMap)["NORTH"].getHeight());
        }
        else {
            (this.containerMap)["NORTH"] = null;
        }

        if ((this.elementMap)["SOUTH"] != null) {
            (this.containerMap)["SOUTH"].setDOMElement((this.elementMap)["SOUTH"]);
            (this.containerMap)["SOUTH"].setWidth((this.elementMap)["SOUTH"].getWidth());
            (this.containerMap)["SOUTH"].setHeight((this.elementMap)["SOUTH"].getHeight());
        }
        else {
            (this.containerMap)["SOUTH"] = null;
        }

        if ((this.elementMap)["CENTER"] != null) {
            (this.containerMap)["CENTER"].setDOMElement((this.elementMap)["CENTER"]);
            (this.containerMap)["CENTER"].setWidth((this.elementMap)["CENTER"].getWidth());
            (this.containerMap)["CENTER"].setHeight((this.elementMap)["CENTER"].getHeight());
        }
        else {
            (this.containerMap)["CENTER"] = null;
        }

        if ((this.elementMap)["WEST"] != null) {
            (this.containerMap)["WEST"].setDOMElement((this.elementMap)["WEST"]);
            (this.containerMap)["WEST"].setWidth((this.elementMap)["WEST"].getWidth());
            (this.containerMap)["WEST"].setHeight((this.elementMap)["WEST"].getHeight());
        }
        else {
            (this.containerMap)["WEST"] = null;
        }

        if ((this.elementMap)["EAST"] != null) {
            (this.containerMap)["EAST"].setDOMElement((this.elementMap)["EAST"]);
            (this.containerMap)["EAST"].setWidth((this.elementMap)["EAST"].getWidth());
            (this.containerMap)["EAST"].setHeight((this.elementMap)["EAST"].getHeight());
        }
        else {
            (this.containerMap)["EAST"] = null;
        }
    },

    getContainerMap: function() {
        return this.containerMap;
    }
});

var IRBorderLayoutManager = Class.create({
    initialize: function(elements) {
        this.containerMap = new Array();
        this.borderLayoutBuilder = new IRBorderLayoutBuilder(elements);
        this.borderLayoutBuilder.initContainers();
        this.containerMap = this.borderLayoutBuilder.getContainerMap();
    },

    makeLayout: function() {
        if (this.rootContainer == undefined || this.rootContainer == null) {
            return;
        }

        var rootContainerWidth = this.rootContainer.getWidth();
        var rootContainerHeight = this.rootContainer.getHeight();
        var pageBorderWidth = rootContainerWidth;
        var pageContentHeight = rootContainerHeight;

        if (this.rootContainer.isWaitForChildren()) {
            rootContainerWidth = this.rootContainer.getParentDOMElement().getWidth() - 3;
            rootContainerHeight = this.rootContainer.getParentDOMElement().getHeight();
            pageBorderWidth = rootContainerWidth;
            pageContentHeight = rootContainerHeight;
        }

        /*-----------NORTH------------*/
        if ((this.containerMap)["NORTH"] != undefined && (this.containerMap)["NORTH"] != null) {
            if ((this.containerMap)["NORTH"].getUnitOfMeasureW() != "%")
                (this.containerMap)["NORTH"].setWidth(rootContainerWidth);
            if ((this.containerMap)["NORTH"].getUnitOfMeasureH() != "%")
                (this.containerMap)["NORTH"].setHeight(((this.containerMap)["NORTH"]).getHeight());

            (this.containerMap)["NORTH"].renderContainer();
            pageContentHeight = pageContentHeight - (this.containerMap)["NORTH"].getHeight();
        }
        /*-----------SOUTH------------*/
        if ((this.containerMap)["SOUTH"] != undefined && (this.containerMap)["SOUTH"] != null) {
            if ((this.containerMap)["SOUTH"].getUnitOfMeasureW() != "%")
                (this.containerMap)["SOUTH"].setWidth(rootContainerWidth);
            if ((this.containerMap)["SOUTH"].getUnitOfMeasureH() != "%")
                (this.containerMap)["SOUTH"].setHeight(((this.containerMap)["SOUTH"]).getHeight());
            (this.containerMap)["SOUTH"].renderContainer();
            pageContentHeight = pageContentHeight - (this.containerMap)["SOUTH"].getHeight();
        }
        /*-----------CENTER-----------*/
        if ((this.containerMap)["CENTER"] != undefined && (this.containerMap)["CENTER"] != null) {
            if ((this.containerMap)["CENTER"].getUnitOfMeasureW() != "%")
                (this.containerMap)["CENTER"].setWidth(((this.containerMap)["CENTER"]).getWidth());
            if ((this.containerMap)["CENTER"].getUnitOfMeasureH() != "%")
                (this.containerMap)["CENTER"].setHeight(pageContentHeight);
            (this.containerMap)["CENTER"].renderContainer();
            pageBorderWidth = pageBorderWidth - (this.containerMap)["CENTER"].getWidth();
            /*if(this.rootContainer.toString() == "pageTopBottom")
            alert(this.rootContainer.getDOMElement().getWidth());*/
        }
        /*-----------WEST-------------*/
        if ((this.containerMap)["WEST"] != undefined && (this.containerMap)["WEST"] != null) {
            if ((this.containerMap)["WEST"].getUnitOfMeasureW() != "%")
                (this.containerMap)["WEST"].setWidth(pageBorderWidth / 2);
            if ((this.containerMap)["WEST"].getUnitOfMeasureH() != "%")
                (this.containerMap)["WEST"].setHeight(pageContentHeight);
            (this.containerMap)["WEST"].renderContainer();
        }
        /*-----------EAST-------------*/
        if ((this.containerMap)["EAST"] != undefined && (this.containerMap)["EAST"] != null) {
            if ((this.containerMap)["EAST"].getUnitOfMeasureW() != "%")
                (this.containerMap)["EAST"].setWidth(pageBorderWidth / 2);
            if ((this.containerMap)["EAST"].getUnitOfMeasureH() != "%")
                (this.containerMap)["EAST"].setHeight(pageContentHeight);
            (this.containerMap)["EAST"].renderContainer();
            /*if((this.containerMap)["EAST"].toString() == "pageMenuRightBorder")
            alert((this.containerMap)["EAST"].getDOMElement().getWidth());*/
        }

        if (this.rootContainer.isWaitForChildren()) {
            this.rootContainer.setChildrenRendered(true);
        }
    },

    setContainer: function(containerPosition, containerObject) {
        if (containerPosition == "NORTH") {
            (this.containerMap)["NORTH"] = containerObject;
        }
        else if (containerPosition == "SOUTH") {
            (this.containerMap)["SOUTH"] = containerObject;
        }
        else if (containerPosition == "WEST") {
            (this.containerMap)["WEST"] = containerObject;
        }
        else if (containerPosition == "EAST") {
            (this.containerMap)["EAST"] = containerObject;
        }
        else if (containerPosition == "CENTER") {
            (this.containerMap)["CENTER"] = containerObject;
        }
    },

    getContainer: function(containerPosition) {
        return (this.containerMap)[containerPosition];
    },

    setRootContainer: function(rootC) {
        this.rootContainer = rootC;
    },

    getRootContainer: function() {
        return this.rootContainer;
    },

    doLayout: function() {
        this.makeLayout();
    },

    setContainerBorders: function(containerPosition, borderSizes) {
        (this.getContainer(containerPosition)).setBorders(borderSizes[0], borderSizes[1], borderSizes[2], borderSizes[3]);
    }
});

var IRFlexGridLayoutBuilder = Class.create({
    initialize: function(m, n, elements) {
        this.containerMatrix = new Array();
        var i = 0;
        var j = 0;
        for (i = 0; i < m; i++) {
            (this.containerMatrix)[i] = new Array(n);
        }
        for (i = 0; i < m; i++) {
            for (j = 0; j < n; j++) {
                (this.containerMatrix)[i][j] = new IRLayoutContainer();
            }
        }
        this.nRows = m;
        this.nCols = n;
        this.elementMatrix = elements;
    },

    initContainers: function() {
        var i = 0;
        var j = 0;
        for (i = 0; i < this.nRows; i++) {
            for (j = 0; j < this.nCols; j++) {
                (this.containerMatrix)[i][j].setDOMElement((this.elementMatrix)[i][j]);
                (this.containerMatrix)[i][j].setWidth((this.elementMatrix)[i][j].getWidth());
                (this.containerMatrix)[i][j].setMinimumWidth((this.elementMatrix)[i][j].getWidth());
                (this.containerMatrix)[i][j].setHeight((this.elementMatrix)[i][j].getHeight());
                (this.containerMatrix)[i][j].setMinimumHeight((this.elementMatrix)[i][j].getHeight());
            }
        }
    },

    getContainerMatrix: function() {
        return this.containerMatrix;
    }
});

var IRFlexGridLayoutManager = Class.create({
    initialize: function(m, n, elements) {
        this.flexGridLayoutBuilder = new IRFlexGridLayoutBuilder(m, n, elements);
        this.flexGridLayoutBuilder.initContainers();
        this.containerMatrix = this.flexGridLayoutBuilder.getContainerMatrix();
        this.nRows = m;
        this.nCols = n;
        this.algorithm = "SAME_SIZE";
    },

    makeLayout: function() {
        if (this.rootContainer == undefined || this.rootContainer == null) {
            return;
        }

        var i = 0;
        var j = 0;
        var rootContainerWidth = this.rootContainer.getWidth();
        var rootContainerHeight = this.rootContainer.getHeight();

        if (this.algorithm == "SAME_SIZE") {
            var containerWidth = rootContainerWidth / (this.nCols)-1;
            var containerHeight = rootContainerHeight / (this.nRows);

            for (i = 0; i < this.nRows; i++) {
                for (j = 0; j < this.nCols; j++) {
                    (this.containerMatrix)[i][j].setWidth(containerWidth);
                    (this.containerMatrix)[i][j].setHeight(containerHeight);
                    (this.containerMatrix)[i][j].renderContainer();
                }
            }
        }
        else if (this.algorithm == "SAME_PADDING") {
            var totalHeight = 0;
            for (i = 0; i < this.nRows; i++) {
                var totalWidth = 0;
                for (j = 0; j < this.nCols; j++) {
					totalWidth = totalWidth + (this.containerMatrix)[i][j].getWidth();
                }
                var totalPaddingW = rootContainerWidth - totalWidth;
                var paddingW = Math.floor(totalPaddingW / (2 * (this.nCols)));
                for (j = 0; j < this.nCols; j++) {
					if((j == this.nCols-1) && (Prototype.Browser.IE)) {
						paddingWIE = Math.floor(paddingW);
						var diff =  (rootContainerWidth -(totalWidth + paddingWIE*this.nCols*2))/2;
						paddingW = paddingW + diff;
					}
                    (this.containerMatrix)[i][j].setPaddings(-2, paddingW, -2, paddingW);
                }
	        totalHeight = totalHeight + (this.containerMatrix)[i][0].getHeight();
            }

            var totalPaddingH = rootContainerHeight - totalHeight;
            var paddingH = totalPaddingH / (2 * (this.nRows));
            for (i = 0; i < this.nRows; i++) {
                for (j = 0; j < this.nCols; j++) {
                    (this.containerMatrix)[i][j].setPaddings(paddingH, -2, paddingH, -2);
                    (this.containerMatrix)[i][j].renderContainer();
                }
            }
        }
    },
	
    setContainer: function(i, j, containerObject) {
        (this.containerMatrix)[i][j] = containerObject;
    },

    getContainer: function(i, j) {
        return (this.containerMatrix)[i][j];
    },

    setRootContainer: function(rootC) {
        this.rootContainer = rootC;
    },

    getRootContainer: function() {
        return this.rootContainer;
    },

    doLayout: function() {
        this.makeLayout();
    },

    setContainersBorders: function(borderSizes, addTopFirst, addRightLast, addBottomLast, addLeftFirst) {
        var i = 0;
        var j = 0;
        var borderTemp = new Array();
        for (i = 0; i < this.nRows; i++) {
            for (j = 0; j < this.nCols; j++) {
                borderTemp[0] = borderSizes[0];
                borderTemp[1] = borderSizes[1];
                borderTemp[2] = borderSizes[2];
                borderTemp[3] = borderSizes[3];
                if (i == 0 && !addTopFirst) {
                    borderTemp[0] = 0;
                }
                if (j == this.nCols - 1 && !addRightLast) {
                    borderTemp[1] = 0;
                }
                if (j == this.nRows - 1 && !addBottomLast) {
                    borderTemp[2] = 0;
                }
                if (j == 0 && !addLeftFirst) {
                    borderTemp[3] = 0;
                }
                (this.containerMatrix)[i][j].setBorders(borderTemp[0], borderTemp[1], borderTemp[2], borderTemp[3]);
            }
        }
    },

    setAdjustmentAlgorithm: function(algorithmType) {
        this.algorithm = algorithmType;
    }
});

var IRContentLayoutBuilder = Class.create({
    initialize: function(elements, topMargin, bottomMargin) {
        var leftMargin = elements["LEFT_MARGIN"];
        var rightMargin = elements["RIGHT_MARGIN"];
        var content = elements["CONTENT"];

        this.containerMap = new Array();
        this.containerMap["LEFT_MARGIN"] = new IRLayoutContainer();
        this.containerMap["RIGHT_MARGIN"] = new IRLayoutContainer();
        this.containerMap["CONTENT"] = new IRLayoutContainer();
        this.top = topMargin;
        this.bottom = bottomMargin;

        this.containerMap["LEFT_MARGIN"].setWidth(44);
        this.containerMap["LEFT_MARGIN"].setHeight(20);
        this.containerMap["LEFT_MARGIN"].setMinimumWidth(44);
        this.containerMap["LEFT_MARGIN"].setMinimumHeight(20);
        this.containerMap["LEFT_MARGIN"].setDOMElement(leftMargin);
        this.containerMap["RIGHT_MARGIN"].setWidth(44);
        this.containerMap["RIGHT_MARGIN"].setHeight(20);
        this.containerMap["RIGHT_MARGIN"].setMinimumWidth(44);
        this.containerMap["RIGHT_MARGIN"].setMinimumHeight(20);
        this.containerMap["RIGHT_MARGIN"].setDOMElement(rightMargin);
        this.containerMap["CONTENT"].setDOMElement(content);
    },

    initContainers: function() {
        /**/
    },

    getContainerMap: function() {
        return this.containerMap;
    },

    getTopMargin: function() {
        return this.top;
    },

    getBottomMargin: function() {
        return this.bottom;
    }
});

var IRContentLayoutManager = Class.create({
    initialize: function(elements, topM, bottomM) {
        this.contentLayoutBuilder = new IRContentLayoutBuilder(elements, topM, bottomM);
        this.contentLayoutBuilder.initContainers();
        this.containerMap = this.contentLayoutBuilder.getContainerMap();
        this.topMargin = this.contentLayoutBuilder.getTopMargin();
        this.bottomMargin = this.contentLayoutBuilder.getBottomMargin();
    },

    makeLayout: function() {
        if (this.rootContainer == undefined || this.rootContainer == null) {
            return;
        }

        var i = 0;
        var j = 0;

        var rootContainerWidth = this.rootContainer.getDOMElement().getWidth();
        var rootContainerHeight = this.rootContainer.getDOMElement().clientHeight;
        rootContainerHeight = rootContainerHeight - this.topMargin - this.bottomMargin;
        var contentContainerHeight = this.containerMap["CONTENT"].getDOMElement().getHeight();

        var resultHeight = (contentContainerHeight > rootContainerHeight) ? contentContainerHeight + this.bottomMargin : rootContainerHeight;

        this.containerMap["LEFT_MARGIN"].setHeight(resultHeight);
        this.containerMap["RIGHT_MARGIN"].setHeight(resultHeight);

        this.containerMap["LEFT_MARGIN"].renderContainer();
        this.containerMap["RIGHT_MARGIN"].renderContainer();
    },

    setRootContainer: function(rootC) {
        this.rootContainer = rootC;
    },

    getRootContainer: function() {
        return this.rootContainer;
    },

    doLayout: function() {
        this.makeLayout();
    }
});

var IRFooterLayoutBuilder = Class.create({
    initialize: function(elements, topMargin, bottomMargin) {
        var content = elements["CONTENT"];
        var footer = elements["FOOTER"];
        this.containerMap = new Array();
        this.top = topMargin;
        this.bottom = bottomMargin;

        this.containerMap["FOOTER"] = new IRLayoutContainer();
        this.containerMap["CONTENT"] = new IRLayoutContainer();

        this.containerMap["FOOTER"].setDOMElement(footer);
        this.containerMap["CONTENT"].setDOMElement(content);
    },

    initContainers: function() {

    },

    getContainerMap: function() {
        return this.containerMap;
    },

    getTopMargin: function() {
        return this.top;
    },

    getBottomMargin: function() {
        return this.bottom;
    }
});

var IRFooterLayoutManager = Class.create({
    initialize: function(elements, topM, bottomM) {
        this.footerLayoutBuilder = new IRFooterLayoutBuilder(elements, topM, bottomM);
        this.footerLayoutBuilder.initContainers();
        this.containerMap = this.footerLayoutBuilder.getContainerMap();
        this.topMargin = this.footerLayoutBuilder.getTopMargin();
        this.bottomMargin = this.footerLayoutBuilder.getBottomMargin();
    },

    makeLayout: function() {
        if (this.rootContainer == undefined || this.rootContainer == null) {
            return;
        }

        var rootContainerWidth = this.rootContainer.getDOMElement().getWidth();
        var rootContainerHeight = this.rootContainer.getDOMElement().getHeight();
        var footer = this.containerMap["FOOTER"];
        var content = this.containerMap["CONTENT"];
        rootContainerHeight = rootContainerHeight - this.topMargin - this.bottomMargin - content.getDOMElement().getHeight();
        var resultHeight = (rootContainerHeight > 10) ? rootContainerHeight : 10;
        footer.getDOMElement().setStyle({
            position: 'relative',
            bottom: -resultHeight + 'px'
        });
    },

    setRootContainer: function(rootC) {
        this.rootContainer = rootC;
    },

    getRootContainer: function() {
        return this.rootContainer;
    },

    doLayout: function() {
        this.makeLayout();
    }
});

/*var IRSingleContainerManagerHeight = Class.create({
initialize: function(containerObject, element) {
this.container = containerObject;
this.container.setWidth(element.getWidth());
this.container.setHeight(element.getHeight());
},
	
makeLayout: function() {
if(this.rootContainer == undefined || this.rootContainer == null) {
return;
}
			
var rootContainerHeight = this.rootContainer.getHeight();
this.container.setHeight(rootContainerHeight);
this.container.renderContainer();
},
		
setRootContainer: function(rootC) {
this.rootContainer = rootC;
},
	
getRootContainer: function() {
return this.rootContainer;
},
	
doLayout: function() {
this.makeLayout();
}
});*/

var IRLayoutListener = Class.create({
    initialize: function(cAreaObject, rootContainer) {
        this.clientAreaObject = cAreaObject;
        this.rootLayoutContainer = rootContainer;
    },

    startObserving: function(strEventType) {
        var handlerFunction = this.rootLayoutContainer.renderContainer.bind(this.rootLayoutContainer);
        Event.observe(this.clientAreaObject, strEventType, handlerFunction);
    },

    stopObserving: function(strEventType) {
    }
});
