consolidated code for visitGallery controls