var emailsignup = new function() {
	this.email_label = "Don't be left in the dark, enter your email";
	this.email_selector = '#emailsignup_email';
	this.ajax_url = '/templates/emailsignup/ajax.php';
	
	this.setup = function() {
		jQuery(this.email_selector)
			.val(this.email_label)
			.focus(function() {
				if (jQuery(this).val() == emailsignup.email_label)
					jQuery(this).val('');
			})
			.blur(function() {
				if (jQuery(this).val() == '')
					jQuery(this).val(emailsignup.email_label);
			});
	}
	
	this.complete = function() {
		jQuery("#emailsignup_form").fadeOut();
		jQuery("#emailsignup_message").fadeIn();
	};
	
	this.submit = function() {
		var str_email = jQuery(this.email_selector).val();
		
		if (str_email == "" || str_email == this.email_label) {
			jQuery(this.email_selector).addClass('err').focus();
		} else {
			jQuery.post(this.ajax_url, { email: str_email }, function() { emailsignup.complete(); });
		}
	}
};

jQuery(document).ready(function() {
	emailsignup.setup();
});

