// PNG fix: Replaces all images with longdesc="png" with a reference to a png

function fixPNGs() {
	
	if (document.getElementsByTagName) {
	
		var allImages = document.getElementsByTagName('img');
		
		for (var imgEnum = 0; imgEnum < allImages.length; imgEnum++) {
			
			// window.alert(allImages.length);
			
			var imgNode = allImages[imgEnum];
			var imgSrc = imgNode.getAttribute('src');
			var imgLongDesc = imgNode.getAttribute('longDesc');
			
			// window.alert("num: " + imgEnum + ",src: " + imgSrc + ",longdesc: " + imgLongDesc)
			
			if (imgLongDesc && imgLongDesc.length > 0 && imgLongDesc.indexOf('png') >= 0) {
				
				var newSrc = imgSrc.substring(0, imgSrc.length-4) + '.png';
				
				if (window.is_ie5up) {
				
					var imgID = (imgNode.getAttribute('id')) ? "id='" + imgNode.getAttribute('id') + "' " : "";
					var imgClass = (imgNode.getAttribute('class')) ? "class='" + imgNode.getAttribute('class') + "' " : "";
					var imgStyle = "display:inline-block;" + imgNode.getAttribute('style');
					
					var strNewHTML = "<span " + imgID + imgClass;
					strNewHTML += " style=\"" + "width:" + imgNode.getAttribute('width') + "px; height:" + imgNode.getAttribute('height') + "px;" + imgStyle + ";";
					strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
					strNewHTML += "(src=\'" + newSrc + "\', sizingMethod='scale');\"></span>" ;
					
					imgNode.outerHTML = strNewHTML;
					
					// decrement enumeration because its not a img anymore
					
					imgEnum--;					
		
				} else {
					
					imgNode.setAttribute('src', newSrc);
				
				}
			
			}
		
		}
		
	}

}