(function($)
{

var type;
var speed;
var stopSection;
var frameRate;
var conWidth;
var conHeight;
	
$.fn.mousescroll = function(opt)
{
    var defaults = {
    speed: 5,
		stopSection: 150,
		type: "horizontal",
		frameRate: 90
    };
    
	var options = $.extend(defaults, opt);
  speed = options.speed;
	stopSection = options.stopSection;
	type = options.direction;
	frameRate = options.frameRate;
	
	var move = false;
	
	$(this).bind("mouseenter", function(e){
		move = true;
	});
	
	$(this).bind("mouseleave", function(e){
		move = false;
	});
	
	$(this).css({overflow: 'hidden'});
	conWidth = parseInt($(this).css('width'));
	conHeight = parseInt($(this).css('height'));
	
	var currentY;
	var currentX;
	
	$(this).mousemove(function(e){
		currentY = e.pageY - $(this).offset().top;
    currentX = e.pageX - $(this).offset().left;
	});
	
	var lessThanY = parseInt($(this).css('height'))/2 - stopSection/2;
	var moreThanY = parseInt($(this).css('height'))/2 + stopSection/2;
	var lessThanX = parseInt($(this).css('width'))/2 - stopSection;
	var moreThanX = parseInt($(this).css('width'))/2 + stopSection;
	
	function enterFrame(){
		if(move){
			if(currentX < lessThanX){
				scrollContainerX(-1, (lessThanX - currentX)/lessThanX);
			}
			else if(currentX > moreThanX){
				scrollContainerX(1, (currentX - moreThanX)/(conWidth - moreThanX));
			}
			else{
				scrollContainerX(0, 0);
			}
			
			if(currentY < lessThanY){
				scrollContainerY(-1, (lessThanY - currentY)/lessThanY);
			}
			else if(currentY > moreThanY){
				scrollContainerY(1, (currentY - moreThanY)/(conHeight - moreThanY));
			}
			else{
				scrollContainerY(0, 0);
			}
		}
	}
	var timer = setInterval(enterFrame, 1000/frameRate);
	
	function scrollContainerY(direction, acc){
		if(type == "vertical" || type == "both"){
			$('#slider').attr('scrollTop', $('#slider').attr('scrollTop') + (direction * speed)*acc);
		}
	}
	
	function scrollContainerX(direction, acc){
		if(type == "horizontal" || type == "both"){
			$('#slider').attr('scrollLeft', $('#slider').attr('scrollLeft') + (direction * speed)*acc);
		}
	}
	
};



})(jQuery);