// Ensures AJAX requests are properly formated so that Rails knows how to respond to them.
$.ajaxSetup({
  beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});

/* Ensures AJAX requests have the proper Rails authenticity token.  See the following
   for more info:

   http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery
   http://dev.jquery.com/ticket/3387
*/
$(document).ajaxSend(function(event, request, settings){
  var authToken = "<%= form_authenticity_token %>";
  if (authToken != null) {
    settings.data = settings.data || '';
    settings.data += (settings.data ? "&" : '') + "authenticity_token=" + encodeURIComponent(authToken);
  };
});