﻿ResizerClass = function(document) {
/// <summary>Управляет высотой панелей в зависимости от размеров окна.</summary>
/// <param name="document">Объект документа, используемый методами класса.</param>

    /// <field name="_document" domElement="true">Внутренняя ссылка на используемый объект документа.</field>
    this._document = document;

    ResizeElementClass = function(item, document) {
    /// <summary>Описывает отдельную панель для управления ее размером.</summary>
    /// <param name="item">DOM Element отдельного элемента управления размером панели bodyResizeElem</param>
    /// <param name="document">Объект документа, используемый методами класса.</param>
    
        if (Global.isNull(item)) return;

        /// <field name="_document" domElement="true">Внутренняя ссылка на используемый объект документа.</field>
        this._document = document;
        
        /// <field name="__toOf" integer="true">Расстояние до верхнего края страницы.</field>
        this.__tpOf = Global.toInt(item.getAttribute("topOffset"));

        /// <field name="__btOf" integer="true">Расстояние до нижнего края страницы.</field>
        this.__btOf = Global.toInt(item.getAttribute("bottomOffset"));

        /// <field name="__inEl" domElement="true">DOM Element управляемой панели</field>
        this.__inEl = item.getAttribute("ElementID") ? this._document.getElementById(item.getAttribute("ElementID")) : item.parentNode;
        this.flagToWidth = item.getAttribute("rWidth") ? true : false;

        this.checkObj = function() {
        /// <summary>Выполняет готовности панели к изменению размеров.</summary>
        /// <returns type="Boolean" >Отдельный bodyResizeElem элемент </returns>
            return (Global.isNull(this.__inEl));
        }

        this.Resize = function() {
        /// <summary>Выполняет подгонку размеров отдельной панели.</summary>
            
            if (!this.checkObj()) {
                var height = null;

                if (this.flagToWidth) {
                    var width = null;
                    var offset = Global.isSafari() ? 20 : 25;
                    if (Global.isSafari() || Global.isMozilla()) {
                        width = Global.toInt(innerWidth);
                    }
                    if (Global.isMSIE()) width = Global.toInt(this._document.getElementsByTagName('html')[0].offsetWidth);

                    if (!Global.isNull(width)) {
                        if (this.__inEl.style) this.__inEl.style.width = (width - offset).toString() + "px";
                    }
                }

                if (Global.isSafari() || Global.isMozilla()) {
                    height = Global.toInt(innerHeight);
                }
                if (Global.isMSIE()) height = Global.toInt(this._document.getElementsByTagName('html')[0].offsetHeight);


                if (!Global.isNull(height)) {
                    if (this.__inEl.style) {
                        var newHeight = height - this.__tpOf - this.__btOf;
                        if (newHeight > 0) {
                            this.__inEl.style.height = (newHeight).toString() + "px";
                        }
                    }
                }
            }
        }
    }

    this.__El = this._document.getElementsByTagName('bodyResizeElem');
    this._resEl = new Array();
    for (var i = 0; i < this.__El.length; i++) {
        this._resEl.push(new ResizeElementClass(this.__El[i], this._document));
    }
    for (var j in this._resEl) {
        this._resEl[j].Resize();
    }

    this.Resize = function() {
        /// <summary>Выполняет подгонку размеров панели под текущие размеры окна.</summary>
        for (var j in this._resEl) this._resEl[j].Resize();
    }
}


