Nit: it would be cleaner to have the overlay-menu code here in the if statement as well.  That is how you do it below for the empty gallery case, and I think you should do it that way here, also.