title: trying to get simple javascript gallery with next and previous buttons to loop back to the beginning
body: <p>im fairly new to javascript, but im basically trying to make a next/previous click through gallery. I've managed to find tutorials and bits to get images to click through. however i cant seem to work out how to return to the beginning of the series after the 4th(final) image. </p>
  
  <p>this is what i have so far-</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
   var photos=new Array()
   var which=0
   photos[0]='images/image1.jpg'
   photos[1]='images/image2.jpg'
   photos[2]='images/image3.jpg'
   photos[3]='images/image4.jpg'
  
   function backward(){
      if (which &gt; 0){
          which=which-1
          document.images.photoslider.src=photos[which]
      }
   }
  
   function forward(){
       if (which&lt;photos.length-1){
          which=which+1
          document.images.photoslider.src=photos[which]
       }
   }
  
   &lt;/script&gt;
  
   &lt;form&gt;
       &lt;input type="button" value="&amp;lt;&amp;lt;Back" onClick="backward()"&gt; 
       &lt;input type="button" value="Next&amp;gt;&amp;gt;" onClick="forward()"&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>essentially I want the buttons to create a continuous loop through the 4 images. I know there is going to be a simple solution I just cant see it. Any help would be great! 
  thank you in advance!</p>