$(function() {

	// ###############################################
	// Classificados interna
	// ###############################################	
	$("img.minImg").click(function() {		
		var grd = "#" + this.id + "_max";
		$("img#img_grande").attr({src: $(grd).html()});
	});

	// ###############################################
	// Classificados
	// ###############################################
	$("input#campoBusca").focus(function() {
		if(this.value == "Digite a palavra chave") {
			this.value = "";
		}
	});

	$("#form").submit(function() {
		location.href = $("#form input#campoBusca").serialize();
	});
	
	// ###############################################
	// Anuncie - Classificados
	// ###############################################
	$("#linkFormAnuncie").click(function(){
		if($("#formClassificados").css("display") == "block") {
			$("#formClassificados").hide();
		}else {
			$("#formClassificados").show();
			$("#nome").focus();
		}
	});
	
	// ###############################################
	// Newsletter
	// ###############################################
	$("#formEnvNews").submit(function() {
		
		if($("#campoNews").val() == "") {
			// caso campo de email esteja em branco		
					
			alert("Campo não deve ficar em branco!");
			$("#campoNews").focus();
		}else {
			// caso esteje preenchido

			if(mValidaEmail('campoNews')) {
				// caso email seja válido
				
				// faz requisição via ajax
				$.ajax({type: "POST", url: this.action, timeout: 4000, data: $("#formEnvNews *").serialize(),
				   beforeSend: function() {
						$("#respFormNewsletter").html("<p id='mensagem'>Aguarde...</p>");
				   },
				   success: function(msg) {
						$("#respFormNewsletter").html(msg);
				   }
				 });
			}
		}
		return false;
	});
	
	// ###############################################
	// Contato
	// ###############################################
	$("#formContato").submit(function() {
		if(validaForm()) {
			// campos em brancos estiverem validos
			
			if(mValidaEmail('email')) {
				// caso email seja válido
				
				// faz requisição via ajax
				$.ajax({type: "POST", url: this.action, timeout: 2000, data: $("#formContato input, select, textarea").serialize(),
				   beforeSend: function() {
						$("#formContato").hide();
						$("#aviso").hide();
						$("#txtEnviado").show();
						$("#txtEnviado").html("<p>Aguarde...</p>");
				   },
				   success: function(msg) {
						$("#txtEnviado").html(msg);
				   }
				 });
			}
		}
		return false;
	});
	
	// ###############################################
	// Galeria de fotos
	 // ###############################################
	$("#galeria").change(function() {

			// faz requisição via ajax
			$.ajax({type: "GET", url: "index.php?acao=fotosGaleria", timeout: 2000, data: $("#galeriasTopo input, select").serialize(),
			   beforeSend: function() {
					$("div#fotos").html("<p>Aguarde...</p>");
			   },
			   success: function(msg) {
					$("div#fotos").html(msg);
			   }
			 });
	});
});