Hi Tony Webb,
i would recommend you to use either AllWebMenus (Sliding Menu) or Likno Web Accordion Builder. You can find both in http://www.likno.com. This way you don't need to write your own...