By "link directly to the image" do you mean that, when the user clicks on the image, you want it to open in a new window showing just the image??
If so, it's trivial:
Code:
<img id="mainImg"
src="images/gallery/1.jpg"
style=" border: solid #7d3d3d 5px;"
alt="galleryimage"
onclick="window.open(this.src,'FULLIMAGE','width=800,height=600');"
/>
The width/height/whether scrollbars show/etc. is all controlled by the third argument to window.open().
If you use '_blank' instead of 'FULLIMAGE' (or any other name), then each image opens in its own new window, instead of images reusing the same popup window. Usually, that's annoying, so I'd use a name instead. But up to you.