Check whether image is wrapped inside a link so next/previous buttons work

In the next and prev functions, I added a ternary operator to check whether the image has a parent "a" tag and modified the next_img and prev_img variables if it does. This makes it so that the left and right arrows work properly when the image is inside a link.