Shadowbox.init();

$(document).ready(function() {
/*-------------------------------------
	SHADOWBOX (LIGHTBOX)
-------------------------------------*/
	$(".wp-caption a").attr("rel","shadowbox");


/*------------------------------------------------------------------
	MOSTRA/ESCONDE DA LISTA DOS ARQUIVOS
------------------------------------------------------------------*/
	var ano_lista = $(".lista-noticias").attr("id");
	$(".arquivos li ul").hide();
	
	//if( ano_lista != null ) {
	if( typeof ano_lista != 'undefined' && ano_lista != false ) {
		var ano = ano_lista.replace("arquivos-","");
		$(".arquivos").find(".arquivos-" + ano + " ul").show();
	} else {
		$(".arquivos li:first").find("ul").show();
	}
	
	$(".tit-arquivo").click(
		function() {
			var lista = $(this).next();
			if( $(lista).is(":visible") ){
				$(".arquivos li ul").slideUp("fast");
				//$(lista).slideDown("fast");
			} else {
				$(".arquivos li ul").slideUp("fast");
				$(lista).slideDown("fast");
			}
			return false;
		}
	);


/*-----------------------------------------------
	CONTATO
-----------------------------------------------*/
	
	function retorno(tipo, mensagem) {
		$(".retorno").remove();
		
		var msg_retorno = '<p class="retorno ' + tipo + '" style="display: none;">' + mensagem + '</p>';
		$(msg_retorno).insertBefore("#form-fale-conosco").fadeIn("fast");
	}
	
	$("#form-fale-conosco").live("submit", function(event) {
		var data = $(this).serialize();
		var nome = $("#nome").val();
		var email = $("#email").val();
		var telefone = $("#telefone").val();
		var mensagem = $("#mensagem").val();
		//var URL = $(this).attr("action");
		var URL = $("#logo a").attr("href") + "admin/wp-content/themes/verso/includes/envia_contato.php";
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		if ( nome == '' || email == '' || telefone == '' || mensagem == '' ) {
			
			retorno("erro", "Antes de enviar o seu contato, preencha todos os campos.");
			
		} else if( !emailReg.test(email) ) {
			
			retorno("erro", "Por favor, digite um email válido.");
			
		} else {
			
			$.ajax({
				type: "POST",
				url: URL,
				data: data,
				success: function() {
					$("#form-fale-conosco").fadeOut(
						500, 
						function() { retorno("sucesso", "Sua mensagem foi enviada com sucesso. Agradecemos seu contato."); }
					);
				},
				error: function() {
					retorno("erro", "Desculpe, ocorreu um erro durante o envio de sua mensagem. Por favor, tente novamente.");
				}
			});
			
		}
		
		event.preventDefault();
	});


/*-----------------------------------------------
	TWITTER
-----------------------------------------------*/
	$(function(){
		$("#tweets").tweet({
			join_text: "",
			username: "versocomunica",
			avatar_size: 0,
			count: 1,
			auto_join_text_default: "",
			auto_join_text_ed: "",
			auto_join_text_ing: "",
			auto_join_text_reply: "",
			auto_join_text_url: "",
			loading_text: "Carregando tweets..."
		});
	});


/*-----------------------------------------------
	MÁSCARA EM FORMULÁRIOS
-----------------------------------------------*/
	$(function(){
	   $("#telefone").mask("(99) 9999-9999");
	});


/*-----------------------------------------------
	MÁSCARA EM FORMULÁRIOS
-----------------------------------------------*/
	$(".gallery ul").jcarousel();
	
});
