var Scroller = Class.create(); Scroller.prototype = { initialize: function(id, rate) { this.element = $(id); if ( !this.element ) { throw new Exception("No such element: " + id); } if ( rate ) { this.rate = rate; } else { this.rate = 500; } }, start: function() { h = $(this.element.parentNode).getHeight(); this.offset = h - (3*h/10); this.margin = this.offset; this.element.style.marginTop = this.offset + "px"; // this.executer = new PeriodicalExecuter(this.scroll.bind(this), this.rate); this.executer = setTimeout(this.scroll.bind(this), this.rate); }, stop: function() { this.executer.stop(); }, scroll: function() { this.margin--; if ( this.element.getHeight() + this.margin <= 0 ) { this.margin = this.offset; } this.element.style.marginTop = this.margin + "px"; this.executer = setTimeout(this.scroll.bind(this), this.rate); }, reset: function() { this.margin = this.offset; this.element.style.marginTop = this.margin + "px"; } };