(function($){
	$.fn.billboard = function(settings){
		var config = {
			advance			: 1,
			auto			: false,
			displayTime		: 6000,
			progressBar		: true,
			speed			: 500
		};
		
		if (settings) $.extend(config,settings);
		return this.each(function(intIndex){
			var clearInt	= null;
			var obj			= $(this);
			var numPanels	= $('li',obj).length;
			var panelWidth	= obj.width();
			var position	= 1;
			
			if(config.progressbar){
				$(obj).append('<div class="progressbar" style="background:#0099CC;bottom:0em;left:0em;position:absolute;z-index:1;"></div>');
				$('.progressbar',obj).width('100%').height(4).css('opacity','.6');
			}
			
			if(config.auto){
				clearInt	= setTimeout(function(){next();},config.displayTime)
				if(config.progressBar) startProgressBar(config.displayTime);
			}
			
			function startProgressBar(barTime){
				barTime = (barTime==null) ? config.displayTime:barTime;
				$('.progressbar',obj).width('100% !important').fadeIn('normal');
				$('.progressbar',obj).animate({'width':'0% !important'},barTime);
			}

			function next(){
				$('ul',obj).fadeOut(config.speed /2,function(){
					leftPosition	= position == $('li',obj).length ? 0 : (panelWidth * position);
					position		= position == $('li',obj).length ? 1 : position + 1;
					$('ul',obj).css('left',-leftPosition).fadeIn(config.speed /2,function(){
						if(config.progressBar)startProgressBar(config.displayTime);
						clearInt	= setTimeout(function(){next();},config.displayTime);
					});
				});
			}//End next()

			function test(){
				alert('test');
			}
			
		});
		
	};

})(jQuery);

$(document).ready(function(){
	$('#billboard').billboard({auto:true,progressbar:true});
});
