Items in task, plus:

* fixed the scrolling behavior of the legend
* several hard-coded js html bits were moved to be html templates.