Weird things happen when you put something you don't understand something else you may not understand either. For example:

for (var i = 1; i <= 4; i++) {
   setTimeout(function() { console.log(i); }, 1000*i); // 5 5 5 5 
}

Weird right? 

So, this is what I did, 

function run_timeout(i){
   setTimeout(function(){ console.log(i); }, delay);
}

for(var i = 0; i <= 4; i++){ run_timeout(i); }