Hey Maz,
I have to roll on home in a minute, so I'll post this, assuming that you want a random image in a menu item (if not, we'll try again tomorrow):
Suppose you have three images you want to rotate through: egg0.gif, egg1.gif, and egg2.gif. The base name, "egg" in this example, can be anything, but the numbers must start at zero and be consecutive, and they must all be of the same file type (.gif in this case). The following function would randomly select from the three files mentioned above:
Code: Select all
function getRandomImage()
{
var upperLimit = 2;
var imagePath = "";
var baseName = "egg";
var imageType = ".gif";
var randomNum = Math.round(Math.random()*upperLimit);
var fileName = imagePath + baseName + randomNum + imageType;
return fileName;
}
You could put the function at the top of your menu_data.js file. There are four user-defined parameters at the top of the function. Edit them to fit your situation:
upperLimit = how many images minus 1. In the example at the top, there are three images, so upperLimit = 2, generating random numbes from 0 through 2.
imagePath = where your images are stored, up through the last / that would be in front of the image name. Leave it set to "" (blank) if the images are in the same directory as the page.
baseName = the base name of your image files, up to the number. In the example given at the top, the baseName = "egg".
imageType = the file type of the image files; ".gif" in the example at the top (don't forget the dot!).
To include the random image in a menu item, define the item like so:
Code: Select all
aI("text=item Text;url=whatever.htm;image="+getRandomImage()+";status=whatever;");
Insert menu item properties as usual. In this example, each time the page is loaded, the menu item will randomly show egg0.gif, egg1.gif, or egg2.gif.
The function could be modified to work with multiple menu items, selecting from multiple image "sets".
Hope that helps,
Kevin