// JavaScript Document

$(document).ready(function() {
						   
	// fix for target="_blank"
	$("a[@rel~='external']").click(function(){
		window.open($(this).attr("href"), 'janela','scrollbars=yes,resizable=yes,width=650,height=600');
		return false;
	});
	
	//focus no primeiro campo
	$("#f_contato :input:visible:enabled:first").focus();
	
	//codigo morse
	$("#bt_morse").click(function() {
		var otexto = $("#t").val();
		var traduz = $("input[name=c]:radio[checked]").val();
		
		if(otexto=="") {
			alert("Digite um texto");
			return false
		}
		if(traduz=="") {
			alert("Selecione um módulo de tradução");
			return false
		}
		
		var nr_rand = Math.random();
		var params="t="+otexto+"&c="+traduz+"&random="+nr_rand;
		var txt = $.ajax({
			url: "morse.php",
			data: params,
			async: false
		 }).responseText;
		 
		 $("#trad_morse").html(txt);
								 
	})
	
	// Menu home
	 $(".bt_menu_home").click(function() {
		$(".submenu").slideUp("fast");
		$(this).next().slideDown("normal");
	 });
	// Clica no último item do menu
	 if($("#menu_home").length > 0) {
	 	$(".bt_menu_home:last").trigger("click");
	 }
	 
	// Revesa fotos da Home
	if($("#bnr_topo").length>0) {
		var qt_fotos=7; // Quantidade total de fotos para revesar
		var numRand = (Math.floor(qt_fotos*Math.random()))+1;
		src_img = "img/home/foto"+numRand+".jpg";
		$("#foto_home").attr("src", src_img);

	}
	 
	//Listas de itens ocultos
	$('.lista1').find('dd').hide().end().find('dt').click(function() {
		 $('.lista1').find('dd').each(function() {
			  dd = $(this);
			  dt = $(this).prev();
			  if (dd.is(':visible')) {
				  dd.slideUp();
				  dt.css({fontWeight:"normal", background:"url(img/bt_mais.gif) no-repeat left center"});
			  }
		  });
		 var resposta = $(this).next();
		 if (resposta.is(':visible')) {
			 resposta.slideUp();
			 $(this).css({fontWeight:"normal", background:"url(img/bt_mais.gif) no-repeat left center"});
		 } else {
			 resposta.slideDown();
			 $(this).css({fontWeight:"bold", background:"url(img/bt_menos.gif) no-repeat left center"});
		 }
	});

});

