/**
* Scripts criado por Paulo
* Data: 27/12/2007 - 17:42:00
**/

var a_banner_atual = 0;
var a_banner_total = 0;
var o_timer;
var i_tempo = 5000;

function MudarBanner(banner, banner_total) {
	banner_total = parseInt(banner_total);
	
	if (banner_total > 0) {
		var x;
		
		for (x = 1; x <= banner_total; x++) {
			document.getElementById('banner_destaque_0' + x).style.display = "none";
			document.getElementById('banner_pagina_' + x).className = "";
		}
	
	
		obj = document.getElementById('banner_destaque_0'+banner);
		objP = document.getElementById('banner_pagina_'+banner);
		
		obj.style.display = "block";
		
		objP.className = "active";
		
		//finaliza o timer
		FinalizaBannerAuto();
		
		//atualiza o banner atual
		a_banner_atual = banner;
		
		//inicia o banner auto
		IniciaBannerAuto();
	}
} 

function IniciaBannerAuto() {
	o_timer = window.setTimeout("MudarBannerAuto()",i_tempo);
} 

function FinalizaBannerAuto() {
	window.clearTimeout(o_timer);
} 

function MudarBannerAuto() {
	//verifica se o total de banners é maior que o banner atual
	total = parseInt(a_banner_total);
	atual = parseInt(a_banner_atual);
	
	//verifica se o total de banner é maior que 0
	if (total > 0) {
	
		//verifica qual a posiçao do banner atual
		if (atual < total) {
			atual = atual + 1;			
		} else {
			atual = 1;
		}
		
		//atualiza a variável global
		a_banner_atual = atual;
		
		
		//esconde os outros banners
		var x;
		
		if (total > 0) {
			for (x = 1; x <= total; x++) {
				document.getElementById('banner_destaque_0' + x).style.display = "none";
				document.getElementById('banner_pagina_' + x).className = "";
			}
		}
		
		obj  = document.getElementById('banner_destaque_0'+atual);	
		objP = document.getElementById('banner_pagina_'+atual);
		
		obj.style.display = "block";
		objP.className = "active";
		
		IniciaBannerAuto();
	
	}
}
