Looping Rhamej xml gallery/slideshow

I would like to make the xml thumbnails loop from the last photo to the first photo (when pressing the Next button while viewing the last image) and also do the same for the prev button.
It is for the thumbnails scroller, this is the code:
//button actions
scroller.nextBtn.onRelease = function() {
var m:Number = pictures.length;
var buts:MovieClip = scroller.container[“thumb”+(m-1)];
if (clickCount<howMclick) {
clickCount++;
frwrd = true;
slideMain();
}
};
scroller.prevBtn.onRelease = function() {
var buts:MovieClip = scroller.container[“thumb”+0];
if (clickCount != 0) {
clickCount–;
frwrd = false;
slideMain();
}
};
I’ ve tried everything but i can’t find the solution.
Thanks a lot
Max