[#435] added support for the visibilitychange API

also rewrite some code to avoid any conflicts between the legacy
blur/focus event and this one.