This is a simplified version of the example for Complex Menu Positioning.
You can view the relevant source code: