Fix issue with multiple galleries on one page (#417)

See issue #417. This pull request includes a fix to use the correct thumbnail index in the `hashchange` event, even when there are multiple galleries on the page.