re-write gallery.js