var timerid = 0; var images = new Array( "image_1.png", "image_1.png", "image_2.png", "image_3.png", "image_4.png", "image_5.png", "image_6.png", "image_7.png", "image_8.png"); var countimages = 0; function startTime() { if(timerid) { timerid = 0; } var tDate = new Date(); if(countimages == images.length) { countimages = 0; } if(tDate.getSeconds() % 5 == 0) { document.getElementById("img1").src = images[countimages]; } countimages++; timerid = setTimeout("startTime()", 500); }