Possum,
The reason the OnClick function in JavaScript links to a php file instead of directly to an image file is usually done for one of two reasons.
You need to show more than just an image. This could be anything from a background color, navigation, info, whatever. In the case of the site you showed as an example, it looks like it was just for the black background and the title of the image, because there was nothing else on the page.
You need to do some kind of processing before showing the image. This could be anything from checking if the user has the right to see the file, logging the number of times a link is clicked, modifying the image, etc.
A php file is usually associated with outputting html, but you can also use a php script to load an image, do some processing to the image, and then output it as if it were just an image file (jpg, bmp, gif, png...etc). For example...let's say the images that are stored on the hard drive of the server are too big to display in a browser. I can link to a url like image.php?id=3456&max_width=600. The code in image.php could grab an image off the hard drive by finding it's path and filename in a database (using the id in the url), and then size it down based on the max_width variable I pass to the url, and then output it as just a plain old image.
There are many reasons you would link to a php file to display an image instead of linking directly to the image file. So, Weedpacket was right that the onClick part of it is done on the client, but as you'll find in most web development, the solution is quite often to use both client and server code.