execute a function after a given time or every n secondsFrom https://stackoverflow.com/questions/758688/sleep-in-javascript-delay-between-actionssleep js
function after(ms, fn){ setTimeout(fn, ms); }
//
function every(ms, fn){ setInterval(fn, ms); }
// another option
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
}