Autodetection if site is viewed on Iphone or ipad

Here is the mission I am after.

On the sites I work on we use a flash centerpiece and when you view these sites on Iphone or Ipad you can’t see the flash stuff obviously. A puzzle comes up.

I would like to add javascript code to my pages that if the FLASH PLAYER is not there or better yet if you are viewing this website on an iphone or ipad use this html5 centerpiece.

Anyone ever done this or has an idea of what approach to take?