Uncaught TypeErrors on page change

Uncaught TypeErrors on page change

I'm loading a PhotoSwipe gallery inside a (virtual) "page" using jQuery mobile:

i4ideas.webfactional.com/gallery.html

(No external dependencies, all libraries loaded so you can view the source or grab the page)

The issue is that the gallery doesn't seem to close on page change and it throws errors each time. This is the console log of:

  1. Loading the page
  2. Opening first gallery
  3. Clicking back button
  4. Opening second gallery

enter image description here

.. so apparently, Gallery #1 never closes and Gallery #2 is loaded twice.