$(function() {
	// jQuery extention to clear default input values onfocus
	// For password fields, it adds/removes a password field class that fakes the Password defaultValue
	$.fn.clearDefaultValue = function() {
		return this.focus(function() {
			if(this.value == this.defaultValue)
				this.value = '';
			if(this.type == 'password' && this.value == '')
				$(this).removeClass('passwordField');
		}).blur(function() {
			if(!this.value.length)
				this.value = this.defaultValue;
			if(this.type == 'password' && this.value == '')
				$(this).addClass('passwordField');
		});
	};
	
	$('<p id="result"></p>').insertAfter('#newsletter-signup input.[type="image"]');
	$('#newsletter-signup').submit(function() {
		$.post('/newsletter-signup.php', $(this).serialize(), function(data) {
			if (data == 'Thanks for joining!') {
				$('#newsletter-signup input').hide();
			}
			$('p#result').html(data);
		});
		return false;
	});
	$('#newsletter-signup input.text').clearDefaultValue();

});
