The next and prev button closes the image if you have viewed all images before/after the currently displayed image and you attempt go back/forward using the prev or next links.
I think... closing the image if you're at the last image and click next would be expected; closing the image if you're at the first image and click prev would be expected; in every other case, the next and prev button should move forward or backward one image, even if you have already viewed all images.
Regards