title: Why isn't javascript recognizing my global variable?
body: <p>I'm setting a variable equal to an image and then calling it in a function.
  This does not work because according to the javascript error console it doesn't recognize the image variable as anything but null</p>
  
  <pre><code>var image = document.getElementById("gc");
  var duration = 3000; /* fade duration in millisecond */
  var hidtime = 2000; /* time to stay hidden */
  var showtime = 2000; /* time to stay visible */
  var image_tracker = 1
  
  function change() {
      if (image_tracker == 1) {
          image.src = "IMG_1267.jpg"
          image_tracker = 2
      } else if (image_tracker == 2) {
          image.src = "IMG_1239.jpg"
          image_tracker = 3
      } else {
          image.src = "IMG_1263.jpg"
          image_tracker = 1
      }
  }
  </code></pre>
  
  <p>However this works fine</p>
  
  <pre><code>var duration = 3000; /* fade duration in millisecond */
  var hidtime = 2000; /* time to stay hidden */
  var showtime = 2000; /* time to stay visible */
  var image_tracker = 1
  
  function change() {
  
      var image = document.getElementById("gc");
  
      if (image_tracker == 1) {
  
          image.src = "IMG_1267.jpg"
          image_tracker = 2
      } else if (image_tracker == 2) {
          image.src = "IMG_1239.jpg"
          image_tracker = 3
      } else {
  
          image.src = "IMG_1263.jpg"
          image_tracker = 1
      }
  
  }
  
  var timer = setInterval('change()', 3000);
  </code></pre>