Wrap image open-close functionality in each loop