Better handling for window visibility's effect on sound

Use visibilitychange events if available; window.onfocus/onblur if not.