JS - Image Rotator?

Advert test
Hi all.

I have a javascript code that is saved as a .JPG file, which scans the directory it is placed in, and displays a random image from that directory everytime the page is refreshed:

$dh = opendir(".");
while (false !== ($file = readdir($dh))) 
  if (preg_match('/\.jpg$/i', $file) and $file != "avatar.jpg") // sanning for .jpg files only and stopping avatar.jpg being loaded (you will run into errors if this isnt here)
     $filelist[] = $file;
$picnum = rand(0, sizeof($filelist) - 1);
header("Location: " . $filelist[$picnum]);
I was wondering, could anyone edit this script to that it rotates through the images in the directory say every 6 or 7 seconds?

Thanks in advance, any questions, just ask.