function setupOverlay(overlay) {
    // Close the overlay on clicking any of the pages' close buttons.
    let closeButtons = overlay.querySelectorAll('.page > .close-button');
    for (let i = 0; i < closeButtons.length; i++) {
      closeButtons[i].addEventListener('click', function () {
        cr.dispatchSimpleEvent(overlay, 'cancelOverlay');
      });
    }

    // Remove the 'pulse' animation any time the overlay is hidden or shown.
    overlay.__defineSetter__('hidden', function (value) {
      this.classList.remove('pulse');
      if (value) this.setAttribute('hidden', true);
      else this.removeAttribute('hidden');
    });
    overlay.__defineGetter__('hidden', function () {
      return this.hasAttribute('hidden');
    });

    // Shake when the user clicks away.
    overlay.addEventListener('click', function () {
      // This may be null while the overlay is closing.
      let overlayPage = this.querySelector('.page:not([hidden])');
      if (overlayPage) overlayPage.classList.add('pulse');
    });
  }
Adds behavioral hooks for the given overlay.
@param {HTMLElement} overlay The .overlay.