

var config = {
	slideShowTime: 5000,
	slideShowStart: 0
	}

//Function to pre-initialise some stuff (before the page has actually finished loading)
function preInit() {
	
	//Hide all images initially
	imgs = document.getElementById('hero').getElementsByTagName("img");
	for(i=0;i<imgs.length;i++) {
		imgs[i].xOpacity = 0;
		imgs[i].style.display = "none";
	}
	
	//And stick a spinner in the background
	document.getElementById('hero').style.background = "#fff url(/_common/images/loading.gif) 50% no-repeat";
}

//function to initialise the page
function init() {
	startImageRotation();
}

//Function to start image rotation
function startImageRotation() {
	//Get rid of the spinner again
	document.getElementById('hero').style.background = "#fff";
	
	//Set the opacity of the first image and start the crossfade function
	imgs = document.getElementById('hero').getElementsByTagName("img");
	imgs[config.slideShowStart].style.display = "block";
	imgs[config.slideShowStart].xOpacity = .99;
	setTimeout(so_xfade,config.slideShowTime);
}


//Image crossfades
//Courtesy (in part) of http://slayeroffice.com/code/imageCrossFade/xfade2.html

function so_xfade() {
	cOpacity = imgs[config.slideShowStart].xOpacity;
	nIndex = imgs[config.slideShowStart+1]?config.slideShowStart+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[config.slideShowStart].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[config.slideShowStart]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[config.slideShowStart].style.display = "none";
		config.slideShowStart = nIndex;
		setTimeout(so_xfade,config.slideShowTime);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}