Randomizing the XML Gallery thing

I used the tutorial for making a xml gallery and changed it up a bit to make a banner ad gallery from an xml file. This makes life easier for my non flash designers to just update the xml file when new ads come out. I would now like to make it randomly select the first image. Can anyone help. The only idea I had was to change the p = 0; part to p = Math.floor(Math.random() * total); That didn’t work.

There is some additional code in there for a coldfusion click tracker and some to build the url string for the coldfusion page.

Here is the code: HELP!!

// Load XML, define arrays, and initiate loading of first image

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
track = [];
adName = [];
destURL = [];
adTracker = xmlNode.firstChild.nextSibling.attributes[“url”];
total = xmlNode.firstChild.nextSibling.nextSibling.childNodes.length;

    for (i=0; i<total; i++) {
        image* = xmlNode.childNodes[2].childNodes*.childNodes[0].firstChild.nodeValue;
        track* = xmlNode.childNodes[2].childNodes*.childNodes[3].firstChild.nodeValue;
        adName* = xmlNode.childNodes[2].childNodes*.childNodes[2].firstChild.nodeValue;
        destURL* = xmlNode.childNodes[2].childNodes*.childNodes[1].firstChild.nodeValue;
    }
   
firstImage();
} 

else {
    content = "file not loaded!";
}

}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(_root.xmlpath);

// Functionality for keyboard navigation

listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
}

else if (Key.getCode() == Key.RIGHT) {
    nextImage();
}

};

Key.addListener(listen);

// Functionality for mouse navigation

previous_btn.onRelease = function() {
prevImage();
};

next_btn.onRelease = function() {
nextImage();
};

// Define p to zero to fix numbering issues

p = Math.floor(Math.random() * total);
// p = 0;

// Preloader for ads
this.onEnterFrame = function() {
filesize = adFrame.getBytesTotal();
loaded = adFrame.getBytesLoaded();
preloader._visible = true;

if (loaded != filesize) {
    preloader.preload_bar._xscale = 100*loaded/filesize;
}

else {
    preloader._visible = false;
    if (adFrame._alpha<100) {
        adFrame._alpha += 10;
    }
}

};

// Next Image Function

function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
adFrame._alpha = 0;
adFrame.loadMovie(image[p], 1);
linkHolder.onRelease = function () {
getURL (adTracker+"?t="+track[p]+"&n="+adName[p]+"&qs="+destURL[p]);
};
ads_num();
}
}
}

// Previous Image Function

function prevImage() {
if (p>0) {
p–;
adFrame._alpha = 0;
adFrame.loadMovie(image[p], 1);
linkHolder.onRelease = function () {
getURL (adTracker+"?t="+track[p]+"&n="+adName[p]+"&qs="+destURL[p]);
};
ads_num();
}
}

// Load first image automatically ADD RANDOM LOAD HERE?

function firstImage() {
if (loaded == filesize) {
adFrame._alpha = 0;
adFrame.loadMovie(image[0], 1);
linkHolder.onRelease = function () {
getURL (adTracker+"?t="+track[0]+"&n="+adName[0]+"&qs="+destURL[0]);
};
ads_num();
}
}

// Ad Numbering

function ads_num() {
current_pos = p+1;
}

Here is a link to the XML file if that helps.