function runSlideShow(imageArray, ctrlId, transitionSpeed){
	blendimage(ctrlId,ctrlId + "img", preLoad[imageSlideIndex].src, preLoad[imageSlideIndex].alt, transitionSpeed);
	imageSlideIndex++;
	if (imageSlideIndex > (imageArray.length - 1)) {
		imageSlideIndex = 0;
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

var fading = null;
function blendimage(divid, imageid, imagefile, imagealt, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	// Do not allow a div to fade again when fading
	if (fading == divid) {
		return;
	}
	fading=divid;
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	//make image foreground image 100% transparent
	changeOpac(0, imageid);
	//change the foreground image to what the new one will be
	document.getElementById(imageid).src = imagefile;
	document.getElementById(imageid).alt = imagealt;

	//fade in the foreground image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpacWithBackground(" + i + ",'" + imageid + "','" + divid + "','" + imageid + "')",(timer * speed));
		timer++;
	}
}

function changeOpacWithBackground(opacity, id, divid, imageid) {
	if (opacity==100){
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	}
	changeOpac(opacity, id);
	if (opacity==100){ 
		fading=null;
	}
}

