var BestHtmlScroller = Class.create({
	initialize: function (el, options) {
		this.el = $(el);
		this.inner = this.el.down();
		this.options = Object.extend({
			delay: 80,
			delta: 1
		}, options);
		this.timer = false;
		this.canScroll = false;
	},
	update: function () {
		if (!this.canScroll) return;
		this.canScroll = false;
		var top = parseInt(this.inner.getStyle('top'));
		var first = this.inner.down();
		var firstHeight = first.getHeight();
		firstHeight += parseInt(first.getStyle('margin-top') || 0);
		firstHeight += parseInt(first.getStyle('padding-top') || 0);
		firstHeight += parseInt(first.getStyle('margin-bottom') || 0);
		firstHeight += parseInt(first.getStyle('padding-bottom') || 0);
		if (top+firstHeight < 0) {
			top = 0;
			first.remove();
			this.inner.appendChild(first);
		}
		this.inner.style.top = (top - this.options.delta) + 'px';
		this.canScroll = true;
	},
	start: function () {
		if (this.timer) return;
		this.canScroll = true;
		this.timer = setInterval(this.update.bind(this), this.options.delay);
	},
	stop: function () {
		if (!this.timer) return;
		this.canScroll = false;
		clearInterval(this.timer);
		this.timer = false;
	}
})

var feedScroller = new BestHtmlScroller($('splash-feeds'), {});
feedScroller.start();
