/**
 * JS
 * (c) 2007 Darío G. Ruellan / D²
 */

var timed_reset;

$(function() {

	$("#author_contact").submit(function(){
		return false;
	});
	$("#abortbtn").click(function(){
		reset();
	});
	$("#emailR").click(function(){
		$("#title_text").html("Mensaje para Darío G. Ruellan");
		$("#abortbtn").show().fadeIn();
		$("#t").val("m1");
		slide(2);
	});
	$("#emailG").click(function(){
		$("#title_text").html("Mensaje para Darío González");
		$("#abortbtn").show().fadeIn();
		$("#t").val("m2");
		slide(2);
	});
	$("#nextbtn a").click(function(){
		$("#title_text").html("¿Cuál es su mensaje?");
		$("#nextbtn").fadeOut();
		$("#sendbtn").show().fadeIn();
		slide(3);
	});
	$("#sendbtn a").click(function(){
		$("#title_text").html("<img src=images/d2_sending.gif alt=enviando /> Enviando...");
		$("#sendbtn").fadeOut();
		
		var email = $("#e").val();
		var dest = $("#t").val();
		var msg = $("#m").val();
		
		$.post("lib/authormsgsend.ajax.php", {
				t: dest, e: email, m: msg
			},function(data){
				$("#send_result").html(data);
				$("#title_text").html("¡Gracias!");
				slide(4);
				timed_reset = setTimeout(function(){
					reset();
				}, 9000);
	  	});
	});

	$('#e').keyup(function(){
		if ( email_filter.test($('#e').val())) {
			if ( $("#nextbtn").css("display") == "none" ) $("#nextbtn").show().fadeIn();
		} else {
			if ( $("#nextbtn").css("display") != "none" ) $("#nextbtn").hide();
		}
	})

	function slide (n) {
		pos = -330 * (n-1);
		$("#slider").animate({
				left: pos
		}, "slow");
		if ( pos == 0 ) {
			$("#slider").animate({
					left: pos
			}, "slow");	
		}
	}
	function reset(){
		$("#abortbtn").fadeOut();
		$("#nextbtn, #sendbtn").hide();
		$("#e,#m").val("");
		slide(1);
		clearTimeout(timed_reset);
	}

});