// JavaScript Document


$(window).resize(function() {
		AlturaLargura();
	if (myWidth >= 980){
		Redimenciona(18,false);
	}
 	
});

$(document).ready(function(){
	$("#table_loading").css("display","none"); 
	razao=531/1440
	footerH = $("#footer").height();
	headerH = $("#header").height();
	
	$('.rotate_fundo_home').fadeIn("fast");
	if (myWidth >= 980){
		Redimenciona(20,false);
	}
	
	$("#menu ul li a").mouseover(function(){
		$('.rotate_fundo_home').cycle("pause");
	}).mouseout(function(){
		$('.rotate_fundo_home').cycle("resume");
	})
	
 });

function Redimenciona(a,b){
	AlturaLargura();
	if (myWidth <= 980) myWidth = 1000;
	$(".fundo_home").each(function(){
		$(this).css("width",myWidth - a);
		$(this).css("height",razao*myWidth);
		$(".fundo_home").show();
		$(".rotate_fundo_home").css("width",myWidth - a);
		$(".rotate_fundo_home").css("height",razao*myWidth);
		$("#main_sup").css("width",myWidth - a);
		$("#main_inf").css("width",myWidth - a);
		$("#footer_titulo").css("width",myWidth - a);
		$("#footer_borda_sup").css("width",myWidth - a);
		$("#container").css("width",myWidth - a);
		$("#mainContent").css("width",myWidth - a);
		
		var areaHF = (myHeight - $("#mainContent").height())/2 -a;
		$("#header").css("height", areaHF );
		$("#footer").css("height", areaHF );
			
		if (myHeight < $("#mainContent").height() && !b){
			Redimenciona(20,true);
		}
		else{
			$("#menu_conteudo").css("height",razao*myWidth);
			$("#conteudo1").css("height",razao*myWidth - 20);
			$("#conteudo1").css("width",myWidth - $("#menu_conteudo").width() - a - 20);
			$(".rotate_fundo_home").stop();
			$(".fundo_home").stop();
			$(".rotate_fundo_home").css("text-align","center");
			$(".fundo_home").css("text-align","center");
			$('.rotate_fundo_home').show();
			$('.rotate_fundo_home').css("z-index",0);
			$('.rotate_fundo_home').cycle({ 
				fx:    'fade', 
				speedIn: 1500,
				speedOut:1500,
				sync: 	true,
				timeout: 6000
				//,easeIn: "fadeIn",
				//easeOut: "fadeOut"
			});
		}
	});
	
}

function CarregaAlbum(id){
	$(id).fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});
}

function CorrerEsquerda(id){
	if (document.getElementById("menu_conteudo").style.display == 'none'){
		$("#menu_conteudo").html( $("#" + id).html() );
		$("#menu_conteudo").animate({width: 'toggle'});
		FecharDireita("conteudo1");
	}
	else if ($("#menu_conteudo").text() != $("#" + id).text() ){
		$("#menu_conteudo").animate({width: 'toggle'},function(){
			$("#menu_conteudo").html( $("#" + id).html() );
			$("#menu_conteudo").animate({width: 'toggle'});												  
			FecharDireita("conteudo1");
		});
	}
	else{
		FecharDireita("conteudo1");
		$("#menu_conteudo").fadeOut("medium");												  
		$("#menu_conteudo").fadeIn("medium");												  
			
	} 

}

function FecharDireita(id){
	if (document.getElementById(id).style.display != 'none'){
		$("#" + id).html( $("#" + id).html() );
		$("#" + id).animate({width: 'toggle'});
	}
}

function AbrirConteudo(url){
	if (document.getElementById("conteudo1").style.display == 'none'){
		$("#conteudo1").animate({width: 'toggle'});
		$("#conteudo1").empty().html("<div style='text-align:center; margin:auto; width:50px; height:50px; background:url(../imagens/fundo_transp50.png) repeat; padding:10px;'><img src='../imagens/loading.gif' width='50' height='50' /></div>");
		$("#conteudo1").load(url);
		$("#conteudo1").fadeIn("medium");
		$("#table_loading").css("display","none");			   
	}
	else{
		$("#conteudo1").fadeOut("medium", function(){	
			$("#conteudo1").empty().html("<div style='text-align:center; margin:auto; width:50px; height:50px; background:url(../imagens/fundo_transp50.png) repeat; padding:10px;'><img src='../imagens/loading.gif' width='50' height='50' /></div>");
			$("#conteudo1").load(url);
			$("#conteudo1").fadeIn("medium");
			$("#table_loading").css("display","none");			   

		});
			
	}
}

function AbrirConteudoCorrerEsquerda(url, id){
	if (document.getElementById("menu_conteudo").style.display == 'none'){
		$("#menu_conteudo").html( $("#" + id).html() );
		$("#menu_conteudo").animate({width: 'toggle'}, AbrirConteudo(url));
	}
	else if ($("#menu_conteudo").text() != $("#" + id).text() ){
		$("#menu_conteudo").animate({width: 'toggle'},function(){
			$("#menu_conteudo").html( $("#" + id).html() );
			$("#menu_conteudo").animate({width: 'toggle'});
			AbrirConteudo(url);
		});
	}
	else{
		$("#menu_conteudo").fadeOut("medium", AbrirConteudo(url));												  
		$("#menu_conteudo").fadeIn("medium");
	}
}

function MostrarLogo(id, imagem){
		$("#menu_lateral_logo").empty().html("<img width='100' src='../img_usr/" + imagem + "'>");
		var p = $(id).position();
		$("#menu_lateral_logo").css("left", p.left + 140);
		$("#menu_lateral_logo").css("top", p.top - 20);
		$("#menu_lateral_logo").css("z-index", 1000);
		$("#menu_lateral_logo").stop(true, true).fadeIn("fast");
	//window.alert($(id).css("top"))
	//window.alert($(id).css("left"))
}

