/* It takes things and makes them scroll */

(function($) {
  $.fn.scrollBot = function(options) {
    var settings = {
      'speed' 		: false,
	  'direction'	: 'top', /* top-left-right-bottom */
	  'children'	: false
    };
    if (options) { $.extend(settings, options); }
    var a = 0;
	
    return this.each(function() {
		
		function scroll() {
			$scroller.animate({
				'margin-top' : -h
			}, speed, 'linear', function() {
				$scroller.css('margin-top', 0);
				speed = h*50;
				scroll();
			});
		}
		
		var $obj = $(this);
		$obj.children().wrapAll('<div class="scroller">');
		var $scroller = $('div.scroller', $obj);
		var h = $scroller.height();
		var speed = 0;
		if (settings['speed']) {
			speed = settings['speed'];
		} else {
			speed = h*50;
		}
		$scroller.children().clone().appendTo($scroller);
		$scroller.mouseenter(function() {
			$scroller.stop(true);
		}).mouseleave(function() {
			speed = (h+parseFloat($scroller.css('margin-top')))*50;
			scroll();
		});
		scroll();
		
	});
  };
})(jQuery);
