/* Correção para bug do Internet Explorer 
   Ele não interpreta a pseudo-classe HOVER para elementos div, tendo
   que ser obrigado via javascript */
   
startList = function() {
	if (document.all&&document.getElementById) {
		elem = document.getElementsByTagName("ul");
		for(j=0;j<elem.length;j++){
			if (elem[j].id.substring(0,3) == "nav"){
				navRoot = document.getElementById(elem[j].id);
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() { this.className+=" over"; menuOver(); }
						node.onmouseout=function() { this.className=this.className.replace(" over", ""); menuOut(); }
					}
				}
			}
		}
	}
}

/* Correção para bug do Internet Explorer 6.0 e anteriores,
   um select (combo) com z-index menor que um div insiste em aparecer
   acima dele.
   Não acontece no Firefox e demais, por isso ele é exclusivo para o IE.
   Essa função é genérica para todos os sub-menus. 
   O truque é posicionar um iframe "burro" abaixo do sub-menu para forçar 
   o select a ficar por baixo. */
function menuOver(){
	elem = document.getElementsByTagName("ul");
	for(i=0;i<elem.length;i++){
		if (elem[i].id.substring(0,3) == "nav"){
			par = document.getElementById(elem[i].id);
			for(j=0;j<par.childNodes.length;j++){
				child = par.childNodes[j];
				if (child.className.indexOf("over") != -1){
					
					var numeroitens;
					for(k=0;k<child.childNodes.length;k++) {
						subitens = child.childNodes[k];
						if(subitens.nodeName == "UL"){
							// Recupera número de itens do sub-menu para cálculo da altura
							numeroitens = parseInt(subitens.childNodes.length);
						}
					}	

					// Posiciona iframe
					var IfrRef = document.getElementById('DivMestra');

					IfrRef.style.width = 210;
					IfrRef.style.height = numeroitens * 18;
					IfrRef.style.top = parseInt(par.style.top)+22;
					IfrRef.style.left = par.style.left;
					IfrRef.style.display = "block";		
					
					// Posiciona box p/ sombra
					var boxS = document.getElementById("boxSombra");

					boxS.style.width = IfrRef.style.width;
					boxS.style.height = IfrRef.style.height;
					boxS.style.top = parseInt(IfrRef.style.top)+4;
					boxS.style.left = parseInt(IfrRef.style.left)+4;
					boxS.style.display = "block";		
				}
			}
		}
	}
}

/* Oculta o iframe no evento onmouseout 
   Complemento da correção acima (Ie) */
function menuOut(){
	var IfrRef = document.getElementById('DivMestra');
	IfrRef.style.display = "none";	
	var boxS = document.getElementById('boxSombra');
	boxS.style.display = "none";	
}

window.onload=startList;

function habilitaMenu() { 
  var i,p,v,obj,args=habilitaMenu.arguments;
  for (i=0; i<(args.length-2); i+=3) 
	  if ((obj=MM_findObj(args[i]))!=null) { 
	  	 v=args[i+2];
	     if (obj.style) { 
		 	obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		 }
		 obj.visibility=v; 
		 
		 obj = obj=MM_findObj(args[i]);
		 var IfrRef = document.getElementById('DivMestra');
		 if (obj.style.visibility == 'visible'){
			IfrRef.style.width = obj.offsetWidth;
			IfrRef.style.height = obj.offsetHeight;
			IfrRef.style.top = obj.style.top;
			IfrRef.style.left = obj.style.left;
			IfrRef.style.zIndex = obj.style.zIndex - 1;
			IfrRef.style.display = "block";
		 }else{
			IfrRef.style.display = "none";
		 }		 
	  }
}  

/* Função que troca todas as strings [CSPACE] por 70 caracteres de espaço
   Recurso utilizado para separar as frases do Marquee em blocos */
function blocoMarquee(mensagem){
	var espacos = "";
	for (i=0;i<70;i++) espacos += "&nbsp;";
	
	while (mensagem.indexOf("[CSPACE]") != -1)
		mensagem = mensagem.replace("[CSPACE]",espacos);
		
	return mensagem;
}

function irPara(){
	x = document.getElementById("cirpara");
	if (x.value != "null"){
		window.frames["conteudo"].location.href = x.value;
		window.frames["conteudo"].frames.focus();
	}else{
		x.selectedIndex = 0;
	}
}
		
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
