//instancia das abas exibidas
var aba1=false;
var aba2=true;

$(document).ready(function(){
	
	
	
	
	
	
	$(".spaceBolsa").hide();
	mostraBanner(1);
	
	if (parseFloat($('[data-banner]').size()) != 1) {
	var intervalo = window.setInterval(rolaBanner, 5000);
	}	
	
	$('.setaBannerVolta').click(function(e) {
		e.preventDefault();
		if (!$(this).is('.disabled')) {
			mostraBanner(parseFloat($('[data-banner]:visible').attr('data-banner'))-1);
		}
		clearInterval(intervalo);
	});
	
	$('.setaBannerVai').click(function(e) {
		e.preventDefault();
		if (!$(this).is('.disabled')) {
			mostraBanner(parseFloat($('[data-banner]:visible').attr('data-banner'))+1);
		}
		clearInterval(intervalo);
	});
	
	
//	var intervaloMoedas = window.setInterval(mudaValores, 15000);
	
	$(".aba").click(function(){
		if($(this).attr("id")=="aba1"){
				
			$(".spaceBolsa").hide();
			$(".spaceCotacao").show();
			
			$(".titFundoCot2").hide();
			$(".titFundoCot").show();
			
			document.getElementById('aba2').className = 'titBolsa replace floatLeft aba';
			document.getElementById('aba1').className = 'titCambio replace floatLeft aba';
			
			
			
			aba1=true;
			aba2=false;
		}
		if($(this).attr("id")=="aba2"){
			$(".spaceCotacao").hide();
			$(".spaceBolsa").show();
			
			$(".titFundoCot").hide();
			$(".titFundoCot2").show();
			
			document.getElementById('aba2').className = 'titBolsa2 replace floatLeft aba';
			document.getElementById('aba1').className = 'titCambio2 replace floatLeft aba';

			
			aba2=true;
			aba1=false;
		}
		
	});
	
});
function mudaValores() {
	//$('.valores').fadeToggle(0); //antes era com toggle mas tivemos que mudar o jQuery para versao 1.4.2 e ela nao tem fadeToggle
	
	//mete uma gambi aqui
	$('.valores').each(function() {
		if ($(this).is(':visible')) {
			$(this).hide();
		} else {
			$(this).show();
		}
	});
	
}
function rolaBanner() {
	
	if ($('.setaBannerVai').is('.disabled')) {
		mostraBanner(1);
	} else {
		mostraBanner(parseFloat($('[data-banner]:visible').attr('data-banner'))+1);
	}
	
}

function mostraBanner(index) {
	
	$('[data-banner]:visible').fadeOut(200);
	$('[data-banner="'+index+'"]').fadeIn(200);
	
	if ($('[data-banner]:first').is('[data-banner="'+index+'"]')) {
		$('.setaBannerVolta').addClass('disabled');
	} else {
		$('.setaBannerVolta').removeClass('disabled');
	}
	
	if ($('[data-banner]:last').is('[data-banner="'+index+'"]')) {
		$('.setaBannerVai').addClass('disabled');
	} else {
		$('.setaBannerVai').removeClass('disabled');
	}
	
}
