The page is jumping around because you are using a fragment identifier. "#anchor1" will take you to an anchor named "anchor1" but just "#" will take you to the top of the page.
If you add "return false" to your onclick event, then only the JavaScript will be executed and the browser won't follow the link:
<a href="#" onclick="yourFunction(); return false;"><img src... etc></a>
Note that it's pretty bad for accessibility to have links with a href of just "#". The link should point to real content, thereby anyone without JavaScript, or using a screen reader can still view the page.
Ideally you'd have all your JS in an external file and an event handler to hook into the links and set your onclick events, but that might be a bit advanced for now!