Some improvements to the sidebar TOC and other links

This takes into account the possibility of a thin sidebar of may be a long content item in the contents listing.

I've also re-factored some of the stuff and removed some CSS from being inline to being in a separate file that is added to the head section as part of the view.