(function($) {
	$.fn.scroller = function(options) {
		return this.each(function() {
			var $this = $(this);
			var loadedCnt = 0;

			var opt = $.extend({
					speed: "3000",
					tag: "li",
					addHeight: 0,
					fontSize: "12px"
				}, options || {}
			);

			$this.children().hide();
			$this.append("<div style='clear:both; padding: 0px; margin: 0px; font-size:"+opt.fontSize+";'></div>");
			loadedCnt = $(opt.tag, $this).length;

			var intVal = window.setInterval(
				function() {
					if (loadedCnt == $(opt.tag, $this).length) {
						window.clearInterval(intVal);
						//$this.children().fadeIn();
						$this.children().show();
						var totTag = 0;

						$.each(
							$this.children(":not(div)"), function() {
								/*
								$(this).css({
									margin: "0px",
									padding: "0px",
									clear: "both"
								});
								*/
								$(this).bind("mouseover", function() {
									$("div:eq(0)", $this).stop();
								}).bind("mouseout", function() {
									scrollStart($("div:eq(0)", $this), opt);
								});
								$("div:eq(0)", $this).append($(this));
							}
						);
						$("div:eq(0)", $this).css("height", totTag + "px");
						scrollStart($("div:eq(0)", $this), opt);
					}
				}, 100
			);

			function scrollStart($scroll, opt) {
				var tos = -($scroll.children(":eq(0)").height()+opt.addHeight);
				var spd = opt.speed - (Math.abs(parseInt($scroll.css("marginTop"))) * (opt.speed/$scroll.children(":eq(0)").height()));

				$scroll.animate({ marginTop: (tos || "0") + "px" }, spd, "linear", function() {
					$scroll.append($(this).children(":eq(0)"));
					$scroll.css("marginTop", "0px");
					scrollStart($scroll, opt);
				});
			};
		});
	};
})(jQuery);
