/**
 * @author wouter
 */
(function($){  
  $.fn.daconScroller = function(options) {  
   
   	var defaults = {  
    	holder: $(this),  
    	speed: 4000,  
    	default_margin: 5 
   	};
	
	var options = $.extend(defaults, options); 

	var holder 			= options.holder;
	var speed			= options.speed; 
	var default_margin	= options.default_margin;
	var theWidth 		= 0;
			
	/* get the total width of the scroller */
	$("#scroller_holder").children().each(function(){
		theWidth += ($(this).outerWidth((default_margin*2)));
	});
	
	/* set the width */	 	
	$("#scroller_holder").css('width',theWidth+'px');
	
	/* scroller function */
	function scroll(){
		/* find the first element */
		first_element = holder.children(":first");
				
		/* get position of next element */
		position = first_element.outerWidth((default_margin*2));
		
		/* scroll to next element */
		holder.animate({marginLeft:-(position)}, speed, 'linear', function(){
			/* reset the margin */
			holder.css({marginLeft:default_margin});
			
			/* remove the first element */
			first_element.remove().appendTo(holder);		
			
			/* do it all again */
			scroll();					
		});	
	};	
	
	/* holder.mouseover(function(){ return true; }); */
	holder.click(function(){ return true; });
	
	/* start the scroller */
	$(document).ready(function () { scroll(); });
  };  
})(jQuery); 