
// Rotate the background image of any element with an ID, where the images are named alike; with a name
// followed by a number (i.e. image1.gif, image2.gif, etc.)
function rotateImageRandomly(elementId, imagePath, imageName, numImages){
	// locate the element which background image will be rotated
	var element 		= document.getElementById(elementId);

	// generate a random number to determine which image should display
	var randomNumber 	= (Math.floor(Math.random() * numImages)) + 1;

	// truncate the file extension and number
	var name			= imageName.substring(0, imageName.length-4);
	name				= name.replace(/\d/g, "");
	var extension 		= imageName.substring(imageName.length-4, imageName.length);

	// set the background image path
	var source			= imagePath + name + randomNumber + extension;
	element.style.backgroundImage = "url(" + source + ")";
}