	//  This file got a little hacky after I put in all the crap to make IE work.  I guess not so much hacky as just messy since I had to do an if/else statement for each opacity operation
	// I may move them to separate files downloaded depending on browser later, but for now it's not that bad, and it works.
	
	var faders = new Array();
	var opacityregex = /\d\d?\d?.?\d?\d?/;
	var notIE = !(document.all && !window.opera);
	
	var currentImage = 0;
	var timeBetweenImages = 5000;
	var imageFadeSpeed = 800;
	var currZIndex = 1;
	
	function startFading(){
		setTimeout("fadeNextImage()", timeBetweenImages);
	}
	
	
	function fadeNextImage(){
		var toFadeOut = document.getElementById('fadingPic' + currentImage);
		if(!toFadeOut)
		return;
		
		initFadeElement(('fadingPic' + currentImage), imageFadeSpeed, 0.0, 1.0, false);
		
		currentImage++;
		var toFadeIn = document.getElementById('fadingPic' + currentImage);
		if(!toFadeIn)
		currentImage = 0;
		
		var toFadeIn = document.getElementById('fadingPic' + currentImage);
		
		currZIndex++;
		initFadeElement(('fadingPic' + currentImage), imageFadeSpeed, 1.0, 0.0, false);
		toFadeIn.style.zIndex = currZIndex;
		toFadeIn.style.display = '';
		setTimeout("fadeNextImage()", timeBetweenImages);
	}
	
	// Searches the pool of faders for one that is open and returns it, if none are open, it adds a new one to the pool and returns that.
	function getOpenFaderObject(){
		// If the array of faders is empty, add a new one to it.
		if(faders.length == 0)
		faders[faders.length++] = new Object();
		
		// Go through all the objects in the list trying to find one that is available.
		for(var f in faders){
			if(faders[f].stepsleft < 2){
				faders[f] = new Object();
				return f;
			}
		}
		
		// If none is available (wasn't returned in the check above) add a new one and return it.
		faders[faders.length++] = new Object();
		return (faders.length - 1);
	}
	
	
	function stopFade(fadenum){
		clearTimeout(faders[fadenum].timeout);
		
		if(!notIE)
		faders[fadenum].element.style.filter	= null;
		
		faders[fadenum].stepsleft = 0; // Returns the fader to the pool.
		faders[fadenum].element = "";

		if(faders[fadenum].onfinished != null)
		eval(faders[fadenum].onfinished);
	}
		
	
	function fadeElement(fadenum){
		var testob = faders[fadenum].element.style;

		if(notIE) // Not IE
		faders[fadenum].element.style.opacity = (parseFloat(faders[fadenum].element.style.opacity) + faders[fadenum].opacityperstep);
		else // IE
		faders[fadenum].element.style.filter = "alpha(opacity=" + (parseFloat(faders[fadenum].element.style.filter.match(opacityregex)) + parseFloat(faders[fadenum].opacityperstep)) + ")";
		
		faders[fadenum].stepsleft--;
		
		if(faders[fadenum].stepsleft < 2){
			if(notIE) // Not IE
			faders[fadenum].element.style.opacity = faders[fadenum].targetopacity;
			else // IE
			faders[fadenum].element.style.filter = "alpha(opacity=" + (faders[fadenum].targetopacity) + ")";
			
			if(faders[fadenum].targetopacity == 0)
			faders[fadenum].element.style.display = 'none';
			stopFade(fadenum);
			return;
		}
		
		faders[fadenum].timeout = setTimeout("fadeElement(" + fadenum + ")", 33);
	}
	
	
	function checkAlreadyFading(targetid){
		if(faders.length == 0)
		return false;
		
		var checkelem = document.getElementById(targetid);
		
		for(var f in faders){
			if(faders[f].element == checkelem)
			return f;
		}
		
		return false;
	}
	

	// targetid = element to fade;   timetofade = in ms;  callback = string to eval() upon completion of the fade
	function initFadeElement(targetid, timetofade, targetopacity, startopacity, callback){
		var already = checkAlreadyFading(targetid);
		if(already){		// If the element is already involved in a fade, cancel.
			stopFade(already);
			if(notIE) // Not IE
			startopacity = document.getElementById(targetid).style.opacity;
			else // IE
			startopacity = parseFloat(document.getElementById(targetid).style.filter.match(opacityregex));
		}
		
		var fadenum = getOpenFaderObject();
		
		faders[fadenum].element = document.getElementById(targetid);
		if(faders[fadenum].element == null){  // Checks to make sure a valid id was submitted.
			faders[fadenum].stepsleft = 0; // Returns the fader to the pool.
			return;
		}
		
		if(notIE) // Not IE
		faders[fadenum].targetopacity = targetopacity;
		else // IE
		faders[fadenum].targetopacity = (targetopacity * 100.0);
		
		if(targetopacity > 0)
		faders[fadenum].element.style.display = '';
		
		if(callback != null && typeof(callback) == "string")
		faders[fadenum].onfinished = callback;

		if(notIE){ // Not IE
			if(!faders[fadenum].element.style.opacity)
			faders[fadenum].element.style.opacity = 0.0;
		}
		else{ // IE
			if(faders[fadenum].element.style.filter == "")
			faders[fadenum].element.style.filter= "alpha(opacity=0)";
		}
		
		if(!notIE) // IE
		faders[fadenum].element.style.zoom = "1"; // IE hasLayout hack
		
		if(startopacity != null){
			if(notIE) // Not IE
			faders[fadenum].element.style.opacity = startopacity;
			else // IE
			faders[fadenum].element.style.filter = "alpha(opacity=" + (startopacity * 100.0) + ")";
		}
		
		faders[fadenum].stepsleft = Math.round(timetofade / 33.0);  // 33 = 30 FPS ... (1000 / 33) = 30 FPS
		
		if(notIE) // Not IE
		faders[fadenum].opacityperstep = (targetopacity - faders[fadenum].element.style.opacity) / faders[fadenum].stepsleft;
		else
		faders[fadenum].opacityperstep = (faders[fadenum].targetopacity - parseFloat(faders[fadenum].element.style.filter.match(opacityregex))) / faders[fadenum].stepsleft;

		fadeElement(fadenum);
	}