This could be accomplished easily with CSS instead of altering PHP files.

#productMainImage already has a class (.centeredContent), but the id (#pi-left) has a float restricting the width of (#productMainImage), so setting the width of (#productMainImage) to 100% allows the built in class (.centeredContent) to center the image.

Code:
#productMainImage { width:100%; }
I'm not seeing an issue with the additional images unless you already fixed.