Help, Firefox messing up XML gallery

I’m using a code I got from kirupa. I basically have an xml gallery, and this resizes to the size of the picture loaded from the xml file. I have multiple xml files, for different categories. I have 5 categories, and I load different xmls for each frame. It works fine in Flash, and in Firefox, but unfortunately, for Safari and Firefox, there’s a glitch. What happens is if you switch to another category, instead of getting the dimension of the new picture in the new category, it will get the dimension of the next picture from the current category you’re viewing.

To better illustrate it:

Category 1, image 1, 200x200
Category 1, image 2, 300x300
Category 2, image 1, 100x50
Category 2, image 2, 200x70

You’re viewing Image 1 category 1, and you decide to go to Category 2, instead of the border resizing to 200x70, the border will resize to 300x300, and yet load the correct picture (200x70). The border follows the dimension of the wrong image, but loads the correct image anyway. It works fine in flash and in IE though. Has anyone encountered this before? Any suggestions?