/*
 *	PngTransparencyFix
 */
var PngTransparencyFix = {
	/*
		imageSrc
		The src for the transparent image.
	*/
	imageSrc: null,
	
	/*
		maxImages
		The maximum number of images to process (for performance)
	*/
	maxImages: -1,
	
	/*
		apply()
		Loops though the images in the current document and applies a fix 
		to display alpha transparency in Internet Explorer.
	*/
	apply: function() 
	{
		var trans = PngTransparencyFix.imageSrc || document._transparentImageSrc || null;
		var max = parseInt( document._maxImages, 10 ) || PngTransparencyFix.maxImages;
		if( typeof trans == "string" )
		{
			var isPng = new RegExp( "\.png$", "i" );
			var isTransparent = new RegExp( trans + "$", "i" );
			for( var img = null, i = 0; null != (img = document.images[ i ]); i++ )
			{
				if( max > -1 && i > max ) return;
				var src = img.src || "";
				if( isPng.test( src ) && !isTransparent.test( src ) )
				{
					var width	= img.width;
					var height	= img.height;
					img.src		= trans;
					img.width	= width;
					img.height	= height;
					img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='" + src + "', sizingMethod='scale' )";
				}
			}
		}
		for (i=0; i < document.all.length; i++){
				var bg = document.all[i].currentStyle.backgroundImage;	
				if (bg) {
					if (bg.match(/\.png/) != null) { 
						var mypng = bg.substring(5,bg.length-2);
						//document.all[i].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
						document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='crop')";
						document.all[i].style.backgroundImage = "URL('/images/spacer.gif')";	
					}
				}
			}				
		}
	};

/* Set the transparent dummy image here or map the uri and set 
 * it elsewhere from within in your page
 */
PngTransparencyFix.imageSrc = "/images/spacer.gif";

/*
 * attach event to fix png's for the Internet Explorer event model only
 */
if( window.attachEvent )
{
	var version = navigator.appVersion;
	version = version.indexOf( "MSIE" ) != -1 
		? parseFloat( version.split( "MSIE" )[ 1 ] )
		: 5.5;
	
	if( version > 5 && version < 7 )
	{
		//alert( "IE has to load alpha png's.\n" + version );
		window.attachEvent( "onload", PngTransparencyFix.apply );
		
	}
}
