Kirupa PhotoGallery using XML tutorial

Hi,

I’m trying to customize a few things from the Kirupa Photogallery using XML tutorial.
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm
**
Two questions:**

  1. I wanna tweak this code so if you hit the next button on the last image, it loop back to this first image, and vice-versa, if you hit the previous button on the first image, it should go to the last image. I think its just tweaking these functions with a conditional statement but i can’t figure it out.

[COLOR=Navy]function nextImage() {

if (p<(total-1)) {
    p++;

    if (loaded == filesize) {

        picture._alpha = 0;
        picture.loadMovie(image[p],1);
        desc_txt.text = description[p];
        mat_txt.text = materials[p];
        picture_num();
        
    }

}

}
function prevImage() {

if (p>0) {
    
    p--;
    picture._alpha = 0;
    picture.loadMovie(image[p],1);
    desc_txt.text = description[p];
    mat_txt.text = materials[p];
    picture_num();
}

}
[/COLOR]
2) I’m planning to have larger jpgs viewed in an external HTML page so i’m going to make separate HTML pages for each image. How do I write the actionscript for a getURL that updates the image number corresponding with the XML variable [p], which is keeping track of the image number in the gallery in the tutorial?

For example, I tried doing this: +[p] in the code to make the image number update in the url address but alas it didn’t work.

[COLOR=Navy]viewlarger.onRelease = function() {
getURL(“http://www.craighein.net/images/large/” + [p], “_blank”);
};[/COLOR]

Any help is much appreciated!