/**
 * @author mthornton
 */
(function($) {

$.fn.slidingImageBar = function(options) {
	
	return this.each(function() {	
	  
		var
		  $this = $(this), 
		    defaults = {
		  	speed: 400, 
		  	delay: 3000,
			direction: 'left',
		  	list_item_width: $this.children('li').outerWidth() 
	     },
	     
		  settings = $.extend({}, defaults, options); 
		 $this.data('over', false);
	  
	$this.hover( function(){
		$this.data('over', true);
	},
	function(){
		$this.data('over', false);
	});
	  
	  if (settings.direction == 'left') {
	  	setInterval(function(){
	  		if ($this.data('over') == false) {
	  			$this.children('li:first').animate({
	  				marginLeft: '-' + settings.list_item_width,
	  				opacity: 'hide'
	  			}, settings.speed, function(){
	  				$this.children('li:first').appendTo($this).css('marginLeft', 0).fadeIn(300);
	  			}); // end animate
					}
			}, settings.delay); // end setInterval
		}
		else {
	  		setInterval(function(){
		  		if ($this.data('over') == false) {
		  			$this.children('li:first').animate({
						marginLeft: '+' + settings.list_item_width
					}, settings.speed, function(){
						$this.children('li:last').hide().prependTo($this).fadeIn(300);
						$this.children('li:eq(1)').css('marginLeft',0);
					});	// end animate
				}
			}, settings.delay); // end setInterval			
		}
	});
}

})(jQuery);