Rewritten to support iPad (thanks to Olivier Larivain)