(function($){ 
    $.fn.extend({
    	options:
    	{
			scrollStep: 4,
			scrollInterval: 10
    	},
    	
    	self: null,

        scroll: function(leftButton, rightButton)
        {
        	// Save the own object to access threw functions
        	self = this;

        	// Cast the given strings or objects to a jQuery object
        	leftButton  = $(leftButton);
        	rightButton = $(rightButton);

        	// Save the variables
        	self.leftButton  = leftButton;
        	self.rightButton = rightButton;

        	// Initialize events
        	self.initialize();
        	
            // Return a jQuery object
            return $(self); 
        },
        
        initialize: function()
        {
        	// Add the left scroll event
        	self.leftButton.mouseover(function() {
        		// Scroll left
        		self.scrollLeft = true;
        		self.scrollToLeft();
        	});
        	// Add the left scroll end event
        	self.leftButton.mouseout(function() {
        		// Stop scroll left
        		self.scrollLeft = false;
        	});

        	// Add the right scroll event
        	self.rightButton.mouseover(function() {
        		// Scroll right
        		self.scrollRight = true;
        		self.scrollToRight();
        	});
        	// Add the right scroll end event
        	self.rightButton.mouseout(function() {
        		// Stop scroll right
        		self.scrollRight = false;
        	});
        },
        
        scrollToLeft: function()
        {
        	// Check whether we have to scroll
        	if(self.scrollLeft)
        	{
            	// Get the parent elemens
            	var parent = self.parent();
            	
            	// Get the old scroll
            	var oldScroll = parent.scrollLeft();
            	
            	// Set the new scroll
            	parent.scrollLeft(parent.scrollLeft() - self.options.scrollStep);
            	
            	// Check whether the scroll has changed
            	if(oldScroll != parent.scrollLeft())
            	{
            		// Do it again
            		setTimeout(self.scrollToLeft, self.options.scrollInterval);
            	}
            	else
            	{
            		// Stop scroll left
            		self.scrollLeft = false;
            	}
        	}
        },
        
        scrollToRight: function()
        {
        	// Check whether we have to scroll
        	if(self.scrollRight)
        	{
            	// Get the parent elemens
            	var parent = self.parent();
            	
            	// Get the old scroll
            	var oldScroll = parent.scrollLeft();
            	
            	// Set the new scroll
            	parent.scrollLeft(parent.scrollLeft() + self.options.scrollStep);
            	
            	// Check whether the scroll has changed
            	if(oldScroll != parent.scrollLeft())
            	{
            		// Do it again
            		setTimeout(self.scrollToRight, self.options.scrollInterval);
            	}
            	else
            	{
            		// Stop scroll left
            		self.scrollRight = false;
            	}
        	}
        }

        // TODO: scrollTop/Bottom and directions
    }); 
})(jQuery);
