var _scroller=new Object;
_scroller.speed=0;
_scroller.speed_inc_step=0.01;
_scroller.speed_dec_step=0.01;

_scroller.run=function (id, side){
    this.id=id;
    this.obj = document.getElementById(this.id);
    this.side=side;
    this.height=this.obj.scrollHeight - this.obj.offsetHeight;
    this.width=this.obj.scrollWidth - this.obj.offsetWidth;
    var self=this;
    this.scroll_timer=setTimeout('_scroller.faster()', 1);
}

_scroller.do_scroll=function(){
	switch(this.side){
	case 'up':
    	if (this.obj.scrollTop > 0) {
	        this.obj.scrollTop-=this.speed;
	    }else{
	    	clearTimeout(this.scroll_timer);
	    	this.speed=0;
	    }
	    break;
    case 'down':
	    if (this.obj.scrollTop < this.height) {
	        this.obj.scrollTop+=this.speed;
	    }else{
	    	clearTimeout(this.scroll_timer);
	    	this.speed=0;
	    }
	    break;
	case 'left':
	    if (this.obj.scrollLeft > 0) {
	        this.obj.scrollLeft-=this.speed;
	    }else{
	    	clearTimeout(this.scroll_timer);
	    	this.speed=0;
	    }
	    break;
	case 'right':
	    if (this.obj.scrollLeft < this.width) {
	        this.obj.scrollLeft+=this.speed;
	    }else{
	    	clearTimeout(this.scroll_timer);
	    	this.speed=0;
	    }
	    break;
	}
}

_scroller.faster=function(){
	clearTimeout(this.scroll_timer);
    this.speed+=this.speed_inc_step;
	this.do_scroll();
	this.scroll_timer=setTimeout('_scroller.faster()');
}

_scroller.slower=function(){
	clearTimeout(this.scroll_timer);
    this.speed-=this.speed_dec_step;
	if(this.speed<=0){
        this.speed=0;
        clearTimeout(this.scroll_timer);
	}else{
    	this.do_scroll();
    	this.scroll_timer=setTimeout('_scroller.slower()');
	}
}

_scroller.stop=function (){
	this.slower();
}

function start_scroll(id, side){
	_scroller.run(id, side);
}

function stop_scroll(){
	_scroller.stop();
}