Change branch/menu selection from PHP to JS

Now we only build the (entire) tree one single time and select the
branches by digging in the tree using JS.