(function($){
	$.fn.extend({ 
		autoscroll: function(options) {
		
		var options = $.extend(options);
		
			return this.each(function() {
				var $this = $(this);
				$this.css({overflow:'hidden'});
				if(options.direction == 'horizontal') $this.mousemove(function(e) {
					var width = $this.width();
					$this.attr({ scrollLeft: ($this.attr('scrollWidth')-width)*(0.5-Math.cos(Math.PI*(e.pageX-$this.offset().left)/width)/2) });
				});
				else if(options.direction == 'vertical') $this.mousemove(function(e) {
					var height = $this.height();
					$this.attr({ scrollTop: ($this.attr('scrollHeight')-height)*(0.5-Math.cos(Math.PI*(e.pageY-$this.offset().top)/height)/2) });
				});
				else $this.mousemove(function(e) {
					var width = $this.width(), height = $this.height();
					$this.attr({ scrollLeft: ($this.attr('scrollWidth')-width)*(0.5-Math.cos(Math.PI*(e.pageX-$this.offset().left)/width)/2), scrollTop: ($this.attr('scrollHeight')-height)*(0.5-Math.cos(Math.PI*(e.pageY-$this.offset().top)/height)/2) });
				});
			});
		}
	});
})(jQuery);
