// PNG transparency fix HIGHLY modified by Hansel Escobal - 2/1/2005
// Use:
// Call from a linked Script tag in the HEAD section of the page. e.g: "<script type="text/javascript" src="pngfix_new.js"></script>"
// This script will run only after the page has finished loading. That way it will know how many images are in the image array.

function allofus()
{

needHack()

if (needHack() == false)
{
	
	
} else {
	
	//function correctPNG()
	//{	// Loop through the images on the page
		for(var i=0; i<document.images.length; i++)
		{
		//DEBUG: document.images[i].name = "image" + i;
		
		element = document.images[i];
		//DEBUG: alert(element.name);
		
		// If the image is a PNG, run the pngHack() function
		if (element.src.indexOf("png") > 0) 
			{
			pngHack();
			}
		}
		
	function pngHack()
	{
		
		var src = element.src;
		// If the image has a Height defined in Style, use this, if not, use the height of the image.
		if ((element.style.height) == -1) {
			iheight = element.style.height;
			
		} else {
			iheight = element.height;
		}
		
		if ((element.style.width) == -1) {
			iwidth = element.style.width;
			
		} else {
			iwidth = element.width;
		}
		
		var transparentImage = "http://www.ifriends.net/transparent.gif";
		
		if (src.indexOf(transparentImage) != -1)
			return; // Already fixed
	
		if (src.indexOf("png") == -1) 
		{
			element.style.filter = "";
			return;
		}
		//This is the meat of the script: We now add the transparency filter to the style property of our victim:
		element.src = transparentImage;
		element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
			try{
			element.style.height = (iheight - 2);
			element.style.width = (iwidth - 2);
			}catch(e){}
		}
	}

	// This is a vestigial function left over from the original "pngHack" script. 
	// It is supposed to detect the version of the browser but doesn't work reliably enough to use.
	// We don't use it now although it may be useful in the future in case there are errors later on.
	function needHack()
	{
		var pos = navigator.userAgent.indexOf("MSIE ");
	
		if (pos == -1)
			return false;
	
		var version = navigator.userAgent.substring(pos + 5);
	
		return (((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0)) && (navigator.platform == ("Win32")));
	}
	
}
// Here is where we tell this script to run only after the page loads. 
//If it were to run before the page finishes loading, it would have no clue as to which and how many images exist on the page.
window.attachEvent("onload", allofus);
