var podefscommand;

$(function()
{
	var userAgent = navigator.userAgent.toLowerCase();
	var userBrowserName  = navigator.appName.toLowerCase();
	// Figure out what browser is being used
	$.browser = 
	{
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
		safari: /webkit/.test( userAgent ) && !/(chrome)/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ),
		chrome: /chrome/.test( userAgent ),
		name:userBrowserName
	};
	podefscommand = ($.browser.msie && parseInt($.browser.version) >= 6);
});


function flash(movie, flashvars, width, height, retorna)
{	
	strSWF = '';
	swfid = movie.split("/");
	swfid = swfid[swfid.length-1].replace(".swf", "");
	
	if(podefscommand)
	{
		flashvars = "podefscommand=sim&" + flashvars;
		strSWF = '<scr' + 'ipt for="' + swfid + '" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>';
	}

	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="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '" quality="high" 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 abreMenu(){
	try {
		$("#div_menu").css("clip", "rect(0 961px 430px 0)");	
	}
	catch(e){ 
		setTimeout("abreMenu()", 250); 
	}
}

function fechaMenu(){
	try {
		$("#div_menu").css("clip", "rect(0 961px 42px 0)");
	}
	catch(e){ 
		setTimeout("fechaMenu()", 250); 
	}
}

function redirecionacombo(combo)
{
	window.open(combo.value);
}


$(document).ready(function()
{
	
	fechaMenu();
	
	// configura os botőes com rollover

	var LinkIconImgs = new Array();
	var j = 0;
	
	$("a.LinkIcon").each(function(i)
	{
		img = $("img:first", this);
		j++;
	    LinkIconImgs[j] = new Image(); 
    	LinkIconImgs[j].src = img.attr("src").replace("off", "on");
		img.attr("original", img.attr("src"));
		img.attr("rollover", LinkIconImgs[j].src);
	});
	
	$("a.LinkIcon").mouseover(function()
	{
		$("img:first", this).attr("src", $("img:first", this).attr("rollover"));
	});
	$("a.LinkIcon").mouseout(function()
	{
		$("img:first", this).attr("src", $("img:first", this).attr("original"));
	});	
	

});

function janela(url, W, H){
	jan = window.open(url, "", "width=" + W + ",height=" + H + ",left=" + ((screen.availWidth - W) / 2) + ",top=" + ((screen.availHeight - H) / 2));
	jan.focus();
}

function recomende(){
	
    Shadowbox.open({
        content: "../home/recomende.asp?url=" + escape(location.href) + "&titulo=" + escape(document.title),
        player:  "iframe",
        title:   "Recomende esta P&aacute;gina",
        width:   400, 
        height:  260
    });
}

/* AbreShadowbox

Exemplos (uso no flash):
	
	javascript: AbreShadowbox('foto.jpg', 'Minha Foto', 'img', 640, 480);
	javascript: AbreShadowbox('pagina.htm', 'Minha Página', 'iframe', 500, 400);

Exemplos (uso no HTML):

	<a href="foto.jpg" onclick="AbreShadowbox(this.href, 'Minha Foto', 'img', 640, 480); return false;">link</a>
	<a href="pagina.htm" onclick="AbreShadowbox(this.href, 'Minha Página', 'iframe', 500, 400); return false;">link</a>

*/
function AbreShadowbox(url, titulo, player, w, h)
{
    Shadowbox.open({
        content: url,
        player:  player,
        title:   titulo,
        width:   w, 
        height:  h
    });
}


var tabAtual;

function TabAnos(tipo)
{
	tipo = !tipo? "ajax" : tipo;

	if(tipo=="div")
	{
		$("#doclist div").css("display", "none");
		$("#doclist div:first").css("display", "block");
	}
								 
	$(".tab > li > a").each(function(i)
	{
		$(this).bind("mouseover", function(e)
		{
			$(this).animate(
			{
				opacity: 0.7
			}, 250);
		});
		$(this).bind("mouseout", function(e)
		{
			$(this).animate(
			{
				opacity: 1
			}, 250);
		});	
		$(this).bind("click", function(e)
		{
			tabNova = $(this).attr("id");
			$("#" + tabAtual).attr("class", "tab_off");
			$(this).attr("class", "tab_on");
			
			if(tipo=="div")
			{
				$("#" + tabAtual.replace("ano", "div")).css("display", "none");
				$("#" + $(this).attr("id").replace("ano", "div")).css("display", "block");
			}
			
			tabAtual = tabNova;
			
			width = $(".tab > li > a").length * $(".tab > li > a").width();

			if(tipo=="ajax")
			{
				$("#doclist").html("<img src='../imagens/carregador.gif' style='margin: 100px 0 100px " + parseInt((width-86)/2) + "'>");
				$("#doclist").load($(this).attr("href") + " #doclist div", function (responseText, textStatus, XMLHttpRequest){ Shadowbox.setup("a.download[rel^='shadowbox']"); });
			}
			
			return false;
		});
	});	
}


function slideDown(div)
{
	if($("#" + div).css("display")=="none") 
	{
		$("#" + div).slideDown("normal");
	} 
	else 
	{
		$("#" + div).slideUp("normal");
	}
}

function busca(txt)
{
	if(txt=="")
	{
		alert("Por favor digite o termo a ser pesquisado");
	}
	else
	{
		location = "../home/busca.asp?busca=" + txt;
	}
}