I'm trying to figure out how to run code based on an event handler. Here's what I have:

(function ($, Drupal, window, document, undefined) {
$(window).on("backstretch.before", function (e, instance, index) {
  // If we wanted to stop the slideshow after it reached the end
  if (index === instance.images.length - 1) {
    instance.pause();
  };
});})(jQuery, Drupal, this, this.document);

However, somehow the event doesn't fire. Is there something I'm doing wrong? Thanks in Advance.