$(document).ready(function(){
        $(".emailSignupRetry").click(function(){
                window.clearTimeout(failTimeout);
                $(this).find(".newsletterFail").css('z-index',1);
                $(this).find(".hpNewsletterContainer").animate({height:115},"slow",function(){
                        $(this).find(".newsletterSignup").css({display:'block',
	                        zIndex:2}).fadeIn("slow");
                });
        })

        $(".newsletterForm").submit(function(){
                //check email validity
                if($(this).find(".newsletterEmail").val().indexOf('@') > 0 && $(this).find(".newsletterEmail").val().indexOf('.') >= 0)
                {
                        $("#wrapper").append($("<img />").attr("src","http://www.homesandproperty.co.uk/es/enewletterobyx.obyx?newsletterEmail=" + $(this).find(".newsletterEmail").val()).attr("width",1).attr("height",1));
                        $(this).parents(".hpNewsletterContainer").find(".newsletterSignup").css('display','none');
                        $(this).parents(".hpNewsletterContainer").find(".newsletterThanks").fadeIn("slow");
                        $(this).parents(".hpNewsletterContainer").animate({height:100},"slow");

                }
                else
                {
                        $(this).parents(".hpNewsletterContainer").find(".newsletterFail").fadeIn("slow",function(){
                                $(this).parents(".hpNewsletterContainer").find(".newsletterSignup").css('display','none');
                        });
                        $(this).parents(".hpNewsletterContainer").animate({height:90},"slow");
                        failTimeout = window.setTimeout(function(){
                                $(this).parents(".hpNewsletterContainer").find(".newsletterFail").css('z-index',1);
                                $(this).parents(".hpNewsletterContainer").animate({height:115},"slow",function(){
                                        $(this).parents(".hpNewsletterContainer").find(".newsletterSignup").css({display:'block',
                                        	zIndex:2}).fadeIn("slow");
                                });
                        },5000)
                }
                return false;
        });

        $(".newsletterEmail").click(function(){
                if($(this).val() == "Enter your email address here")
                {
                        $(this).val("");
                }
        });
});
