Multiple XML photo gallery thumbnails question

Hi, i’m looking for some quick help with my photo gallery

I have it set up to load multiple XML files, but, when you select a new book/xml, i want it the thumbnails to refresh starting with thumbnail #1, instead of wherever it left off in the array

this obviously has something to do with the variable k, but i am having a lot of trouble figuring out where to fix this at.

sorry if this is super obvious, and thanks in advance for your help!

// Buttons to call each Gallery and reload data

bookone_btn.onRelease = function() {
xmlURL = “book1.xml”; // sets xml file
xmlLoader(); // loads xml data
thumbnails_fnRemove(k); // clear old thumbnails
thumbnails_fn(k); // populate new thumbnails
};

booktwo_btn.onRelease = function() {
xmlURL = “book2.xml”; // sets xml file
xmlLoader(); // loads xml data
thumbnails_fnRemove(k); // clear old thumbnails
thumbnails_fn(k); // populate new thumbnails
};

portfolio_btn.onRelease = function() {
xmlURL = “book2.xml”; // sets xml file
xmlLoader(); // loads xml data
thumbnails_fnRemove(k); // clear old thumbnails
thumbnails_fn(k); // populate new thumbnails
};

//------------------------------------------------------

// load starting gallery xml
xmlURL = “book1.xml”;
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(xmlURL);

// function to call gallery xml after xmlURL stated by buttons
function xmlLoader() {
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.load(xmlURL);
xmlData.onLoad = loadXML;
};

delay = 1000;

var curLength;
function loadXML(loaded) {
//reset p
p = 0;
//remove old thumbs
for (var j = 0; j<curLength; j++) {
thumbnail_mc[“t”+j].removeMovieClip();
}
if (loaded) {
xmlNode = this.firstChild;
image = ;
thumbnails = ;
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
thumbnails* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
thumbnails_fn(i);

    }
    //changes
    firstImage();
    //set curLength
    curLength = total;        
} else {
    content = "file not loaded!";
}

}

//navigation for keyboards arrow keys
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
clearInterval(myInterval);
}
if (Key.getCode() == Key.RIGHT) {
nextImage();
clearInterval(myInterval);
}
if (Key.getCode() == Key.DOWN) {
clearInterval(myInterval);
slideshow();
}
if (Key.getCode() == Key.UP) {
clearInterval(myInterval);
}
};

//navigation for next/prev buttons
Key.addListener(listen);
previous_btn.onRelease = function() {
prevImage();
};
next_btn.onRelease = function() {
nextImage();
};
play_btn.onRelease = function() {
nextImageSlide();
};
pause_btn.onRelease = function() {
clearInterval(myInterval);
};

// image preloader
p = 0;
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 10;
}
}
};

var myInterval;

// next and previous image navigation
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
picture_num();
clearInterval(myInterval);
}
}
}

function nextImageSlide() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
picture_num();
clearInterval(myInterval);
slideshow();
}
}
}

function prevImage() {

clearInterval(myInterval);

slideshow();

if (p>0) {
p–;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
picture_num();
}
}

function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
picture_num();
clearInterval(myInterval);
}
}

function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}

function slideshow() {
myInterval = setInterval(pause_slideshow, delay);
function pause_slideshow() {
clearInterval(myInterval);
if (p == (total-1)) {
p = 0;
firstImage();
} else {
nextImageSlide();
}
}
}

function thumbNailScroller() {
// thumbnail code!
this.createEmptyMovieClip(“tscroller”, 504);
scroll_speed = 20;
tscroller.onEnterFrame = function() {
if ((_root._xmouse>=thumbnail_mc._x) && (_root._xmouse<=thumbnail_mc._x+thumbnail_mc._width)) {
if ((_root._ymouse>=(hit_right._y-120)) && (thumbnail_mc.hitTest(hit_right))) {
thumbnail_mc._y -= scroll_speed;
} else if ((_root._ymouse<=(hit_left._y+120)) && (thumbnail_mc.hitTest(hit_left))) {
thumbnail_mc._y += scroll_speed;
}
} else {
delete tscroller.onEnterFrame;
}
};
}

// function to clear thumbnails from scroller ready for ready for loaded xml data
function thumbnails_fnRemove(k) {
target_mc.removeMovieClip();
removeMovieClip(thumbnail_mc.t(+k));

}

// function to load new thumnails into scroller from loaded xml
function thumbnails_fn(k) {
thumbnail_mc.createEmptyMovieClip(“t”+k, thumbnail_mc.getNextHighestDepth());
tlistener = new Object();
tlistener.onLoadInit = function(target_mc) {
target_mc._y = hit_left._y-117+(target_mc._height+5)*k;

target_mc.pictureValue = k;
target_mc.onRelease = function() {
p = this.pictureValue-1;
nextImage();
};
target_mc.onRollOver = function() {
this._alpha = 50;
thumbNailScroller();
};
target_mc.onRollOut = function() {
this._alpha = 100;
};
};
image_mcl = new MovieClipLoader();
image_mcl.addListener(tlistener);
image_mcl.loadClip(thumbnails[k], “thumbnail_mc.t”+k);
}