(function($){
 $.fn.turbsSlider = function(options) {

	var defaults = {
	direction	: 'right',
	oncomplete	: function(childrenLength){},
	speed		: 5000,
	currentNode : 1
	};
	var options = $.extend(defaults, options);
	
	return this.each(function() {
			
		var childWidth 		= $( 'img', this ).outerWidth();
		var children 		= $( this ).children();
		var childrenLength	= children.length;
		var currentChild 	= 0;
		var scroller		= $(this);
		
		$(this).css({
			
			'position':'absolute',
			'margin-left':0,
			'width': childrenLength*childWidth
			
		});
		$('div',this).css({
			
			'float':'left'
			
		})
		
		
		var scrollOver = function(){
		var children 		= $( scroller ).children();

			oncompleteChild = options.currentNode;
			currentChild++;options.currentNode++;
			if( options.currentNode == childrenLength ) options.currentNode = 0;
			if( currentChild == childrenLength ){
			
				$(children[childrenLength-1]).prependTo( $(scroller) );
				$(scroller).stop(true,true).css('margin-left',0);
				currentChild = 1;
				
				$(scroller).animate({
					marginLeft : childWidth*currentChild*-1
				},500,options.oncomplete(oncompleteChild))
				
			}else{
			
				$(scroller).animate({
					marginLeft : childWidth*currentChild*-1
				},500,options.oncomplete(oncompleteChild))

			
			}
		}
		
		var startScroll = setInterval(scrollOver,options.speed);
		
	
	})
 }
})(jQuery);
