(function($) {
  Drupal.behaviors.incubatorEventsListings = {
    attach: function (context, settings) {
      $('.incubator-events-popups .views-field-title a').click(function() {
        $(this).closest('.views-row').find('.views-field-rendered-entity').addClass('show-event');
        return false;
      });
      $('.incubator-events-popups .views-field-rendered-entity').click(function() {
        $(this).removeClass('show-event');
      });
      $('.incubator-events-popups .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));
