replace setInterval by setTimeout javascript function