// JavaScript to interpolate random images into a page.
var ic = 3;										// Number of alternative images
var i = new Array(ic);				// Array to hold filenames
var j = new Array(ic);				// Array to hold descriptions

// Set up the images. These are GIFs, but they don't have to be. You could also save space in your file by including the unchanging part of the image filename (i.e. 'inline/imageSample' and '.gif') in the 'writeln' statement below, and just storing the part of the image name that actually changes. Used this way you could reference a very large number of different images while keeping the file size small.
i[0] = "images/home_top_left_1.jpg";
j[0] = "images/home_top_right_1.jpg";
i[1] = "images/home_top_left_2.jpg";
j[1] = "images/home_top_right_2.jpg";
i[2] = "images/home_top_left_3.jpg";
j[2] = "images/home_top_right_3.jpg";

// pickRandom - Return a random number in a given range. If we're running on an older browser that doesn't support 'Math.random()', we can fake it by using the current time. This isn't ideal for mission-critical security applications, but it's fine here. Note that we divide the current time by 1000 to get rid of the milliseconds which Navigator doesn't seem to take into account.
function pickRandom(range) {
	if (Math.random)
		return Math.round(Math.random() * (range-1));
	else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

// Write out an IMG tag, using a randomly-chosen image name.
function getrandomimage(){
	var choice = pickRandom(ic);
	//document.getElementById("i_image").setAttribute("style","background-image: url(" + i[choice] + ");");
	//document.getElementById("j_image").setAttribute("style","background-image: url(" + j[choice] + ");");
	
	//document.getElementById("i_image").setAttribute("background",i[choice]);
	//document.getElementById("j_image").setAttribute("background",j[choice]);
	
	//document.getElementById("i_image").style = "background-image: url(" + i[choice] + ")";
	//document.getElementById("j_image").style = "background-image: url(" + j[choice] + ")";
	
	document.getElementById("i_image").style.cssText = "background:url(" + i[choice] + ");";
	document.getElementById("j_image").style.cssText = "background:url(" + j[choice] + ");";
}