(function($) {
	$.fn.featureScroller = function(options) {
		//merge options with defaults
		var settings = $.extend({}, $.fn.featureScroller.defaults, options);
		
		//loop through each matched container
		return this.each(function(){
			$this = $(this);
			// build element specific options
			var s = $.meta ? $.extend({}, settings, $this.data()) : settings;
			
			//set up container styles
			//$this.css({position:"absolute", overflow:"hidden"});
			
			//get the elts to scroll
			var elts=$this.find(settings.selector);
			if(elts.length>1){
				//store the current position and object count in the container
				$this.data('count', elts.length);
				$this.data('current', 0);
				$this.data('settings', s);
				
				//hide all but the first element- these are shown and hidden before and after animation respectively
				elts.not(':first').hide();
				
				//set up timing. Store in the container in case we need it
				var id=$this.attr('id');
				$this.data('interval', setInterval(function(){$.fn.featureScroller.scroll(id)}, s.interval));
			}
		});
	};
	$.fn.featureScroller.scroll= function(container_id){
		var container=$('#'+container_id)
		var settings =container.data('settings');
		var next= container.data('current')+1;
		if(next==container.data('count')){
			next=0;
		}
		var elts=container.find(settings.selector);
		$(elts[container.data('current')]).css({position:'absolute'}).animate(settings.outEffect, {duration: settings.duration, complete: function(){$(this).hide();}});
		$(elts[next]).css({position:'absolute'}).show().animate(settings.inEffect, {duration: settings.duration});
		container.data('current', next);
	}
	
	$.fn.featureScroller.defaults = {
		selector:  '> div',
		interval:  5000,
		outEffect: {opacity:0},
		inEffect: {opacity:1},
		duration: 600
	}
	/*
	var offset= $(elts[0]).offset();
	elts.each(function(){
		//set up element css
		$(this).css({position:'absolute', top: offset.top});
	});
	*/
})(jQuery);