// JavaScript Document

function hoverMenus(elm, tmp)
{
	$(elm).hover(function(){
		document.overOn = true;
		$(this).next().slideDown("normal");
		$(this).parent().addClass("active");
		if(elm=="#navItem01_link")
			$("#navItem07_link").next().slideUp("slow", function() { $(this).parent().removeClass(); });
		else if(elm=="#navItem07_link")
		 $("#navItem01_link").next().slideUp("slow", function() { $(this).parent().removeClass(); });
	}, function () {
		document.overOn=false;
		$(this).timer = window.setTimeout(function() {								
			if(document.overOn==false)
			{
				$(elm).next().slideUp("slow", function() { $(this).parent().removeClass(); document.overOn = false; });
			}
		}, tmp);
	});
	$(elm).next().hover(function(){
		document.overOn=true;
	},function(){
		document.overOn=false;				
		$(this).timer = window.setTimeout(function() {								
			if(document.overOn==false)
			{
				$(elm).next().slideUp("slow", function() { $(this).parent().removeClass(); document.overOn = false; });
			}
		}, tmp);				
	});
}

function initMenu()
{	
	$("#subNavItem01").removeClass('hide');
	$("#subNavItem01").addClass('subItem');
	$("#subNavItem07").removeClass('hide');
	$("#subNavItem07").addClass('subItem');
	$(".subItem").hide();
	$(document).overOn = false;			
	hoverMenus("#navItem01_link", 800);
	hoverMenus("#navItem07_link", 800);		
	
	//outros itens, além do menu, para páginas e situacoes especificas
	toggleHoverBorder(".pImgLeft a img", "imgBrdThumb01_left", 4, true);	
	toggleHoverBorder(".pImgRight a img", "imgBrdThumb01_right", 4, true);	
	toggleHoverBorder(".fotosContainer a img", "imgBrdFotos", 4, true);
	//$("#boxFotos .boxSideBarContent01 a").lightbox();
	toggleHoverBorder("#boxFotos .boxSideBarContent01 a img", "imgBrdFotos", 4, true);	
	
		initSideBar();
}

function initSideBar()
{
	if($("#sideBar").html()!="")
	{
		document.sideBarHeight = 0;
		document.scrolling = 0;
		document.bottomDistance = 340;		
		$(".boxSideBar").each(function(){
			document.sideBarHeight += $(this).height()+50;
		});
		$("#sideBar").css("position","relative");
		
		if($.browser.msie)
		{
			if(Number($.browser.version)>6)
				$("body").scroll(function(){ posSideBar(); });
			else
			{
				if(document.sideBarPosInterval)
				 document.sideBarPosInterval = null;
				document.sideBarPosInterval = window.setInterval(function()
				{
					posSideBar();
				},15);
			}
		}
		else
			$(document).scroll(function(){ posSideBar(); });
	}	
}

function posSideBar(zerar)
{
	if(window.scrollY)
	{
		document.scrolling = window.scrollY;
	}
	else
	{
		document.scrolling = document.body.parentNode.scrollTop;
	}	
	if($("#contentBody").height() > 740 && document.scrolling > 200 && zerar==null)
	{
		$("#sideBar").css("height",document.sideBarHeight+"px");
		if($("#sideBar").height() + document.scrolling + document.bottomDistance < $("body").height() - 50)
		{
			$("#sideBar").css("top", (document.scrolling-200)+"px");
		}
	}
	else
	{
		$("#sideBar").css("height","740px");
		$("#sideBar").css("top","0px");	
	}
}

function initHighLight(folder, language)
{
	//************** como é a primeira função, esta receberá a verificação de linguagem.
		$.cookie('language', null);
	 //verificaBrowserLanguage(language);
	//**********************************************************************************

	var highLightSwf = new SWFObject(((language!=null)? '../' : '') + '_swf/homeIntro.swf', 'homeIntro', '780', '140', '8', '#FFFFF');
	highLightSwf.addParam('useExpressInstall', 'false');
	highLightSwf.addParam('wmode', 'transparent');
	if(language)
		highLightSwf.addVariable('idioma', language);
	if(!folder)
		highLightSwf.addVariable('path', '_img/estrutura/');
	else
		highLightSwf.addVariable('path', folder+'_img/estrutura/');
	highLightSwf.write('highlight');
}

function initBoxItasca(){
	$("#boxItasca p a").attr("target", "_blank");
	$("#boxItasca select").change(function(){
		if($(this).val()!="")
			window.open($(this).val());				
	});
}
function initBoxPublicacoesHome(){
	$("#boxPublicacoes dd a").each(function(){		
		if($(this).attr("href").indexOf("http://")!="-1")
			$(this).attr("target", "_blank");
	});
}

function toggleHoverBorder(elms, className, bdrWidth, useLightBox)
{
		$(elms).hover(function(){		
		$(this).parent().addClass(className);
		$(this).parent().attr("style", "background:transparent url("+$(this).attr("src")+") -"+bdrWidth+"px -"+bdrWidth+"px no-repeat; width:"+($(this).width()-(bdrWidth*2))+"px; height:"+($(this).height()-(bdrWidth*2))+"px;");		
		$(this).parent().hover(function(){ void(null); }, function(){			
			$(this).removeClass(className);
		});
	}, function(){ void(null); });
	if(useLightBox)
		$(elms).parent().lightbox();
}

(function ($) {
  $.fn.fixAccordionOverflow = function () {				
				if ($.browser.msie) {
					return this.each(function () {
						$(this).children(".selected").next().attr('style', "display:block; overflow-x:hidden !important");
						if(Number($.browser.version)<7)
						{
							$(this).children(".selected").next().focus();
						}						
					});
    }
				else
				 $(this).children(".selected").next().attr('style', "height:320px");
  };
})(jQuery); // usage: $('pre').fixOverflow().doOtherPlugin();

function validaFormularioContato()
{
	if($("#txtNome").val()=="" || $("#txtEmail").val()=="" || $("#txtAssunto").val()=="" || $("#txtMensagem").val()=="")
	{
		$("#link01").click();
		window.hash = "";
		return false;
	}
	else
	{
		vlrEmail = $("#txtEmail").val();
		er = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$/;							
		if(er.test($("#txtEmail").val())==false && $("#txtEmail").val()!="")
		{
			$("#link02").click();
			window.hash = "";				
			return false;
		}
	}
	$("#frmContato").submit();
}
function initForm()
{
	$("input, textarea").focus(function(){
		$(this).addClass("txtFocus");
	});
	$("input, textarea").blur(function(){
		$(this).removeClass("txtFocus");
	});
	$("#frmContato .btn").click(function(){
		validaFormularioContato();
	});
	$("#link01").attr("href", "#TB_inline?height=70&width=265&inlineId=msg01&modal=true");
	$("#link02").attr("href", "#TB_inline?height=70&width=265&inlineId=msg02&modal=true");
	$("#link03").attr("href", "#TB_inline?height=70&width=265&inlineId=msg03&modal=true");
	verUrl = document.URL;
	if(verUrl.indexOf("msg=ok")!=-1)
	 $("#link03").click();
}

function verificaBrowserLanguage(langInfo)
{
  //links idiomas
	$("#mnLangEnglish a").click(function(){
		//$.cookie('language', 'en', { expires: 60, path: '/' });
	});
	$("#mnLangEspanol a").click(function(){
		//$.cookie('language', 'es', { expires: 60, path: '/' });
	});
	$("#mnLangPortugues a").click(function(){	
		//$.cookie('language', 'pt', { expires: 60, path: '/' });
	});

  //redirecionamento
  if(langInfo==null) {
   //por cookie
   if($.cookie('language')!='pt' && $.cookie('language')!=null)
   {
	window.location = $.cookie('language');
	return false;
   }
   
   //por idioma
   var lct="en";
   if (navigator.language) {
     lct=navigator.language.toLowerCase().substring(0, 2);
   } else if (navigator.userLanguage) {
     lct=navigator.userLanguage.toLowerCase().substring(0, 2);
   } else if (navigator.userAgent.indexOf("[")!=-1) {
     var debut=navigator.userAgent.indexOf("[");
     var fin=navigator.userAgent.indexOf("]");
     lct=navigator.userAgent.substring(debut+1, fin).toLowerCase();
   }
	if(lct=="en" && ($.cookie('language')=="" || $.cookie('language')==null)) //english
		window.location = "en";
	else if(lct=="es" && ($.cookie('language')=="" || $.cookie('language')==null)) //espanol
  		window.location = "es";
  }
}

function iconesEntrevistas(idioma)
{
	if(idioma!=null)
	 path = "../";
	else
	 path = "";
	$("ul.ul01 li").each(function() {
		var ext = $(this).children("a").attr("href");
		ext = ext.length;
		ext = $(this).children("a").attr("href").substring(ext-3, ext);			
		if(ext=="wmv" || ext=="wma" || ext=="mp3")
		{
			if(ext=="wma" || ext=="mp3")
				$(this).append("<img src='"+path+"_img/bullet/bullet_mp3.gif' alt='audio' width='18' height='18' style='display:inline;margin:3px 0 0 5px' />");
			else if(ext=="wmv")
				$(this).append("<img src='"+path+"_img/bullet/bullet_wmv.gif' alt='video' width='18' height='18' style='display:inline;margin:3px 0 0 5px' />");
		}
	});
}