function fadeImage(targetPicture, opacityChange, timeInterval) {
	//If it is the first time we are running the function...
	if (fading === undefined) {
		//Set the interval of the function
		fading = window.setInterval(function () {fadeImage(targetPicture, opacityChange, timeInterval);}, timeInterval);
	}

	//Check for a finished fade in, in this case we just want to end the function.
	if (opacity > 1.0 && opacityChange > 0) {
		//Take this time to switch backPic if at all.
		var backPic = document.getElementById("backPic");
		backPic.src = Pix[PicCurrentNum].src;
		
		//Done with the function, turn off the safety switch and unset the interval
		fading = window.clearInterval(fading);
		return false;
	}
	//If we are finished fading out we want to take this chance for chaning the current picture and incrementing to the next picture
	else if (opacity < 0.01 - opacityChange && opacityChange < 0) {
		opacity = 0;
		changeOpacity(targetPicture, opacity);
		//Now that the image is finished fading out we can change the actual picture
		targetPicture.src = Pix[PicCurrentNum].src;
		
		//Increment our picture and then check that we don\'t exceed Pix.length
		++PicCurrentNum;
		if (PicCurrentNum === howMany) {
			PicCurrentNum = 0;
		}
		
		//Clean up the function
		fading = window.clearInterval(fading);
		return true;
	}
	else {
		//Decrease the opacity by 5% and change it with our helper function.
		opacity += opacityChange;
		changeOpacity(targetPicture, opacity);
	}
}
function setBack(targetPicture) {
	//Make sure that fadeImage() isn\'t already running with out switch
	if (fading === undefined) {
		//If the image fades properly, fade it back in!
		if (fadeImage(targetPicture, -0.1, 35)) {
			fadeImage(targetPicture, 0.1, 35);
		}
	}
	else {
		//Do nothing and hope that the fade is complete by the next time this function is called.
	}
}
function startPix() {
	var targetPicture = document.getElementById("ChangingPix");
	add_event(targetPicture, "MouseOver", function () { fading = true;});
	add_event(targetPicture, "MouseOut", function () { fading = undefined; });
	document.getElementById("backPic").src = Pix[0].src;
	setInterval(function () { setBack(targetPicture);}, timeDelay);
}
