window.onload = function(){
	externalLinks();
	randomPrevisao();
	randomNoticias();
	randomFamosos();
	randomEventos();
	
	externalLinks();
	
	if (typeof(SWFObject) != 'undefined'){
		//Carrega o banner do topo do site
		if(document.getElementById('banner') != null){
			//<![CDATA[
				if(bannerAtivo != ""){ 
					bn = "f/banner-topo/" + bannerAtivo;
				} else {
					bn = "f/f/banner-topo";
				}
				var so = new SWFObject(URL + bn + ".swf", "banner", "100%", "130px", "8", "");
				so.addParam("quality", "high");
				so.write("banner");
			//]]>
		}
	
	//Carrega os players das músicas do Top 10 da área interna
	//<![CDATA[
		if((top10[1] != "") && (document.getElementById('top_1') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_1", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=1&nome=" + top10[1].substring(0, (top10[1].length - 4)));
			so.write("top_1");
		}
		
		if((top10[2] != "") && (document.getElementById('top_2') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_2", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=2&nome=" + top10[2].substring(0, (top10[2].length - 4)));
			so.write("top_2");
		}
		
		if((top10[3] != "") && (document.getElementById('top_3') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_3", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=3&nome=" + top10[3].substring(0, (top10[3].length - 4)));
			so.write("top_3");
		}
		
		if((top10[4] != "") && (document.getElementById('top_4') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_4", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=4&nome=" + top10[4].substring(0, (top10[4].length - 4)));
			so.write("top_4");
		}
		
		if((top10[5] != "") && (document.getElementById('top_5') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_5", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=5&nome=" + top10[5].substring(0, (top10[5].length - 4)));
			so.write("top_5");
		}
		
		if((top10[6] != "") && (document.getElementById('top_6') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_6", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=6&nome=" + top10[6].substring(0, (top10[6].length - 4)));
			so.write("top_6");
		}
		
		if((top10[7] != "") && (document.getElementById('top_7') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_7", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=7&nome=" + top10[7].substring(0, (top10[7].length - 4)));
			so.write("top_7");
		}
		
		if((top10[8] != "") && (document.getElementById('top_8') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_8", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=8&nome=" + top10[8].substring(0, (top10[8].length - 4)));
			so.write("top_8");
		}
		
		if((top10[9] != "") && (document.getElementById('top_9') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_9", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=9&nome=" + top10[9].substring(0, (top10[9].length - 4)));
			so.write("top_9");
		}
		
		if((top10[10] != "") && (document.getElementById('top_10') != null)){
			var so = new SWFObject(URL + "f/f/botao.swf", "top_10", "35px", "35px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=10&nome=" + top10[10].substring(0, (top10[10].length - 4)));
			so.write("top_10");
		}
	//]]>
	
	//Carrega os players das músicas do Top 10 da capa
	//<![CDATA[
		if((top10[1] != "") && (document.getElementById('ctop_1') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_1", "16px", "17px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=1&nome=" + top10[1].substring(0, (top10[1].length - 4)));
			so.write("ctop_1");
		}
		
		if((top10[2] != "") && (document.getElementById('ctop_2') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_2", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=2&nome=" + top10[2].substring(0, (top10[2].length - 4)));
			so.write("ctop_2");
		}
		
		if((top10[3] != "") && (document.getElementById('ctop_3') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_3", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=3&nome=" + top10[3].substring(0, (top10[3].length - 4)));
			so.write("ctop_3");
		}
		
		if((top10[4] != "") && (document.getElementById('ctop_4') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_4", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=4&nome=" + top10[4].substring(0, (top10[4].length - 4)));
			so.write("ctop_4");
		}
		
		if((top10[5] != "") && (document.getElementById('ctop_5') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_5", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=5&nome=" + top10[5].substring(0, (top10[5].length - 4)));
			so.write("ctop_5");
		}
		
		if((top10[6] != "") && (document.getElementById('ctop_6') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_6", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=6&nome=" + top10[6].substring(0, (top10[6].length - 4)));
			so.write("ctop_6");
		}
		
		if((top10[7] != "") && (document.getElementById('ctop_7') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_7", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=7&nome=" + top10[7].substring(0, (top10[7].length - 4)));
			so.write("ctop_7");
		}
		
		if((top10[8] != "") && (document.getElementById('ctop_8') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_8", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=8&nome=" + top10[8].substring(0, (top10[8].length - 4)));
			so.write("ctop_8");
		}
		
		if((top10[9] != "") && (document.getElementById('ctop_9') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_9", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=9&nome=" + top10[9].substring(0, (top10[9].length - 4)));
			so.write("ctop_9");
		}
		
		if((top10[10] != "") && (document.getElementById('ctop_10') != null)){
			var so = new SWFObject(URL + "f/f/pequeno.swf", "ctop_10", "16px", "16px", "7", "");
			so.addParam("quality", "high");
			so.addParam("FlashVars", "link="+ URL + "&posicao=10&nome=" + top10[10].substring(0, (top10[10].length - 4)));
			so.write("ctop_10");
		}
	//]]>
	}
}

var pa = rand(21);
function rand(n){
  return (Math.floor(Math.random() * n + 1 ));
}

function randomPrevisao(){
	
	if((document.getElementById('previsao-tempo') != null) && (previsao[pa] != null)){	
		var pv_cidade = document.getElementById('pv_cidade');
		var pv_data = document.getElementById('pv_data');
		var pv_img = document.getElementById('pv_img');
		var pv = document.getElementById('pv');
		var pv_max = document.getElementById('pv_max');
		var pv_min = document.getElementById('pv_min');
		
		pv_cidade.innerHTML = previsao[pa].nome;
		pv_data.innerHTML = previsao[pa].data;
		pv_img.src = URL + 'f/i/tempo/' + previsao[pa].img + '.gif';
		pv.innerHTML = previsao[pa].descricao;
		pv_max.innerHTML = previsao[pa].tmax;
		pv_min.innerHTML = previsao[pa].tmin;
	}
	
	if(previsao[pa] == null){
		pa = 0;
	} else {
		pa++;
	}
	
	setTimeout('randomPrevisao()', 10000);
}


var nt = 0;
function randomNoticias(){
	if(document.getElementById('nt_desc') != null){
				
		
		var js_img = document.getElementById('js_img');
		var nt_link = document.getElementById('nt_link'); 
		var nt_desc = document.getElementById('nt_desc');
		
		nt_link.innerHTML = noticias[nt].titulo;
		nt_link.href = URL + 'noticias-da-stylo/' + noticias[nt].url;
		nt_link.title = 'Veja mais detalhes da notícia ' + noticias[nt].titulo;
		nt_desc.innerHTML = noticias[nt].data + ' - ' + noticias[nt].descricao;
		if(noticias[nt].img != ''){
			js_img.innerHTML = "<p><img src='" + URL + "f/noticias-stylo/" + noticias[nt].cod + "-" + noticias[nt].codimg + "-P." + noticias[nt].img + "' alt='" + noticias[nt].titulo + "'></p>";
		} else {
			js_img.innerHTML = '';
		}
		
		
		setTimeout('randomNoticias()', 10000);
		
		if(nt == (noticias.length - 1)){
			nt = 0;
		} else {
			nt++;
		}
	}
}


var fm = 0;
function randomFamosos(){
	if(document.getElementById('fm_desc') != null){
				
		
		var js_fmimg = document.getElementById('js_fmimg');
		var nt_link = document.getElementById('fm_link'); 
		var nt_desc = document.getElementById('fm_desc');
		
		nt_link.innerHTML = famosos[fm].titulo;
		nt_link.href = URL + 'o-mundo-dos-famosos/' + famosos[fm].url;
		nt_link.title = 'Veja mais detalhes da notícia ' + famosos[fm].titulo;
		nt_desc.innerHTML = famosos[fm].data + ' - ' + famosos[fm].descricao;
		if(famosos[fm].img != ''){
			js_fmimg.innerHTML = "<p><img src='" + URL + "f/mais-quentes/" + famosos[fm].cod + "-" + famosos[fm].codimg + "-P." + famosos[fm].img + "' alt='" + famosos[fm].titulo + "'></p>";
		} else {
			js_fmimg.innerHTML = '';
		}
		
		setTimeout('randomFamosos()', 10000);
		
		if(fm == (famosos.length - 1)){
			fm = 0;
		} else {
			fm++;
		}
	}
}


var ev = 0;
function randomEventos(){
	if(document.getElementById('ev_agendado') != null){
		var eveA = document.getElementById('ev_agendado');
		var eveB = document.getElementById('ev_out_agendado');
		
		//Cria um Array com as posições dos eventos modificados
		var qt = eventos.length;
		var posicao = Array();
		var psAt = ev;
		for(i=0; i < eventos.length; i++){
			posicao[i] = psAt;
			psAt++;
			
			if(psAt == qt){
				psAt = 0;
			}
		}
		
		ev++;
		if(ev == qt){
			ev = 0;
		}		
		
		//Monta a estrutura a ser exibida
		var evDestaques = '';
		var outrosEventos = '' ;
		for(i=0; i < qt; i++){
			if(i <= 1){
				evDestaques += "<h3><a href=\"" + LNK + "agenda-de-eventos/" + eventos[posicao[i]].url + "\">" + eventos[posicao[i]].titulo + "</a></h3>\n";
				evDestaques += "<p>" + eventos[posicao[i]].descricao + "</p>\n";
			} else {
				eveA.innerHTML = evDestaques;
			}
			
			if(i >= 2){
				outrosEventos += "<li>" + eventos[posicao[i]].data + " - " + "<a href=\"" + LNK + "agenda-de-eventos/" + eventos[posicao[i]].url + "\">" + eventos[posicao[i]].titulo + "</a></li>\n";
			}
		}
		
		if(outrosEventos != ''){
			eveB.innerHTML = outrosEventos;
		}
		
		if(qt >= 3)
			setTimeout("randomEventos()", 8000);
	}
}

