var intervalo;
var x = 0;
var total;
$(document).ready(function(){
	total = $('#banners img').size();
	for(var y=1;y<=total;y++){
		$('#botoes').append('<div></div>');
	}
	$('#botoes div:eq('+x+')').addClass('selected');
	$('#botoes div').css({
		cursor:'pointer'
	}).hover(function(){
	},function(){
	}).click(function(){
		if($('#banners img:eq('+$(this).index()+')').is(':hidden')) {
			clearInterval(intervalo);	
			$('#banners img:eq('+x+')').fadeOut();
		$('#botoes div:eq('+x+')').removeClass('selected');
			x = $(this).index();
			$('#banners img:eq('+x+')').fadeIn();
		$('#botoes div:eq('+x+')').addClass('selected');
			banner();
		}
		
	});
	total--;
	$('#banners img:gt(0)').hide();
	banner();
	
	$(window).blur(function(){
		clearInterval(intervalo);
	}).focus(function(){
		clearInterval(intervalo);
		banner();
	})
	
})
function banner(){
	intervalo = setInterval(function(){
		$('#banners img:eq('+x+')').fadeOut();
		$('#botoes div:eq('+x+')').removeClass('selected');
		if(x==total){
			x=0;
		}else{
			x++;
		}
		$('#banners img:eq('+x+')').fadeIn();
		$('#botoes div:eq('+x+')').addClass('selected');
	},3000)
}
