var initFunctions = Array(0);

function addToOnLoad(functionName) {
	initFunctions[initFunctions.length] = functionName;
}

function init()  {
	for (var f = 0;f < initFunctions.length;f++) {
		eval(initFunctions[f] + "()");
	}	
}

window.onload=init;


// make array of bg image source files
var bgArray = new Array();
var totalbgs = 26;
// will need to know how many bg images there are and adjust n< ... accordingly
for (var n=0; n<totalbgs; n++) {
	bgArray[n] = "static/img/childs/untitled_" + (n+1) + ".jpg";
}

//preload the bg images
var preloadIm = new Array(bgArray.length);
for (var i=0; i<bgArray.length ; i++) {
	preloadIm[i] = new Image(315,316);
	preloadIm[i].src=bgArray[i];
}

//make an array of the template colours
var colourArray = new Array();
colourArray[0] = "green";
colourArray[1] = "brown";
colourArray[2] = "orange";
colourArray[3] = "rose";
colourArray[4] = "purple";



function loadBG() {
	col = "";
	randnum=Math.round(Math.random()*(totalbgs-1));
	for (var x=0; x<colourArray.length ; x++) {
		if (document.getElementById(colourArray[x])!=null) {
			col=colourArray[x];
			break;
		}
	}
	
	document.getElementById(col).style.background="url(" + preloadIm[randnum].src + ") 105% -15px no-repeat";
}


addToOnLoad ("loadBG");