$.fn.Scroller = function(refresh, direction, speed, waittime) 
{
	$this = $(this);
	
	$this.parent().css("position", "relative");
	$this.parent().css("overflow", "hidden");

	$this.css("position", "relative");
	
	$this.attr("refresh", refresh || 50);
	$this.attr("direction", direction || "up");
	$this.attr("speed", speed || 1);
	$this.attr("waittime", waittime || 20);

	$direction = $this.attr("direction");
	$this.attr("top", 0);
	$this.attr("left", 0);
	if($direction == "up" || direction == "updown")
		$this.attr("top", 0);
	if($direction == "down")
		$this.attr("top", $this.parent().height() - $this.height());
	if($direction == "left" || direction == "leftright")
		$this.attr("left", 0);
	if($direction == "right")
		$this.attr("left", $this.parent().width() - $this.width());
	
	$this.everyTime(parseInt($this.attr("refresh")), function(i) 
	{
		$this = $(this);
		
		$wait = parseInt($this.attr("wait"));
		$paused = $this.attr("paused");
		if($wait > 0 || $paused == "true")
		{
			$wait--;
			$this.attr("wait", $wait);
		}
		else
		{
			$speed = parseInt($this.attr("speed"));
			$top = parseInt($this.attr("top")); 
			$left = parseInt($this.attr("left"));
			$direction = $this.attr("direction");
			
			if(direction == "up")
			{
				$top = $top - $speed;
				if($top < -$this.height())
					$top = $this.parent().height();
			}
			if(direction == "down")
			{
				$top = $top + $speed;
				if($top > $this.parent().height())
					$top = -$this.height();
			}
			if(direction == "left")
			{
				$left = $left - $speed;
				if($left < -$this.width())
					$left = $this.parent().width();
			}
			if(direction == "right")
			{
				$left  = $left + $speed;
				if($left  > $this.parent().width())
					$left  = -$this.width();
			}
			if(direction == "updown")
			{
				$top = $top - $speed;
				if($top > 0 || $top  + 10 < $this.parent().height() - $this.height())
				{
					$speed = -$speed;
					$this.attr("wait", $this.attr("waittime"));
					$this.attr("speed", $speed);
				}
			}
			if(direction == "leftright")
			{
				$left = $left - $speed;
				if($left > 0 || $left  + 10 < $this.parent().width() - $this.width())
				{
					$speed = -$speed;
					$this.attr("wait", $this.attr("waittime"));
					$this.attr("speed", $speed);
				}
			}
			
			$this.css("top", $top + "px");		
			$this.css("left", $left + "px");		
			$this.attr("top", $top);
			$this.attr("left", $left);
		}
	});
	
	$this.hover(function()
	{
		$(this).attr("paused", "true");
	}, function()
	{
		$(this).attr("paused", "false");
	});
	
	return $this;
};