Detect browser tab changes

In a recent project of mine I had some JavaScript animations using timers that were getting mucked up when you navigated away from the page by changing tabs, and then returning. After doing some research I found this great post about the HTML5 Visibility API that helped out my situation.

I took the code that was used in this tutorial and added a callback that could be used to restart the animation when visitors clicked away and returned.

You can check out the code here on github, and view a demo here.

Questions, comments, improvements?