Restructure and test

This separates `main.js` into smaller modules and adds some initial tests.  As part of this refactoring, the behavior handling new gallery image is improved.  Instead of the view count for a new image needing to "catch up" with already viewed images, new images are given a view count one below the minimum view count - meaning new images will be given preference only until they are viewed once.