popup gallery js refactoring and html reflections of that