var imageIndex = 0; var images = ["b","c","d","e","f","g","h","i","j"]; function nextImage() { imageIndex = (imageIndex+1)%images.length; $("#pearlPicture").get()[0].src = "image.php?id=2098&extraCode="+images[imageIndex]; $("#pearlPicture").load(function () { $(this).unbind("load"); setTimeout("nextImage()",4000); }); } $(document).ready(function () { $("#pearlPicture").load(function () { $(this).unbind("load"); setTimeout("nextImage()",4000); }); });