//send any questions/bugs/issues to sdailey@schoolfusion.com
(function($){
	$.fn.scroller = function() {
		var $elem = $(this), resume,
			run = true,
			spacing = 30,
			speed = 200,
			$wrap = $elem.parent('div'),
			tHeight = $elem.outerHeight(),
			wHeight = $wrap.height();
			
		if (tHeight > wHeight) {
			$elem.clone().appendTo($wrap).addClass('clone').css('marginTop', spacing);	
			
			function scroll(e) {
				var $this = $(e);
				if (run === true) {
					$this.animate({ scrollTop: '+=2' }, speed, function() {
						var st = $this.scrollTop();
						if (st > tHeight + spacing) {
							$this.animate({ scrollTop: 2}, 0);
							scroll(e);
						} else {
							scroll(e);
						}
					});	
				}
			};
			
			$.fn.hoverPause = function() {
				$(this).hover(function(){
					run = false;
					clearTimeout(resume);
				}, function() {
					resume = setTimeout(function() {
						run = true;
						scroll($wrap);
					});
				});
			};
			
			resume = setTimeout(function() {
				run = true;
				scroll($wrap);
			});

			$wrap.hoverPause();

		}
	};			
})(jQuery);
