function Appears(iterVector, nSleep) {
    if(typeof(iterVector) == "undefined")
        iterVector = {
            "stWidth": 0,
            "endWidth": 100,
            "stHeight": 0,
            "endHeight": 100,
            "stAlpha": 0,
            "endAlpha": 100,
            "iStep": 0,
            "StepsCount": 100
        };

    this.objectState = {
        "nextIter": function() {
            var v = this.vector;
            (v.iStep < v.StepsCount) ? v.iStep++ : v.iStep;

            this.state.cWidth = this.calc("Width");
            this.state.cHeight = this.calc("Height");
            this.state.cAlpha = this.calc("Alpha");

            return v.iStep<v.StepsCount;
        },
        "prevIter": function() {
            var v = this.vector;
            (v.iStep > 0) ? v.iStep-- : v.iStep;

            this.state.cWidth = this.calc("Width");
            this.state.cHeight = this.calc("Height");
            this.state.cAlpha = this.calc("Alpha");

            return v.iStep>0;
        },

        "calc": function(attrName) {
            var v = this.vector;
            var s = v["st" + attrName];
            var e = v["end" + attrName];

            return parseInt(s+(e-s)*v.iStep/v.StepsCount);
        },
        "vector": iterVector,

        "state": {
            "cWidth": 0,
            "cHeight": 0,
            "cAlpha": 0
        }
    }

    this.delay = typeof(nSleep) == "undefined" ? 50 : nSleep;
	this.navObj = null;
	this.isRunning = false;

	this.Attach = function(hElem) {
    	var hElem = (typeof(hElem)=="string") ? he(hElem) : hElem;
    	if(hElem == null)
    		return false;

    	this.navObj = hElem;

		return true;
	}
	this.Show = function(bShow) {
	    if(typeof(bShow)=="undefined") {
	        bShow = !this.isVisible();
	        if(bShow)
	            this.SetDisplayMode(true);
	    }
	    var bProc = bShow ? this.objectState.nextIter() :
	                        this.objectState.prevIter();

	    this.SetDimentions();

	    var o = this;
	    if(bProc) {
	        this.isRunning = true;
	        setTimeout(
	            function() {
	                o.Show(bShow);
	            },
	            this.delay
	        );
	    } else {
	        this.isRunning = false;
	        if(!bShow)
	            this.SetDisplayMode(false);
	      }
	}
	this.SetPosition = function(x,y) {
	    if(this.navObj != null) {
	        this.navObj.style.top = y + "px";
	        this.navObj.style.left = x + "px";
	    }
	}
	this.SetDimentions = function() {
        var st = this.objectState.state;
        this.navObj.style.width = st.cWidth + "px";
        this.navObj.style.height = st.cHeight + "px";

        setElementOpacity(this.navObj, st.cAlpha/100);
	}
	this.SetDisplayMode = function(bDisplay) {
	    this.navObj.style.display = (bDisplay ? "block" : "none");
	}
	this.isVisible = function() { return getElementComputedStyle(this.navObj, "display") == "block"; }
}

function SetAppearing(btnId, divId, closeId, vect) {	addEventHandler(window, "load",
        function(e) {
            var hBtnAccount = he(btnId);
            if(hBtnAccount != null) {
                var objApp = new Appears(vect, 10);
                if(objApp.Attach(divId)) {
                    addEventHandler(hBtnAccount, "click",
                            function(ev) {
                                var ev = ev||window.event;
                                var t = ev.target||ev.srcElement;
                                var oPos = getElementPosition(t);

    			                ev.returnValue = false;
		    	                if (ev.preventDefault)
		        	                ev.preventDefault();

                                objApp.SetPosition(oPos.left, oPos.top + oPos.height + 3);

                                if(objApp.isRunning == false) {
                                    objApp.Show();
                                }

                                return false;
                            }
                        );
                    var btnAccClose = he(closeId);
                    if(btnAccClose != null)
                    addEventHandler(btnAccClose, "click",
                            function(ev) {
                                var ev = ev||window.event;
    			                ev.returnValue = false
		    	                if (ev.preventDefault)
		        	                ev.preventDefault();

                                if(objApp.isRunning == false) {
                                    objApp.Show();
                                }
                            }
                        );
                }
            }

        }
    );}

