(function($) {
  Drupal.behaviors.incubatorEventsListings = {
    attach: function (context, settings) {
      $('.view-incubator-events .views-field-title a, .view-incubator-regular-events .views-field-title a').click(function() {
        $(this).closest('.views-row').find('.views-field-rendered-entity').addClass('show-event');
        return false;
      });
      $('.view-incubator-events .views-field-rendered-entity, .view-incubator-regular-events .views-field-rendered-entity').click(function() {
        $(this).removeClass('show-event');
      });
      $('.view-incubator-events .views-field-rendered-entity .node, .view-incubator-regular-events .views-field-rendered-entity .node').click(function(event) {
        event.stopPropagation();
      }).once('closebox').after('<a class="incubator-events-closebox" href="#" title="Close" alt="Close">Close</a>');
      $('a.incubator-events-closebox').click(function() {
        $(this).closest('.views-field-rendered-entity').removeClass('show-event');
      });
    }
  };
}(jQuery));
