/*

	--- Overview ---
	This code will fix the PNG transparency problem for most images rendered with Microsoft Internet Explorer versions 5 and 6.  It does not fix the same problem for background images.  
	
	--- Use ---
	This code should be placed in folder "./BTSEffects/FixPNGTransparency" relative to the base (the BASE element) of the HTML document or, if none specified, relative to the folder containing the HTML document.  The folder "./BTSEffects/FixPNGTransparency" should also contain a graphic named "EmptyPixel.gif".  This graphic was originally provided with this code as a 1 pixel by 1 pixel transparent GIF.  
	
	--- Technical Details ---
	As a default, this code binds the function "FixPNGTransparencyAll" to the load event for the document, which converts all document images with a source extension of PNG (".png").  For optimization, give an ID of "TransparentPNG" to all images that load a transparent PNG graphic and modify this code to instead bind the function "FixPNGTransparencyMarked".  Further, for dynamically loaded images which are not determined until after the document load event occurs, the code for binding either function may be disabled or removed and the functions called manually or by some other event after the images are fully loaded, providing calculated "clientWidth" and "clientHeight" properties.  

	--- Legal Notice ---
	David L. Burkhart is the original author and sole owner of this code.  Any public access to or use of this code, in part or in whole, or any derivative thereof is hereby prohibited, except by explicit written permission directly by and from the author.  Permission is hereby granted for private, non-commercial use only.  This notice in full must remain with this code.  
	
	*/

if ( IEVersion>=5 && IEVersion<7 ) {
	window.attachEvent( "onload", FixPNGTransparencyAll );
	//window.attachEvent( "onload", FixPNGTransparencyMarked );
	}


function FixPNGTransparencyAll() {
	var ConvertAllPNG;
	FixPNGTransparency(ConvertAllPNG=true);
	}


function FixPNGTransparencyMarked() {
	var ConvertAllPNG;
	FixPNGTransparency(ConvertAllPNG=false);
	}


function FixPNGTransparency(ConvertAllPNG) { /*

	--- Use ---
	This function may be called with a parameter of true if it is unknown which or if any images contain a transparent PNG graphic.  Otherwise, each image containing a transparent PNG graphic must have a class of "TransparentPNG" in order to be converted.  
	
	--- Technical Details ---
	This function works by converting images so that the actual graphic is rendered by a Microsoft DirectX filter instead of directly by Microsoft Internet Explorer (IE).  From a layer standpoint, this filter renders the graphic between the image background and foreground.  However, in order for the filter to render the graphic, the image must allow to IE to render the foreground along with it.  Simply removing the graphic from the image foreground (the image source/"src") or specifying a non-existent graphic would still render a missing graphic symbol (a little red "x").  Therefore, the image foreground should be replaced with a graphic that will not obstruct the view of the original graphic now rendered by the filter.  
	
	*/
	
	var EmptyPixel, i, Image, ConvertPNG;
	
	if ( IEVersion>=5 && IEVersion<7 ) {
		for ( i=0; i<document.images.length; i++ ) {
			Image = document.images[i];
			if (ConvertAllPNG) {
				// Detect ".png" extension in source URL				ConvertPNG = ( ( Image.src.length>=4 ) && ( Image.src.substr( Image.src.length - 4, 4 ).toLowerCase() == ".png") );				}
			else {
				ConvertPNG = ( Image.className == "TransparentPNG");
				}
			if (ConvertPNG) {
				Image.style.width = Image.clientWidth + "px";				Image.style.height = Image.clientHeight + "px";				Image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='" + Image.src + "', sizingMethod='scale' )";				Image.src = "./BTSEffects/EmptyPixel.gif"; // Hide old image				}
			}
		}
	
	}

