Setinterval(loop,stop) problem

Hi there,

I added a setinterval function to my slideshow.Prob is when the slideshow reaches the last pic it returns to pic1 goes to pic2,… but after the second loop it starts mixing the wrong pics for the wrong number.I guess I did a mistake in the if statement(if (nextSlideNode == null)…). can someone solve this for me.

See following code below. Also how can I stop this animation. I did something like clearinterval(advance); but that did not do the trick. Any help would be appreciated.Grtz

setInterval(advance, 5000);
function advance(nextSlideNode) {
nextSlideNode = currentSlideNode.nextSibling;

if (nextSlideNode == null) { //this should make the loop
updateSlide(firstSlideNode);
rootNode = slides_xml.firstChild;
firstSlideNode = rootNode.firstChild;
currentSlideNode = firstSlideNode;
firstSlideNode = firstSlideNode.nextSibling;
currentIndex = 1;
} else {
currentIndex++;
updateSlide(nextSlideNode);
currentSlideNode = nextSlideNode;
}
}