(function($) {
  Drupal.behaviors.incubatorEventsPrintCalendar = {
    attach: function (context, settings) {
      $('#block-system-main .view-incubator-events').once('printable-calendar-processed', function() {
        $(this).before("<a href='#' id='show-printable-calendar'>" + Drupal.t("Print this calendar") + "</a>");
      });
      $('a#show-printable-calendar').click(function() {
        $("body").addClass('printable-calendar');
        $(window).trigger("resize");
        window.setTimeout(function() {
          window.print();
        }, 500);
        window.setTimeout(function() {
          $("body").removeClass('printable-calendar');
          $(window).trigger("resize");
        }, 1000);
      });
    }
  };
}(jQuery));
