(function($){

		var bannerOpts = false;
		var numOfBanners = 0;
		var listIndex = 0;
		var colection = [];

		$.fn.banner_rotativo = function(opts){
				var defaults = {
							time 		: 7000,
							w				:	263,
							h				:	198
				},	
				imglist = $("ul#imglist li");
				opts = $.extend(defaults,opts);
				
				$(".imgbanners").each(function(i){
						var imgCol = new Image();
						imgCol.src = $(this).attr('src');
											
				});

				imglist.each(function(i){
						colection[i] = $(this).html();
						if(bannerOpts) $("#banner_options").append("<div id='img_"+(i+1)+"'>"+(i+1)+"</div>");
						numOfBanners++;
				});
				
				/* Inicia */
				$.init(opts);
				window.setInterval('$.buildBanners();',opts.time);

		}
		$.buildBanners = function(){
				var limit = numOfBanners-1;
				var banner = colection[listIndex];
				$("#banner_rotativo").html(banner).css({"display":"none"}).fadeIn("slow");
				if(bannerOpts) $.bgSelected();	
				listIndex++;
				if(listIndex > limit)listIndex = 0;
		}
		
		$.init = function(opts){
				$("#banner_rotativo").html(colection[listIndex]);
				
				if(bannerOpts){
						var w=50,h=50;
						$("#banner_options").css({
								opacity:.5,
								'backgroundColor':'#9999FF',
								'position':'absolute',
								'text-align':'center',
								zIndex:1000,
								'width':w+'px',
								'height':h+'px',
								left:opts.w - (w-10),
								'margin-left':'0px'
						});
						$.bgSelected();
				}
				
				listIndex++;
		};

		$.bgSelected = function(){
				var i;
				/* Limpa a cor do fundo */
				for(i=1 ; i<=colection.length ; i++){
					$("#img_"+i).css({
							'backgroundColor':''
					});
				}
				
				
				$("#img_"+(listIndex+1)).css({
						'backgroundColor':'#FF0000'
				});
		};



})(jQuery);
