Hello Andy,
The URL of the site where you're using this would be useful so that we can understand your problem.
JavaScripts tend to be very verbose (big) and don't work if the user has JS turned off or unavailable, as is the case with text browsers (for the visually impaired) and search engines.
You might consider using CSS drop-down menus as an alternative. CSS is invariably enabled and is more accessible, and has a much lighter footprint.
Check out
A List Apart's article and the
SEO Consultants' page about CSS menus. There are others too but these two seem to be the most instructive.
Good luck