﻿$=function (ipt) {return document.getElementById(ipt);};
    var CommonJs={};
    
    //渐变框类
    CommonJs.GradedBox=function (boxname,hpl,wpl,ph,pw) {//函数参数是函数的属性，并不是函数创建的对象的属性
        this.parmsh=ph;//纵向起止点
        this.parmsw=pw;//横向起止点
        this.hto;//当前目标高度
        this.wto;//当前目标宽度
        this.status = false;//当前状态，true展开/false收缩
        this.boxobj=$(boxname);//要操作的盒子对象
        this.timerh=false;//纵向计时器
        this.timerw=false;//横向计时器
        this.hplug=hpl;//纵向开关
        this.wplug=wpl;//横向开关
    };
    
    CommonJs.GradedBox.prototype.checkh = function (){
        var hfrom=parseInt(this.boxobj.style.height);
        var hoffset;
        if(hfrom!=this.hto)
        {
            hoffset=Math.ceil( Math.abs( this.hto - hfrom ) / 10 );
            if ( this.hto < hfrom )
            {
                hoffset = -hoffset;
            }
            this.boxobj.style.height=(hfrom+hoffset)+"px";
        }
        else
        {
            if((parseInt(this.boxobj.style.height)==0 || this.hplug) && (parseInt(this.boxobj.style.width)==0 || this.wplug))
            {
                this.boxobj.style.display="none";
            }
            this.timerh=true;
        }
    };
    
    CommonJs.GradedBox.prototype.checkw = function (){
        var wfrom=parseInt(this.boxobj.style.width);
        var woffset;
        if(wfrom!=this.wto)
        {
            woffset=Math.ceil( Math.abs( this.wto - wfrom ) / 10 );
            if ( this.wto < wfrom )
            {
                woffset = -woffset;
            }
            this.boxobj.style.width=(wfrom+woffset)+"px";
        }
        else
        {
            if((parseInt(this.boxobj.style.height)==0 || this.hplug) && (parseInt(this.boxobj.style.width)==0 || this.wplug))
            {
                this.boxobj.style.display="none";
            }
            this.timerw=true;
        }
    };
    
    CommonJs.GradedBox.prototype.changeh = function (obj,hhandle,whandle){
        if(!this.status)
        {
            this.boxobj.style.display="block";
            this.hto=this.parmsh[1];
            this.wto=this.parmsw[1];
//            obj.value="up";//按钮对象
            this.status=!this.status;
            this.timerw=false;
            this.timerh=false;
        }
        else
        {
            this.hto=this.parmsh[0];
            this.wto=this.parmsw[0];
//            obj.value="down";//按钮对象
            this.status=!this.status;
            this.timerw=false;
            this.timerh=false;
        }
        hhandle();
        whandle();
    };
