Problem with modifying the photo gallery tutorial

After basing the gallery on the tutorial here:

http://www.kirupa.com/developer/mx/photogallery.htm

I have put 37 photos in the array and added some navigation that enables the user to view a specific photo in the sequence, rather than just scrolling through the whole sequence one by one using next and prev buttons. This is the code I used on each button:

on (release) {
_root.changePhoto(“2”);
}

The problem I am having is that this is calling the wrong photo. I suspect the problem is related to this part of the code from the tutorial:

this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {
	this.pIndex += this.pArray.length;
}

but I don’t really understand this bit of code. Any help would be greatly appreciated.

Ade.