All right Big code change to your changeImage function, but once you do, you can add as many images as you'd like and do this. Never have to update the function or add another for this again, really.
function changeImage(imgID) {
i = document.getElementById(imgID);
state = i.getAttribute("state");
img1 = i.getAttribute("img1");
img2 = i.getAttribute("img2");
switch(state){
case "1":
i.src = src2;
i.setAttribute("state", "2");
break;
case "2":
i.src = src1;
i.setAttribute("state", "1");
}
// End function to change images
Now, there's that. It changes three things.. all in the img tag.
imgID is the id attribute in the image.
img1="imageSrc.jpg" // The src of the first image. Likely the same as the original src.
img2="imageSrc2.gif" // The alternate image src. Changed from the default.
state="1" // Always "1" at first, in the original code. This keeps track of which image is showing where.
Now, in the body, the tags for images look like this:
Hopefully that solves it! Good luck, and you can likely copy/paste the function I wrote there.
Should work for you.
See the working example at: http://test-drive.websby.tc/image-switcher-using-javascript/