jQuery.addScreenshotEntry = function(){
  currentId = $("#new_shopify_application .screenshots .screenshot").size() - 1;

  newEntry = $("#new_shopify_application .screenshots .screenshot:last").html();
  newEntry.html(newEntry.replace(/\[\d+\]/, "[" + (currentId + 1) + "]").replace(/(\d+)_image/g, (currentId + 1) + '_image'));

  $("#new_shopify_application .screenshots").append(newEntry);
};

jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

jQuery.fn.submitWithAjax = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

$(document).ready(function() {
  $("form#new_review").submitWithAjax();
  
  $("a.rjs").click( function() {
    $.ajax({
      url: this.href,
      dataType: "script",
      beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
    });
    return false;
  });
  
  $('a[rel*=facebox]').facebox();
  
});