var $Scroller = {
	speed : 700,
	pause : 7000,
	scrollers : { },
	scroller_count : 0,
	interval: null,
	moveUp : function(obj, height) {
		var first = obj.children('ul').children('li:first').clone(true);
		obj.children('ul')
			.animate({top: -height}, $Scroller.speed, function() {
				$(this).children('li:first').remove();
				$(this).css('top', '0px');
			});

		first.appendTo(obj.children('ul'));
	},
	scroll : function() {
		for (var i in $Scroller.scrollers) {
			var item = $Scroller.scrollers[i];
			if (!item.paused) $Scroller.moveUp(item.obj, item.height)
		}
	},
	_findThis : function(obj) {
		for (var i in $Scroller.scrollers) {
			var item = $Scroller.scrollers[i];
			if (item.obj == obj) return item;
		}
		return null;
	},
	onHover : function(obj) {
		var _this = $Scroller._findThis(obj);
		if (!_this) return;
		_this.paused = true;
	},
	afterHover : function(obj) {
		var _this = $Scroller._findThis(obj);
		if (!_this) return;
		_this.paused = false;
	},

	init: function() {
		$('.scroll').each(function() {
			var maxHeight = $(this).height();
			var _this = $(this);
			_this.hover(function(){$Scroller.onHover(_this);}, function(){$Scroller.afterHover(_this);});


			_this.children('ul').children('li').each(function() {
				if ($(this).height() > maxHeight) maxHeight = $(this).height();
			});
			var offset = 0;
			var ul = _this.children('ul:first');
			if (typeof ul.attr('scrolloffset') != 'undefined') {
				offset = parseInt(ul.attr('scrolloffset'));
			}

			$Scroller.scrollers[$Scroller.scroller_count++] = { obj: _this, height: maxHeight+offset, paused: false };
		});
		this.interval = setInterval('$Scroller.scroll()', $Scroller.pause);
	}
};
$(function() { $Scroller.init(); });
