// JavaScript Document
//INICIO FUNCAO TV FLASH
var tvFlash = function (){
	this.numImages = $("#destaques img").size() //conta a quantidade de imagens
	this.numImages = (this.numImages)-1;
	this.numBotao =  $("#botoes a").size() //conta a quantidade de botoes
	this.currentImage = 0;
	this.tTransicao = 500
	var intervalo;
	
	this.startInterval = function (){
		intervalo = setTimeout('changeImage()',8000); 
	}
	
	this.stopInterval = function(){
		clearTimeout(intervalo);
	}
	
	//função do slide show
	 this.changeImage = function(imgNova){
		stopInterval();
		$("#destaque"+currentImage).css('display','none');
		$("#botao" + currentImage).removeClass("ativo");
		
		currentImage = (currentImage >= numImages)?0:Math.round(currentImage)+1	
		
		$("#destaque"+currentImage).css('display','block');
		$("#botao" + currentImage).addClass("ativo");
		startInterval();

	}
	
	//função para parar o slide show ao passar o mouse
	$("#destaques").hover(
		function () {
			stopInterval();
		}, 
		function () {
			startInterval();
		}
	);	
	//funcao botoes
	$("#botoes a").click(function(){	
		var n = (this.id).replace("botao","");
		changeImage(n);			
	});
	
	//função próximo
	$("#proximo").click(function(){	
		changeImage();				
	});
	
	//função anterior
	$("#anterior").click(function(){
		stopInterval();
		$("#destaque"+currentImage).css('display','none');
		$("#botao" + currentImage).removeClass("ativo");

		if(currentImage == 0){
			currentImage = numImages;
		}else{
			currentImage = (currentImage)-1;
		}
		
		$("#destaque"+currentImage).css('display','block');
		$("#botao" + currentImage).addClass("ativo");
		startInterval();		
	});	
	startInterval();
}

function chamadaRandomica(){
	var divs = document.getElementById("chamada-randomica").getElementsByTagName('div');
	var aleat = Math.floor(divs.length * Math.random());
	divs[aleat].style.display = "block";
}
