$(function(){

	if (!$("#photo img")[0].complete)
	{
		$("#photo img").css({opacity:0});
		$("#content").hide();
	}

	$("#photo img").load(function(){
		$("#photo img").animate({opacity:1},"slow");
		$("#content").fadeIn("slow");
	});
	
	$("input:text")
		.val("Ihre E-Mail-Adresse")
		.focus(function(){
			if (typeof this.origVal == "undefined") this.origVal = this.value;
			if (this.value == this.origVal)
			{
				$(this).val("").toggleClass("blur");
			}
		})
		.blur(function(){
			if (this.value == "")
			{
				$(this).val(this.origVal).toggleClass("blur");
			}
			$(this).removeClass("is-email isnot-email")
		})
		.keyup(function(){
			if (this.value != this.oldVal)
			{
				if (verifyEmail(this.value))
				{
					$(this).addClass("is-email").removeClass("isnot-email");
				}
				else
				{
					$(this).addClass("isnot-email").removeClass("is-email");
				}
			}
			this.oldVal = this.value;
		});
	
	$("input:submit")
		.click(function(){
			var emailAddress = $("input:text")[0].value;
			if (verifyEmail(emailAddress))
			{
				$.post(
					"/callbacks/submitemail.php",
					{
						"email" : emailAddress
					},
					function (response) {
						if (response)
						{
							$("#response").html(response.message).slideDown("fast");
						}
					},
					"json"
				);
			}
			else
			{
				$("#response").html("Bitte geben Sie eine g&uuml;ltige E-Mail-Adresse in der Form <em>ihrname@beispiel.de</em> an!").slideDown("fast");
			}
		
			return false;
		});
		
	$("#response").hide();

	var e = $("<a/>").attr("href","mailto:"+"mail"+"@"+"mooistore"+"."+"de").append("mail"+"@"+"mooistore"+"."+"de");
	$("span#email").replaceWith(e);
		
});

function verifyEmail (e)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(e)
}
