title: Javascript slideshow select "next" image confusion
body: <p>I'm very new to javascript. the following code works fine. when I click "next" button the slideshow stops how it should do but when clicking to show previous image it shows only one picture and stops? I can't get what is wrong. help me please</p>
  
  <pre><code>window.onload = function () {
  
      newImg = new Array("images/image1.jpg", "images/image2.jpg", "images/image3.jpg", "images/image4.jpg");
  
      var iImage = 1;
  
      var imgTimer = new Timer();
      imgTimer.Interval = 5000;
      imgTimer.Tick = function () {
          document.slideshow.src = newImg[iImage];
          iImage++
          if (iImage &gt;= newImg.length) {
              iImage = 0;
          }
  
          document.getElementById('next').onclick = function () {
              if (iImage &lt; newImg.length) {
                  document.slideshow.src = newImg[iImage];
                  iImage++
                  if (iImage = newImg.length) {
                      iImage = 0;
  
                  }
              }
              imgTimer.Stop();
          }
          document.getElementById('prev').onclick = function () {
              if (iImage &gt; 0) {
                  document.slideshow.src = newImg[iImage];
                  iImage--
                  if (iImage = 0) {
                      iImage = newImg.length;
                  }
              }
              imgTimer.Stop();
          }
  
  
      };
      imgTimer.Start();
  };
  </code></pre>