$(document).ready(function() {
	
	$.preloadCssImages();
	
	//envia formulario de cadastro
	$('#contact_enviar').click(function() {
		$('.responder').removeClass('responder');
		$('#contact_form_msg').remove();
		validaContato();
	});
	
	//fotos no menu lateral
	var timer;
	clearTimeout(timer);
	povoaGaleriaFlickr();
	
});


function validaContato() {
	validaEmail();
	validaTelefone();
	validaMensagem();
	
	if($('.responder').length > 0) {
		$('#contact_form').append('<div id="contact_form_msg"></div>');
		$('#contact_form_msg').css({opacity: 0, display: 'block'});
		$('#contact_form_msg').html('Preencha os campos corretamente.');
		$('#contact_form_msg').animate({opacity: 1}, 2000);
	} else {
		$('#contact_form').append('<div id="contact_form_msg"></div>');
		$('#contact_form_msg').css({opacity: 0, display: 'block'});
		$('#contact_form_msg').html('Enviando mensagem.');
		$('#contact_form_msg').animate({opacity: 1}, 2000);
		enviaContato();
	}
}


function enviaContato() {
	var valores = $('#contact_form input, #contact_form textarea, #contact_form checkbox').serialize();
	valores += '&mode=contact';
	
	$.post('contato.php', valores, function(data) {
		if(data.success == true) {
			$("#contact_form textarea").val('');
			$('#contact_form_msg').css({opacity: 0, display: 'block', background: '#E7FFDF', borderColor: '#CEEFC2'});
			$('#contact_form_msg').html('Mensagem enviada com sucesso.');
			$('#contact_form_msg').animate({opacity: 1}, 2000);
		}
	}, 'json');
}

function validaEmail() {
	var email = $('#contact_form input[name=email]').val();
	var myregexp = /[a-zA-Z0-9\.\-\_]+\@[a-zA-Z0-9\.\-\_]+\.[a-zA-Z0-9\-\_]+/;
	if(myregexp.test(email) === false) {
		$('#contact_form input[name=email]').addClass('responder');
	}
}

function validaTelefone() {
//	var tel = $('#contact_form input[name=telefone]').val();
//	var myregexp = /\([0-9]{2}\)[0-9]{4}\-[0-9]{4}/;
//	if(myregexp.test(tel) === false) {
//		$('#contact_form input[name=telefone]').addClass('responder');
//	}
}

function validaMensagem() {
	if($('#contact_form textarea[name=mensagem]').val() == '') {
		$('#contact_form textarea[name=mensagem]').addClass('responder');
	}
}

$(document).ready(function() {
		
	//hoverintent do menu
	function menuHoverOver(){
		if($(this).hasClass('nivel1')){
			$(this).children("a").stop().addClass('menu_selecionado').css('opacity', 0).animate({opacity: 0.4}, 'fast').show();
			
			if($(this).children("div").length != 0){
				$("#sub_menu_multimidia").show();
			}
		}
		else {
			$(this).children("a").stop().addClass('menu_selecionado').css('opacity', 0).animate({opacity: 0.4}, 'fast').show();
		}
	};
	
	function menuHoverOut(){
		if($(this).hasClass('nivel1')){
			$(this).children("a").stop().animate({opacity: 0}, 'fast', function() {
				$(this).removeClass('menu_selecionado'); 
			});
			
			if($(this).children("div").length != 0){
				$("#sub_menu_multimidia").hide();
			}
		}
		else {
			$(this).children("a").stop().animate({opacity: 0}, 'fast', function() {
				$(this).removeClass('menu_selecionado'); 
			});
		}
	};
	
	var menuHover = {    
		 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 50, // number = milliseconds for onMouseOver polling interval    
		 over: menuHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 300, // number = milliseconds delay before onMouseOut    
		 out: menuHoverOut // function = onMouseOut callback (REQUIRED)    
	};
	
	$("#menu_superior li").hoverIntent(menuHover);
	
});

