Improved event handling.

Now events are only registered for elements that are available for user
interaction, and unique elements (such as most of the header buttons)
are explicitly registered. The less the browser has to keep track of at
once, the better.

Also, clicking outside of menus now closes them.