title: window.setInterval possible scope issue?
body: <p>Thanks for taking the time to read this post. Finally built up enough courage to ask a question here :) Hope I ask my question in the correct way.</p>
  
  <p>My problem is that I am trying to randomly animate "squares" around a page but am having an issue with the setInterval method.</p>
  
  <p>You can find it here <a href="http://jsfiddle.net/xEMXh/" rel="nofollow">http://jsfiddle.net/xEMXh/</a></p>
  
  <p>In the Init function I am trying to go though each ghost element and set it a interval function that will then make it animate in a random direction every X seconds.</p>
  
  <pre><code>for (ghostCount = 0; ghostCount &lt; ghosts.length; ghostCount += 1) {
              var speed = LesMccutcheon.GhostHunter.GetSpeed($(ghosts[ghostCount]).attr('data-speed')),
                  activeGhost = ghosts[ghostCount];
              window.setInterval(function() {
                  LesMccutcheon.GhostHunter.MoveInDirection(activeGhost);
              }, speed);
          }
  </code></pre>
  
  <p>What is happening is only the last "ghost" element is animating. I know this is because in the for loop I am overriding the variable and by the time the first interval is called activeGhost is the last set in the for loop.</p>
  
  <p>I tried using <em>ghosts[ghostCount]</em> directly in the set.Interval but it seems set interval cannot access this. I tried setting it to a variable inside the set.Interval anom function but it logged as undefined. </p>
  
  <p>My only other half baked idea is to try and set an incremental var identifier but that seems quite counter productive and not a good way to go.</p>
  
  <p>Thanks in advance for any advice!</p>
  
  <p>Les</p>