// Randomise the background image

// make an array of background images
var bg_images = new Array(
	'/assets/backgrounds/bg001.jpg',
	'/assets/backgrounds/bg002.jpg',
	'/assets/backgrounds/bg003.jpg',
	'/assets/backgrounds/bg004.jpg',
	'/assets/backgrounds/bg005.jpg',
	'/assets/backgrounds/bg006.jpg',
	'/assets/backgrounds/bg007.jpg',
	'/assets/backgrounds/bg008.jpg'
);

// default background colour
var bg_color = '#990000';

// use this function to set the background image
function setBackgroundImage(num) {
	var total = bg_images.length;
	if (!num) { num = Math.floor(Math.random()*total); }
	if (num!=(total-1)) { nextNum = num + 1; }
	else { nextNum = 0; }
	
	// if the UA supports getElementById
	if (document.getElementById) {
		
		// find element #wrapper
		var wrapper = document.getElementById('wrapper');
		
		// apply the background colour
		wrapper.style.backgroundColor = bg_color;
		
		// apply the random image
		wrapper.style.backgroundImage = 'url(' + bg_images[num] + ')';
		
		// repeat and position styles
		wrapper.style.backgroundRepeat = 'no-repeat';
		wrapper.style.backgroundPosition = 'top right';
	}
}

// when the page loads set the background image
window.onload = function() {
	setBackgroundImage();
}
