function scrolls(elementId, scrollLeft, scrollTop, visibleWidth, visibleHeight, speed) {
    
    this.elementId = elementId;
    this.visibleWidth = visibleWidth;
    this.visibleHeight = visibleHeight;
    this.scrollLeft = scrollLeft;
    this.scrollTop = scrollTop;
    this.posTop = 0;
    this.posLeft = 0;
    this.posLeftMax = 0;
    this.posTopMax = 0;
    if (typeof(speed)!='undefined' && speed=='slow')
    {
        this.scrollStepSpeed1 = 0.1;
        this.scrollStepSpeed2 = 0.4;
        this.scrollStepSpeed3 = 0.6;
        this.scrollStepSpeed4 = 0.8;
        this.scrollStepSpeed5 = 1;
    }
    else
    {
        this.scrollStepSpeed1 = 0.2;
        this.scrollStepSpeed2 = 0.8;
        this.scrollStepSpeed3 = 1.2;
        this.scrollStepSpeed4 = 1.6;
        this.scrollStepSpeed5 = 2;
    }
    this.scrollTimerSpeed = 1;
    this.scrollTimerMinSpeed = 10;
    this.stepIndex = 0;
    this.stepOutIndex = 0;
    this.run = false;
    this.haltReq = false;
    
    this.timer = null;
    
    if (typeof(sObject)=='undefined')
    {
        this.sObjectIndex = 0;
        sObject = new Array();
        sObject[this.sObjectIndex] = this;
    }
    else
    {
        this.sObjectIndex = sObject.length;
        sObject[this.sObjectIndex] = this;
    }
    //selfObject = this;
    
    this.goScroll = function (direction) {
        if (this.scrollObject==null || typeof(this.scrollObject)=='undefined')
            this.scrollObject = this.getScrollObject(this.elementId);
        if (this.scrollObject)
        {
            if (this.run)
            {
                clearTimeout(this.timer);
            }
            this.run = true;
            this.stepIndex = 0;
//            setTimeout(function(){ sObject[0].scroll(direction); }, this.scrollTimerSpeed);
            setTimeout('sObject['+this.sObjectIndex+'].scroll(\''+direction+'\');', this.scrollTimerSpeed);
            this.haltReq = false;
        }
    }

    this.haltScroll = function (direction) {
        if (this.scrollObject==null || typeof(this.scrollObject)=='undefined')
            this.scrollObject = this.getScrollObject(this.elementId);
        if (this.scrollObject && this.run)
        {
            this.stepOutIndex = (this.stepIndex > 40) ? 40 : this.stepIndex;
            this.haltReq = true;
            this.stepIndex = 0;
            //setTimeout(function(){ self.scroll(direction); }, this.scrollTimerSpeed);
        }
    }
    
    this.scroll = function (direction) {
        if (this.scrollObject)
        {
            this.stepIndex++;
            if (this.haltReq)
            {
                this.stepOutIndex--;
                if (this.stepOutIndex>34 && this.stepIndex>34)
                    step = this.scrollStepSpeed5;
                else if (this.stepOutIndex>26 && this.stepIndex>26)
                    step = this.scrollStepSpeed4;
                else if (this.stepOutIndex>18)
                    step = this.scrollStepSpeed3;
                else if (this.stepOutIndex>10)
                    step = this.scrollStepSpeed2;
                else
                    step = this.scrollStepSpeed1;
                if (this.stepOutIndex==0)
                    this.run = false;
            }
            else
            {
                if (this.stepIndex>34)
                    step = this.scrollStepSpeed5;
                else if (this.stepIndex>26)
                    step = this.scrollStepSpeed4;
                else if (this.stepIndex>18)
                    step = this.scrollStepSpeed3;
                else if (this.stepIndex>10)
                    step = this.scrollStepSpeed2;
                else
                    step = this.scrollStepSpeed1;
            }
            with (this.scrollObject)
            {
                switch (direction)
                {
                    case 'down':
                        if (this.posTop>=this.maxTop)
                            this.run = false
                        else if (this.run)
                        {
                            this.posTop = this.posTop + step;
                            scrollTop = Math.floor(this.posTop);
                        }
                        break;
                    case 'up':
                        if (this.posTop<=0)
                            this.run = false
                        else if (this.run)
                        {
                            this.posTop = this.posTop - step;
                            scrollTop = Math.floor(this.posTop);
                        }
                        break;
                    case 'left':
                        if (this.posLeft>=this.maxLeft)
                            this.run = false
                        else if (this.run)
                        {
                            this.posLeft = this.posLeft + step;
                            scrollLeft = Math.floor(this.posLeft);
                            //style.left = Math.floor(this.posLeft).toString()+'px';
                        }
                        break;
                    case 'right':
                        if (this.posLeft<=0)
                            this.run = false
                        else if (this.run)
                        {
                            this.posLeft = this.posLeft - step;
                            scrollLeft = Math.floor(this.posLeft);
                            //style.left = Math.floor(this.posLeft)+'px';
                        }
                        break;
                }
                //getElement('out').innerHTML = "#"+this.stepIndex+'/'+step+' '+((this.run)?'scrolling':'stopped')+' left:'+this.maxLeft;//Math.floor(this.posLeft)+'/'+this.scrollSpeed;
            }
            if (this.run)
                this.timer = setTimeout('sObject['+this.sObjectIndex+'].scroll(\''+direction+'\');', this.scrollTimerSpeed);
//                this.timer = setTimeout(function(){ sObject[0].scroll(direction); }, this.scrollTimerSpeed);
        }
    }

    this.getScrollObject = function (name) {
        if (document.getElementById)
            return document.getElementById(name)
        else if (document.all)
            return document.all.name
        return false;
    }

    if (this.scrollObject = this.getScrollObject(this.elementId))
    {
        this.offsetWidth = this.visibleWidth;//getElementWidth(this.elementId);
        this.offsetHeight = this.visibleHeight;
        this.scrollObject.style.position = 'relative';
        if (this.scrollLeft > this.offsetWidth)
        {
            this.scrollObject.scrollLeft = this.scrollLeft - this.offsetWidth;
            this.posLeft = this.offsetWidth + (this.scrollObject.scrollLeft - this.offsetWidth);
        }
        //this.scrollObject.scrollTop = 100;
        this.maxLeft = this.scrollObject.scrollWidth - this.offsetWidth;
        this.maxTop = this.scrollObject.scrollHeight - this.offsetHeight;
        //getElement('out').innerHTML = typeof(this.scrollObject.pageXOffset)+' '+this.maxLeft;
    }
    
}

function getElementWidth(Elem) {
	if (typeof(ns4)!='undefined') {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (typeof(op5)!='undefined') {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getElementHeight(Elem) {
	if (typeof(ns4)!='undefined') {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (typeof(op5)!='undefined') { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}
