Self generating menu script.

Can anyone please help with what I’m trying to achieve below??

Some info about the website layout first:
I have my index.html containing 2 iframes.
I have my main (java script) menu in iframe 1 (that works great) on the left hand side of my page, which loads html pages into my second iframe on the right hand side.
Each loaded page contains its own ‘submenu’.
(From page to page the amount of links on the submenus vary).

I am after finding a self generating menu script, that will:
- 01. Know that the loaded page has so many sub pages, and in knowing so, will generate the appropriate number of menu links.
- 02. Do the above preferably by reading a designated directory, in relation to the actual page loaded.

So simply put:
I’m trying to find a single self generating sub-menu system that will change the links (and amount of links) it shows on every individual page load.

Hope someone can help.
Many thanks
T.

See diagram below: