(function($) {

$.bgSlider = {
	active : []
};
$.fn.bgSlider = function(settings)
{
	settings = $.extend({}, $.fn.bgSlider.defaults, settings);

	var rf = function() { return false; };
	
	return this.each(
		function()
		{
			
			var slides = $(this).children('li').size();

			// Do the operation
			do_animation($(this));
		
		
		
		
			function do_animation(parent)
			{

				// Use first li if no active, second if there's an active
				var active = parent.children('li.active');
				
				//alert(active.length); 
				
				
				if (active.length == 0)
				{
					var active = parent.children('li:first-child');					
					active.addClass('active');
				}

				var qued = parent.children('li:nth-child(2)');
				//qued.addClass('next');
				


				// Do the animations.
				window.setTimeout(function(){
				    
				    // First, Drop down active
				    active.animate({
				    	top: 304
				    }, 1000, function(){
				    
				    	// animate next one up.
				    	qued.animate({
				    		top: 0
				    	}, 1000, function(){
				    	
							// Append active slide to end
							var appending = active.html();
							
							parent.append('<li>' + appending + '</li>');
							active.remove();
							do_animation(parent);
							
							//qued.removeClass('next');
				    	});
				    
				    });
				}, settings.autoInterval);
				




			}
			
			
			function do_slider(el)
			{
				var caption = el.children('div.caption');
				
				caption.animate({
					left: 0
				}, 1000);			
			}
			
			function closeout(el, parent)
			{
				
				var caption = el.children('div.caption');
				
				caption.animate({
					left: '-270px'
				}, 1000);

				window.setTimeout(function(){
				    do_animation(parent);
				}, 1000);	
			}
		
			//alert(settings.autoInterval);
		}
	);		
};

$.fn.bgSlider.defaults = {
	autoInterval: 1000,
	fadeDuration: 600


};

})(jQuery);
