Update gallery.js

JsHint says: path is out of scope so here is a better use with $.each loop