http://developer.apple.com/iphone/library/samplecode/WhichWayIsUp/index.html