$(function () {
	var body =  $('body');
	// Create an overlay to capture click events that happen off of the signup form.
	var clickOverlay = $('<div>&nbsp;</div>').css({
		height: body.height(),
		width: body.width()
	}).attr('id', 'newsletter-signup-overlay');

	//functions declared as local variables so they don't pollute global namespace
	var hideSignup = function (event) {
		$('#signup-form').hide();
		$('#newsletter-signup').css({backgroundColor: 'transparent'});
		clickOverlay.remove();
		$.cookie('signup-seenit', 'true')
	}
	var showSignup = function (event) {
		$('#signup-form').show();
		$('#newsletter-signup').css({backgroundColor: '#653614'});
		clickOverlay.appendTo(body).bind('click', hideSignup); // hide signup when they click off of it.
		return false;
	}
	
	//Bind events to appropriate links.
	$('#signup-link').bind('click', showSignup).append(' &darr;');
	$('#signup-close').bind('click', hideSignup);
	
	//Make the 'Email Address' label in the input field dissapear and reappear when appropriate.
	$('#signup-form input').bind(
		'focus', 
		function () {
			if(this.value=='Email Address'){
				this.value='';
				this.style.color='#000';
			}						
		}
	).bind(
		'blur',
		function () {
			if(this.value==''){
				this.value='Email Address';
				this.style.color='#aaa';
			}
		}
	).trigger('blur');
	//Show the signup form automatically if they've never seen it before.
	if ($.cookie('signup-seenit')!='true') {
		showSignup();
	}
});
