// JavaScript Document

$(document).ready(function() {
	
	// Hollover das imagens da galeria
	$('.galeria').hover(
	function() {
		$(this).children('img').css('border', '5px dashed #1C4573');
	},
	function() {
		$(this).children('img').css('border', '5px solid #FFF');
	});
	
	// Mostra resultado da enquete
	$('.enq_res').click(function() {
		$('#enquete_form').animate({opacity:0}, 1000, function() {
			$('#enquete_form').hide();
		});
		$('#resenqueteaux').animate({opacity:1}, 1000, function() {
			$('#resenqueteaux').show();
		});
	});
	$('.enq_form').click(function() {
		$('#resenqueteaux').animate({opacity:0}, 1000, function() {
			$('#resenqueteaux').hide();
		});
		$('#enquete_form').animate({opacity:1}, 1000, function() {
			$('#enquete_form').show();
		});
	});
	
	// Valida form da enquete
	$('#enquete_form').submit(function() {
		var boolValid = false;
		$('#enquete_form input:radio').each(function() {
			if ( $(this).is(':checked') ) {
				boolValid = true;
			}
		});
		if (boolValid == false) {
			alert('Preencha uma das opções!');
			return false;	
		}
	});


	// Ativa galeria pirobox
	$('.thumbs').piroBox({
			mySpeed: 500, 
			bg_alpha: 0.8,
			pathLoader : 'url(images/layout/pirobox/ajax-loader_b.gif) center center no-repeat;', 
			gallery : '.pirobox li a', 
			gallery_li : '.pirobox li',
			single : '.single  a',
			next_class : '.next',
			previous_class : '.previous'
	});
	
	// Valida vormulário
	$("#contato_form").validate({		
		rules: {
			mensagem: {
				required: true,
		  		maxlength: 300
			}
	  	}
	});
	
	// Mostra recados
	$('.recados_txt').hide();
	$('.recados_tit').click(function() {
		$(this).next().next().toggle(500);
		return false;
	});
	
	// Grava newsletter
	$('#news_form').submit(function(e) {
		e.preventDefault();
		$.ajax({
			url: 'modulos/home/gravanews.php',
			dataType: 'html',
			type: 'post',
			data: $('#news_form').serialize(),
			
			beforeSend: function() {
				$('#news_form').css('position', 'relative');
				$('#res_news').html('<img src="images/layout/carregando1.gif" id="carregando" alt="" />').css({position: 'absolute', top: '5px', left: '120px'});
			},
			complete: function() {
				$('#carregando').remove();
			},
			success: function(data, textStatus) {
				$('#res_news').html(alert(data));
				if (data == 'Email cadastrado com sucesso!') {
					$('#news').val('');
				}
			},
			error: function(xhr, er) {
				alert('Error ' + xhr.status + ' - ' + xhr.statusText);
			}
		});
	});

}); // Fim do ready
