// JavaScript Document

//colocar a imagem seguida da url. Ex.
//BannerRotativo('img1.png|url1.html, img2.png|url1.htm2');

var img_links= new Array();
var imgs= new Array();
var links= new Array();
var contador=0;

function BannerRotativo(pasta,imagens_urls, tipo_imgs, id_img, id_a_link,tempo_troca){

	var conteudo=imagens_urls.split(', ');
	
	tamanho_conteudo=conteudo.length;
	
	cont=0;
	
	while(cont<tamanho_conteudo){
		
		img_links[cont]=conteudo[cont];
		
		pos_tipo_img=img_links[cont].indexOf(tipo_imgs);
		
		pos_tipo_img=pos_tipo_img+tipo_imgs.length;
		
		
		imgs[cont]=pasta+"/"+img_links[cont].substr(0,pos_tipo_img);
		
		links[cont]=img_links[cont].substr(pos_tipo_img+1);
		
		cont++;
	}
	
	ExibeBanerRotativo(id_img, id_a_link,tempo_troca);
	
	var funcao= function(){ExibeBanerRotativo(id_img, id_a_link, tempo_troca)};
	
	window.setInterval(funcao,tempo_troca*1000);
	

}


function ExibeBanerRotativo(id_img_, id_a_link_, tempo_troca_){
	
	window.cor=0;
	document.getElementById(id_img_).style.filter="alpha(opacity=0)";
	document.getElementById(id_img_).style.opacity=0;
	
	EfeitoBanner(tempo_troca_, id_img_);
		
	
	document.getElementById(id_img_).src=imgs[contador];
	
	
	document.getElementById(id_a_link_).href=links[contador];
	
	contador++;
	
	maximo=imgs.length;
	
	if(contador==maximo){
		contador=0;
	}
	
}

cor=0;
function EfeitoBanner(tempo,id_img){
	
	tempo=tempo-(tempo*0.8);
	
	document.getElementById(id_img).style.filter="alpha(opacity="+window.cor+")";
	
	document.getElementById(id_img).style.opacity=window.cor*0.01;
	
	funcao2= function(){refresh(tempo, id_img)};
	
	timeout_state=setTimeout( funcao2, 1000*0.02);
	if(window.cor<100){
		window.cor=window.cor+1;
	}
}

function refresh(tempo, id_img)
{	
	EfeitoBanner(tempo, id_img);	
}
