var guardaDiv = 'vazia';

function mostradiv(nomeDiv){
	document.getElementById(guardaDiv).style.display = "none";
	document.getElementById(nomeDiv).style.display = "block";
	if(guardaDiv == nomeDiv){
		document.getElementById(nomeDiv).style.display = "none";
		guardaDiv = 'vazia';
	}
	else{
		guardaDiv = nomeDiv;
	}
}

function escondediv(nomeDiv){
	document.getElementById(nomeDiv).style.display = "none";
}


//*MENU */

primeiroNivel = location.href.split("/");
primeiroNivel = primeiroNivel[3]

segundoNivel = location.href.split("/");
segundoNivel = segundoNivel[4]

terceiroNivel = location.href.split("/");
terceiroNivel = terceiroNivel[5]

quartoNivel = location.href.split("/");
quartoNivel = quartoNivel[6]



function mostraMenu(idPrincipal){
	try{
		divs = document.getElementById(idPrincipal).getElementsByTagName('div');
		for(i = 0; i < divs.length; i ++){
			if(divs[i].id == primeiroNivel){
				//divs[i].className = "block";
				
			}
		}
		
		divs2 = document.getElementById(idPrincipal).getElementsByTagName('ul');
		for(i = 0; i < divs2.length; i ++){
			if(divs2[i].id == segundoNivel){
				divs2[i].className = "block";
			}
		}
		
		divs3 = document.getElementById(idPrincipal).getElementsByTagName('div');
		for(i = 0; i < divs3.length; i ++){
			if(divs3[i].id == segundoNivel){
				divs3[i].className = "block";
				divs[1].className = "none";
				divs[11].className = "none";
				divs[13].className = "none";
			}
		}
		
		divs4 = document.getElementById(idPrincipal).getElementsByTagName('ul');
		for(i = 0; i < divs4.length; i ++){
			if(divs4[i].id == terceiroNivel){
				divs4[i].className = "block";
			}
		}
		
		divs5 = document.getElementById(idPrincipal).getElementsByTagName('ul');
		for(i = 0; i < divs5.length; i ++){
			if(divs5[i].id == quartoNivel){
				divs5[i].className = "block";
			}
		}
		
		linksTopo = document.getElementById('inferior').getElementsByTagName('a');
		for(i = 0; i < linksTopo.length; i ++){
			if(linksTopo [i].id == primeiroNivel){
				if(linksTopo [i].id == "pesquisadores_estudantes"){
					linksTopo[i].className = "ultimomarcado"
				}
				else
					linksTopo[i].className = "marcado";
			}
		}
		
		linksMenu = document.getElementById(idPrincipal).getElementsByTagName('a');
		for(i = 0; i < linksMenu.length; i ++){
			if(location.href.indexOf(linksMenu[i].href) > -1){
				//alert(location.href.indexOf(linksMenu[i].href))
				linksMenu[i].className = "marcado";
				itemLateralAtual = linksMenu[i];
			}
		}
		
		if (itemLateralAtual.parentNode.parentNode.parentNode.nodeName == 'LI')
			itemLateralAtual.parentNode.parentNode.parentNode.getElementsByTagName('a')[0].className = 'marcado';
		
		if (itemLateralAtual.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == 'LI')
			itemLateralAtual.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('a')[0].className = 'marcado';
	}
	catch(e){}
}

function trocarImagem(img){
	imagem = document.getElementById(img);
	imagem.src = imagem.src.substring(0, imagem.src.lastIndexOf('.')) + '_over.gif';
}

function voltarImagem(img){
	imagem = document.getElementById(img);
	imagem.src = imagem.src.substring(0, imagem.src.lastIndexOf('_over')) + '.gif';
}

/* TIRA A BORDA DOS FLASHS
Copyright 2006 Adobe Systems, Inc. All rights reserved.
Versão compacta, alterada por Renato Herculano
	- src, width e height são obrigatórios
	- os demais parametros são opcionais
*/
function flash(src, width, height, id, flashVars, wmode, menu, scale){
	var ret = GetArgumentos(src, width, height, id, flashVars, wmode, menu, scale);
	var str = '<object ';
	for (var i in ret.objAttrs)
		str += i + '="' + ret.objAttrs[i] + '" ';
		str += '>';
	for (var i in ret.params)
		str += '<param name="' + i + '" value="' + ret.params[i] + '" /> ';
		str += '</object>';
	document.write(str);
}


function GetArgumentos(src, w, h, id, flashVars, wmode, menu, scale){
	var ret = new Object();
	ret.params = new Object();
	ret.objAttrs = new Object();

	ret.objAttrs['data'] = ret.params["movie"] = src;
	ret.objAttrs['width'] = w;
	ret.objAttrs['height'] = h;
	ret.params['quality'] = 'high';
	ret.objAttrs['type'] = 'application/x-shockwave-flash';
	ret.params['menu'] = 'false';
	
	if(id) ret.objAttrs['id'] = id;
	
	if(flashVars) ret.params['flashVars'] = flashVars;
	
	ret.params['wmode'] = (wmode)? wmode : 'transparent';
	ret.params['scale'] = (scale)? scale : 'exactfit';
	ret.params['menu'] = (menu)? menu : 'false';
	
	return ret;
}

//abrirPopup(): abre uma popup
//	- url: caminho da janela a abrir
//	- width: width da popup
//	- height: height da popup
//  - scroll(opcional): se a pop-up terá scroll
function abrirPopup(url, width, height,scroll){
	var parametro = 'width=' + width + ', height=' + height;
	if(scroll)
		parametro += ', scrollbars =' + scroll;	
	window.open(url, '', parametro);
}	

/* funcoes para linkar e sinalizar combos */
function envieTopo(){
	if (document.title.indexOf('#') > - 1){
		document.envieAmigo.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1, document.title.indexOf('#'));
	}
	else{			
		document.envieAmigo.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1);
		
	}	
	document.envieAmigo.url.value = location.href;
	document.envieAmigo.submit();
}

//Script para adicionar o site no favoritos do brownser
function favoritos(){	
	url="http://www.energest.com.br"
	title="Enerpeixe - EDP no Brasil"	
	if (document.all)	
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

//mostrarConteudo(): torna um conteudo visível
//	- id: id do conteudo a monstrar
function mostrarConteudo(id){			
	document.getElementById(id).style.display = 'block';
}

//esconderConteudo(): esconde um conteudo
//	- id: id do conteudo a esconder
function esconderConteudo(id){
	document.getElementById(id).style.display = 'none';
}

//trocarConteudo(): troca um conteudo visível por outro
//	-id: id do conteudo a trocar
var visivel = '';
function trocarConteudo(id){
	if(visivel.length > 0) 
		esconderConteudo(visivel);
	mostrarConteudo(id);
	visivel = id;
}
//Redimensiona a div
function exibirConteudo(idConteudo){
	var d = document.getElementById(idConteudo);
	if(d.style.display != 'block'){
		d.style.display = 'block';
		
		if(d.hF)
			d.style.height = d.hF + 'px';
		
		d.hF = d.offsetHeight;
		d.style.height = '1px';
		
		var c = d.innerHTML;
		d.innerHTML = '';					
		expandir(idConteudo, d.hF, escape(c));		
	}			
}

function expandir(id, hF, conteudo){
	var d = document.getElementById(id);
	var h = parseInt(d.style.height);
	if(h < hF){
		d.style.height = (h + 15) + 'px';
		setTimeout('expandir("'+id+'",'+hF+', "'+ conteudo+'")', 1);

	}else{
		d.innerHTML = unescape(conteudo);
	}
}

function ocultarConteudo(idConteudo){
	var d = document.getElementById(idConteudo);
	
	d.style.height = d.hF + 'px';
	
	var c = d.innerHTML;
	d.innerHTML = '';
	
	diminuir(idConteudo, escape(c));
}

function diminuir(id, conteudo){
	var d = document.getElementById(id);
	var h = parseInt(d.style.height);
	if(h > 20){
		d.style.height = (h - 20) + 'px';
		setTimeout("diminuir('"+id+"', '"+conteudo+"')", 1);
	}else{
		d.style.display = 'none';
		d.style.height = d.hF + 'px';
		d.innerHTML = unescape(conteudo);		
	}
}

//trocarConteudo(): troca um conteudo visível por outro
//	-id: id do conteudo a trocar
var visivel = '';
function trocarConteudo(id){
	if(visivel.length > 0) 
		esconderConteudo(visivel);
	mostrarConteudo(id);
	visivel = id;
}