﻿var FilterEffects = function(objid, id, defpos){
    this.obj = new GetDocElement(objid);
    this.id = id;       
    return this;
}

FilterEffects.prototype = {
    CreateElementAround: function(tagname, obj, ElemId){
        var newElem = document.createElement(tagname);
        newElem.id = ElemId;        
        obj.parentNode.insertBefore(newElem,obj);        
        newElem.appendChild(obj);
        return newElem;
    },
    Init: function(){
        if(!this.obj.OuterDiv){
            this.CreateElementAround('div',this.obj,this.obj.id + '_outerDiv');            
            this.obj.OuterDiv = new GetDocElement(this.obj.id + '_outerDiv');
            with(this.obj.OuterDiv.style){                
                overflow = "hidden";
                zIndex = "1";
            }
        }
        if(!this.obj.InnerDiv){
            this.CreateElementAround('div',this.obj,this.obj.id + '_innerDiv');
            this.obj.InnerDiv = new GetDocElement(this.obj.id + '_innerDiv');
            with(this.obj.InnerDiv.style){
                //position = "relative";
                //zIndex = "-1";
            }
        }
        this.MakeSameSize(this.obj,this.obj.InnerDiv);
        this.MakeSameSize(this.obj.InnerDiv,this.obj.OuterDiv);
    },
    MakeSameSize: function(obj1, obj2){
        var object1 = obj1;
        var object2 = obj2;
        if(object1 && object2){            
            var width = object1.offsetWidth;
            var height = object1.offsetHeight;
            //object2.style.width = width + "px";
            object2.style.height = height + "px";
        }
    },
    InitExpand: function(Type){
        this.Init();
        this.obj.MaxExpand = this.obj.offsetHeight;
        this.obj.MinExpand = 1;
        if(!this.obj.haveExpandInfo){
            this.obj.haveExpandInfo = true;
            this.obj.ExpandTimeout = null;
            if(Type=="In"){
                this.obj.CurrExpand = this.obj.MinExpand;
                this.obj.OuterDiv.style.visibility = "hidden";
            }else{
                this.obj.CurrExpand = this.obj.MaxExpand;
                this.obj.OuterDiv.style.visibility = "visible";
            }
            this.obj.OuterDiv.style.height = this.obj.CurrExpand + "px";
        }
    },
    ExpandIn: function(speed, stepper, callback){        
        this.InitExpand("In");
        var step = (stepper/100) * this.obj.MaxExpand;
        clearTimeout(this.obj.ExpandTimeout);
        if(this.obj.CurrExpand<this.obj.MaxExpand){
            this.obj.OuterDiv.style.visibility = "visible";
            this.obj.CurrExpand += step;
            if(this.obj.CurrExpand>this.obj.MaxExpand){
                this.obj.CurrExpand = this.obj.MaxExpand;
            }
            this.obj.OuterDiv.style.height = this.obj.CurrExpand + "px";
            this.obj.ExpandTimeout = setTimeout(this.id + ".ExpandIn(" + speed + "," + stepper + ",\"" + callback + "\");", speed);
        }else{
            this.obj.OuterDiv.style.visibility = "visible";
            this.obj.CurrExpand = this.obj.MaxExpand;
            this.obj.OuterDiv.style.height = this.obj.CurrExpand + "px";                       
            if(callback){
                eval(callback);
            }
        }
        try{this.obj.OuterDiv.focus();}catch(e){}
    },
    ExpandOut: function(speed, stepper, callback){        
        this.InitExpand("Out");
        var step = parseInt((stepper/100) * this.obj.MaxExpand);
        clearTimeout(this.obj.ExpandTimeout);
        if(this.obj.CurrExpand>this.obj.MinExpand){
            this.obj.OuterDiv.style.visibility = "visible";
            this.obj.CurrExpand -= step;
            if(this.obj.CurrExpand<=this.obj.MinExpand){                
                this.obj.CurrExpand = this.obj.MinExpand;               
            }
            this.obj.OuterDiv.style.height = this.obj.CurrExpand + "px";
            this.obj.ExpandTimeout = setTimeout(this.id + ".ExpandOut(" + speed + "," + stepper + ",\"" + callback + "\");", speed);            
        }else{
            this.obj.CurrExpand = this.obj.MinExpand;
            this.obj.OuterDiv.style.height = this.obj.CurrExpand + "px";
            this.obj.OuterDiv.style.visibility = "hidden";
            if(callback){
                eval(callback);
            }
        }
        try{this.obj.OuterDiv.focus();}catch(e){}
    }
}

var GetDocElement = function(objid){
    return document.getElementById(objid);    
}
