var cor = "";
var highlights;

var cores = new Array();
	cores["laranja"]  = "FF9900";
	cores["vermelho"] = "FF0000";
	cores["verde"]    = "99CC33";
	cores["azul"]     = "0066CC";
	cores["roxo"]     = "660099";
	
function $(id){
	return document.all? document.all[id] : document.getElementById(id);
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
}

var url = self.location.href.replace(/\\/, "/").split("/");
var pg = url[url.length-1];
var pgatual = parseInt(pg.replace(".htm", ""), 10);
var pasta = url[url.length-2];
var idioma = url[url.length-3];

var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ieVer = 0;
var podefscommand = "nao";
var iebug = false;


var pgtotal = [];
	pgtotal["ra"] = 30;
	pgtotal["df"] = 41;


var paginacao = [pasta];


if(pasta=="df")
{
	titulodf = document.title.split("-")
	titulodf.shift();
	titulodf.shift();
	titulodf = titulodf.join("-");
}

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer < 7) iebug = true;
	if(ieVer > 5.5) podefscommand = "sim";
}

if(isNaN(pgatual)) pgatual = 0;

if(podefscommand) document.write('<scr' + 'ipt for="menu_flash" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');

function $(id){
	return document.all? document.all[id] : document.getElementById(id);
}

var tags = { "select":iebug, "applet":true };
var apagou = [];


function vai(x){
	temppg = pgatual + x;
	
	if(temppg<=0 || temppg > pgtotal[pasta]) location = "../ra/index.htm";
	else location = z(temppg) + ".htm";
}

function z(numero){
	return numero<10? ("0"+numero) : numero;
}

function abreMenu(){
	try {
		document.getElementById("div_menu_interna").style.clip = "rect(0 250px 615px 0px)";
		for(tag in tags){
			if(tags[tag]){
				items = document.getElementsByTagName(tag);
				for(x = 0; x < items.length; x++){
					if(items[x].style.visibility==""){
						apagou[tag+"-"+x] = true;
						items[x].style.visibility = "hidden";
					}
				}
			}
		}
	}
	catch(e){}
}

function fechaMenu(){
	try {
		document.getElementById("div_menu_interna").style.clip = "rect(0 58px 615px 0px)";
		for(tag in tags){
			if(tags[tag]){
				items = document.getElementsByTagName(tag);
				for(x = 0; x < items.length; x++){
					if(apagou[tag+"-"+x]) items[x].style.visibility = "";
				}
			}
		}
	}
	catch(e){}
}


function flash(movie, flashvars, width, height, retorna){
	swfid = movie.split("/");
	swfid = swfid[swfid.length-1].replace(".swf", "");
	strSWF= '<object id="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="wmode" value="transparent">'+
			'<param name = "allowScriptAccess" value="always">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '" quality="high" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
			'</object>';
	if(!retorna) this.document.write(strSWF);
	else return(strSWF);
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return $(movieName);
    }
    else {
        return document.embeds[movieName];
    }
}

function PegaCor()
{
	return cor;
}

var celula = (pgatual % 6);
celula = celula==0? "06" : z(celula);

function MudaCor(_cor)
{
	cor = _cor;
	
	try { thisMovie(pasta=="ra"?"menu":"menu_df").ASMudaCor(); }
	catch(e){}
	
	try { thisMovie("celulas_" + celula).ASMudaCor(); }
	catch(e){}	

	 if (navigator.appName.indexOf("Microsoft") != -1) {
        $("div_interna").style.scrollbarBaseColor = "#" + cores[cor];
    }
	
	if(highlights)
	{
		for(x = 0; x < highlights.length; x++)
		{
			try{ thisMovie(highlights[x]).ASMudaCor(); }
			catch(e){}
		}
	}
	
	if(pasta=="df")
	{
		img = document.getElementsByTagName("IMG");
		for(x = 0; x < img.length; x++)
		{
			if(img[x].src.indexOf("pixel")>0)
			{
				img[x].src = img[x].src.replace(/roxo|azul|vermelho|laranja|verde/, cor);
			}
		}		
	}
	
	h3 = document.getElementsByTagName("h3");
	for(x = 0; x < h3.length; x++)
	{
		h3[x].innerHTML = flash("../../imagens/subtitulo.swf", "titulo=" + h3[x].rel + "&cor=" + cor, 530, 23, true);
	}
	
	tags = ["h3", "strong", "b", "i", "em", "span", "div", "p", "table", "tr", "td"];
	
	for(x = 0; x < tags.length; x++)
	{
		tag = document.getElementsByTagName(tags[x]);
		for(y = 0; y < tag.length; y++)
		{
			tag[y].className = tag[y].className.replace(/roxo|azul|vermelho|laranja|verde/, cor);
		}
	}
}

if(pasta!="ferramentas" && pgatual > 0)
{
	addEvent(window, "load", AjustaH3, false);
	addEvent(window, "load", AjustaConteudo, false);
	addEvent(window, "resize", AjustaConteudo, false);
}

function AjustaH3()
{
	h3 = document.getElementsByTagName("h3");
	for(x=0;x<h3.length;x++)
	{
		h3[x].rel = h3[x].innerHTML;
		h3[x].innerHTML = flash("../../imagens/subtitulo.swf", "titulo=" + h3[x].innerHTML + "&cor=" + cor, 530, 23, true);
	}
}

function AjustaConteudo()
{	
	try
	{
		h = (document.documentElement.clientHeight) - $("div_interna").offsetTop - 50;
		
		$("div_interna").style.height = (h) + "px";
	}
	catch(e){ alert(e.description) }
}


function celulas()
{
	document.write(flash("../imagens/celulas_" + celula + ".swf", "cor=" + cor, 836, 335, false));
}

/*////////  FERRAMENTAS   //////////// */



function ferramentas(qual, titulo){
	$("iframe_ferramenta").src = "../ferramentas/" + qual;
	$("div_fundao").innerHTML = flash("../../imagens/ferramentas.swf", "titulo=" + titulo, document.documentElement.clientWidth, document.documentElement.clientHeight, true);
	$("div_fundao").style.top = document.documentElement.scrollTop + "px";
	$("div_fundao").style.display = "block";	
}

function MostraFerramenta(){
	document.body.scroll="no";
	$("iframe_ferramenta").style.top = document.documentElement.scrollTop + (((document.documentElement.clientHeight - 600) / 2) + 62) + "px";
	$("iframe_ferramenta").style.left = (((document.documentElement.clientWidth - 630) / 2)) + "px";
	$("iframe_ferramenta").style.display = "block";
}

function ApagaFerramenta(){
	document.body.style.overflow = "auto";
	$("iframe_ferramenta").style.display = "none";
	$("iframe_ferramenta").src = "about:blank";
	setTimeout(function()
	{
		$("div_fundao").innerHTML = "";
		$("div_fundao").style.display = "block";
	}, 300);
}
