YDN.HeadlineScroller = Class.create(); YDN.HeadlineScroller.prototype = { initialize: function(id, speed, delay) { //Set the variables that are passed in to be instance variables this.id = id; this.speed = speed; this.delay = delay; this.scroller = $(this.id); //Set styles Element.setStyle(this.scroller, {position: 'relative', overflow: 'hidden'}); //Create inner scrolling div this.scroller.innerHTML = "
" + this.scroller.innerHTML + "
"; //Set style of inner this.inner = $(id + "_inner"); this.scrollerDimensions = this.scroller.getDimensions(); Element.setStyle(this.inner, {position: 'absolute', left: "0px", top: this.scrollerDimensions.height + "px", width: this.scrollerDimensions.width}); //Calculate the height limit this.limit = this.inner.getElementsBySelector('div').length * parseInt(this.scrollerDimensions.height); //Show the scroller Element.setStyle(this.scroller, {display: 'block'}); //Execute the helper function this.bind(setTimeout(this.doScroll(), parseInt(this.speed))); }, doScroll : function() { nextTick = this.speed; //Move the div if (parseInt(this.inner.getStyle('top')) < -this.limit) { Element.setStyle(this.inner, {top: this.scrollerDimensions.height + "px"}); } else { Element.setStyle(this.inner, {top: (parseInt(this.inner.getStyle('top'))-17) + "px"}); } //Get inner's top and scroller's height innerTop = this.inner.getStyle('top'); scrollerHeight = this.scroller.getHeight(); if (!(parseInt(innerTop) == parseInt(scrollerHeight)) && !(parseInt(innerTop) == -this.limit) && (parseInt(innerTop) % parseInt(scrollerHeight)) == 0) { nextTick = this.delay; } alert(nextTick); this.bind(setTimeout(this.doScroll(), parseInt(nextTick))); } }; var scroller = new YDN.HeadlineScroller("headlinescroller", 20, 4000);