title: Loading image in Jquery and bad behavior
body: <p>I have a little problem with a homemade script, first I'll give you the script</p>
  
  <pre><code>    var heighti = $(window).height();
  var imageLoading = new Array();
  $('.fullHeight').css({'height' : heighti});
      var now,hour,minute,second,dateNow = new Array(),countImg=0,i=0,countDateNow = 0;countImg=0,countThis=0,countDateNowAj=0;
          /* GET THIS HOUR */
          now = new Date();
          hour      = now.getHours();
          minute    = now.getMinutes();
          second    = now.getSeconds();
      function date(){
          //Function to get date
  }
  function loadImage(){
      countThis = 0;
      while(countThis &lt; 6){
      date();
      var imgOn = 'uploads/original/'+dateNow[countDateNowAj]+'.jpg';
      console.log(imgOn);
      var img = $("&lt;img /&gt;").attr('src', imgOn)
                    .load(function(){
                      imageLoading[i] = imgOn ;
                      i++;
                    })
                    .error(function(){
                    console.log('This is the image now : '+imgOn);
                      imageLoading[i] = 'images/noimage.jpg';
                      i++;
                    });
          countThis++;
          countDateNowAj++;
      }
  }
  
  
  setInterval("dateImg()",1000);
  setTimeout("loadImage()",0);
  setInterval("loadImage()",5000);
  </code></pre>
  
  <p>So this is my function, everything works but when I want to do <code>imageLoading[i] = imgOn;</code> the script take always the last value. </p>
  
  <p>This is a log of what I'm talking about : <a href="http://minus.com/mpWvBsXkQ" rel="nofollow">http://minus.com/mpWvBsXkQ</a></p>
  
  <p>First I check the time<br>
  After I check the image who is gonna be checked<br>
  And at the end I check the name of <code>imageLoading[i] = imgOn;</code>     </p>
  
  <p>And I always get the last time and not every second.</p>
  
  <p>I hope you'll understand my query.</p>