refactored gallery js for separate function for arrow clicked