saw a code in the internet and translated it for beginners
<script type="text/javascript">
var a=0;
var t;
var counter=0
function runone()
{
a=a+1;
t=setTimeout("runone()",500);
two();
}
function runtwo()
{
i=a%32;
runthree();
}
function stopit()
{
clearTimeout(t);
counter=0;
}
function runthree()
{
if(i==1)
{
document.getElementById('b1').src="first.jpg";
}
else if (i==2)
{
document.getElementById('b1').src="second.jpg";
}
else if (i==3)
{
document.getElementById('b1').src="third.jpg";
}
else if (i==4)
{
document.getElementById('b1').src="fourth.jpg";
}
else if (i==5)
{
document.getElementById('b1').src="fifth.jpg";
}
else if (i==6)
{
document.getElementById('b1').src="sixth.jpg";
}
else if (i==7)
{
document.getElementById('b1').src="seventh.jpg";
}
else if (i==8)
{
document.getElementById('b1').src="eighth.jpg";
}
else if (i==9)
{
document.getElementById('b1').src="ninth.jpg";
}
else if (i==10)
{
document.getElementById('b1').src="tenth.jpg";
}
else
{
document.getElementById('b1').src="eleventh.jpg";
}
}
</script>
works for me. comment if ther's anything wrong.