$(document).ready(function(){
	$("#banner_home").hide();
	$('a#inline').live('click', function() {
		$(this).fancybox({
				'hideOnContentClick': false,
				frameHeight: 330,
				overlayOpacity: 0.7,
				overlayColor: '#000',
				callbackOnClose: function() {
					$("#banner_home").show();
				}

			});
	});
	$('body').append('<a id="inline" href="/email_box.phtml">This shows content of element who has id="data"</a>');
	$('a#inline').click();
	$('a#inline').slideDown('fast', function() {
		$('a#inline').click();
	});

	$("#submit_box").live('click', function(){
		$(".error").hide();
		var hasError = false;

		var Email_address = $("#email_box").val();

		if(Email_address == '') {
			$("#error_box").html('');
			$("#response_box").slideDown('fast');
			$("#response_box").html('No has introducido una dirección de email!');
			hasError = true;
		}

		if(hasError == false) {
			$.ajax({
				type: "POST",
				async: true,
				url: 'http://' + document.domain + '/email_action.php',
				data: { email: Email_address },
				dataType: "json",
				success: function (json)
				{
					if ( 'OK' == json['status'] )
					{
						$("#response_box").addClass('ok');
						$("#response_box").slideDown('fast');
						$("#form_box").hide();
						$("#response_box").html(json['message']);
					}
					else
					{
						$("#response_box").slideDown('fast');
						$("#response_box").html(json['message']);
					}
				},
				error: function (json)
				{
					$("#response_box").html('Ocurrió un error al procesar la llamada.');
				}
			});
		}
		return false;
	});
});
