generic function loop through time-intervarls, new jquery