var email_message = 'Enter your email address...';

// This sets up the proper header for rails to understand the request type,
// and therefore properly respond to js requests (via respond_to block, for example)
$.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

$(document).ready(function() {

  // UJS authenticity token fix: add the authenticy_token parameter
  // expected by any Rails POST request.
  $(document).ajaxSend(function(event, request, settings) {
    // do nothing if this is a GET request. Rails doesn't need
    // the authenticity token, and IE converts the request method
    // to POST, just because - with love from redmond.
    if (settings.type == 'GET') return;
    if (typeof(AUTH_TOKEN) == "undefined") return;
    settings.data = settings.data || "";
    settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
  });

	// this handles the search box message when it's focused and unfocused (on blur)
	$('#emailaddress').focus(function() {
		if($(this).attr("value") == email_message) {
			$(this).attr("value", '');
		}
	});
	
	$('#emailaddress').blur(function() {
		if($(this).attr("value") == '') {
			$(this).attr("value", email_message);
		}
	});
	
	$('#emailsubscribe').submit(function (){
	  $.post($(this).attr('action'), $(this).serialize(), null, "script");
	  return false;
	});


});
