/*
 * Apply IE fix including PNG images display in IE6 and below and
 * image display contained in textless block elements in IE7 and below
 *Use in <HEAD> with DEFER keyword wrapped in conditional comments:
 *<!--[if lt IE 7]>
 *<!--<script defer type="text/javascript" src="pngfix.js" charset="UTF-8"></script>-->
 *<![endif]-->
 *
 */

var aBrowserVersion = navigator.appVersion.split("MSIE");

// check that IE
if (aBrowserVersion != null)
{
    var nBrowserVersion = parseFloat(aBrowserVersion[1]);

	// apply PNG fix for IE6 and below
	
	// check that version is between 5.5 and 7 (7 not included)
    if (nBrowserVersion >= 5.5 && nBrowserVersion < 7)
    {
		//alert(document.images.length);
		if (document.body != null && document.body.filters != null)
		{
			for (var i = 0; i < document.images.length; i++)
			{
				var oImage = document.images[i];				
				var sImgName = oImage.src.toUpperCase();
				
				if (sImgName.substring(sImgName.length-3, sImgName.length) == "PNG")
				{
					var sImgID = (oImage.id) ? "id='" + oImage.id + "' " : "";
					var sImgClass = (oImage.className) ? "class='" + oImage.className + "' " : "";
					var sImgTitle = (oImage.title) ? "title='" + oImage.title + "' " : "title='" + oImage.alt + "' ";
					var sImgStyle = "display:inline-block;" + oImage.style.cssText;
					if (oImage.align == "left") sImgStyle = "float:left;" + sImgStyle;
					if (oImage.align == "right") sImgStyle = "float:right;" + sImgStyle;
					if (oImage.parentElement.href) sImgStyle = "cursor:hand;" + sImgStyle;
					var sNewHTML = "<span " + sImgID + sImgClass + sImgTitle
						+ " style=\"" + "width:" + oImage.width + "px; height:" + oImage.height + "px;" + sImgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + oImage.src + "\', sizingMethod='scale');\"></span>" ;
					oImage.outerHTML = sNewHTML;
					i = i-1;
				}
			}
        }
    }
    
    // apply fix for block type elements such as TD and DIV containing an IMG element
	// that their HTML was written such that their closing tag does not immediately
	// follow the IMG close tag. in this case a small white space appear adjacent to the image
	for (var i = 0; i < document.images.length; i++)
	{
		var oImage = document.images[i];
		if (oImage.parentNode && oImage.parentNode.innerText.replace(/^\s+|\s+$/, "") == "")
			oImage.parentNode.style.fontSize = "1px";
	}
}

