
$.fn.slider = function(options) 
{
	var sliders = [];
	var last = this.length;
	
	var options = $.extend(
	{
		delay: 20,
		visibleBoxes: 3,
		isRunning: true,
		currentPosition: 0,
		rewindOn: 0,
		container: null
	}, options);
	
	
	var animate = function(o)
	{
		var i = sliders.length;
		
		while(i--)
		{
			var o = sliders[i];
			
			if(!o.isRunning) 
			{
				continue;
			}

			o.currentPosition--;

			if(o.currentPosition <= o.rewindOn)
			{
				o.currentPosition = 0;
			}

			$('ul', o.container).css('top', o.currentPosition+'px');
		}
			
		
		setTimeout(animate, o.delay);	
	}
 


	return this.each(function(i)
	{	
		var o = $.extend({}, options);
		
		if(o.visibleBoxes >= $('li', this).length)
		{
			return this;
		}
		
		o.container = this;

		$('ul', this).css('top', 0);

		$(o.container).mouseover(function()	{	o.isRunning = false;	});
		$(o.container).mouseout(function()	{	o.isRunning = true; 	});

		$('ul li', this).each(function()
		{
			$(this).parent().append('<li>' + $(this).html() + '</li>');
		});

		o.boxHeight = $('ul', this).height();

		o.rewindOn = -1 * (o.boxHeight / 2);
		o.currentPosition = parseInt( $('ul', this).css('top') );

		sliders.push(o);

		if(i+1==last) 
		{
            animate();
        }
		
		return this;
	});
};


