function fadingImg()
{
	var theDiv = (arguments[0]);
	var fadeToColor = arguments[1] ? arguments[1] : "#000";
	var imageWidth = arguments[2] ? arguments[2] + "px" : null;
	var imageHeight = arguments[3] ? arguments[3] + "px" : null;
	var opacity = 100;
	var opacityChangeRate = 3;
	var fadeLimit = 60;
	var isHovering = false;
	var hoverFunc;
	
	var makeBackdrop = function(fadingImg)
	{
		// Copy some important data that will be overwritten
		var fadingImgCopy = fadingImg.cloneNode(true);
		var backgroundDiv = document.createElement("div");
		var parent = fadingImg.parentNode;
		var fadingImgId = fadingImg.id;
		var backgroundDivId = fadingImgId + "Background";
		
		var fadingImgHeight = imageHeight ? imageHeight : fadingImg.offsetHeight;
		var fadingImgWidth = imageWidth ? imageWidth : fadingImg.offsetWidth;
		
		// Swap out the image for the background its background
		parent.replaceChild(backgroundDiv, fadingImg);
		
		// Copy some dimensions of image to the background
		backgroundDiv.style.width = fadingImgWidth + "px";
		backgroundDiv.style.height = fadingImgHeight + "px";
		
		backgroundDiv.style.background = fadeToColor;
		
		// Drop the image on top of the background
		backgroundDiv.appendChild(fadingImgCopy);
		
		// Update the pointer to theDiv
		theDiv = document.getElementById(fadingImgCopy.id);
	};
	
	
	var loadEvent = function()
	{	
		restoreImageData();
		
		if (imageWidth)
			theDiv.width = imageWidth;
			
		if (imageHeight)
			theDiv.height = imageHeight;
			
		// Get the ID here due to scope
		theDiv = document.getElementById(theDiv);

		// Put theDiv on a solid color background
		makeBackdrop(theDiv);
		
		hoverFunc = theDiv.id + "FadeHover";
		
		// 33 is 1000/30, or 30 frames per second.
		setTimeout("document." + hoverFunc + "()", 33);
		
		theDiv.onmouseover = function()
		{	
			isHovering = true;
		};
		
		theDiv.onmouseout = function()
		{
			isHovering = false;
		};
		
		document[hoverFunc] = function()
		{	
			if (isHovering)
				opacity -= opacityChangeRate;
			else
				opacity += opacityChangeRate;
			
			theDiv.style.opacity = opacity / 100; // Useful browsers
			theDiv.style.filter = "alpha(opacity = " + opacity + ")"; // IE
			
			// Keep opacity in a safe range
			if (opacity > 100)
				opacity = 100;
				
			if (opacity < fadeLimit)
				opacity  = fadeLimit;
			
			
			// Reset the callback to loop indefinitely
			setTimeout("document." + hoverFunc + "()", 33);
		};
		
	};
	
	// Tack on the above function onto the window's onload event
	addLoadEvent(loadEvent);
}