// PNG fix: Replaces all images with longdesc="png" with a reference to a png
// Idea and Code by Moritz Zimmer, omo@oio.ch, www.oio.ch

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 strNewHTML = "<span " + imgID + imgClass + " style=\"display:inline-block;" + "width:" + imgNode.getAttribute('width') + "px; height:" + imgNode.getAttribute('height') + "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + newSrc + "\', sizingMethod='image');\"></span>";
					if (imgNode.getAttribute('align'))
						strNewHTML = "<div align=\"" + imgNode.getAttribute('align') + "\">" + strNewHTML + "</div>";
					
					imgNode.outerHTML = strNewHTML;
					
					// decrement enumeration because its not a img anymore
					
					imgEnum--;					
		
				} else {
					
					imgNode.setAttribute('src', newSrc);
				
				}
			
			}
		
		}
		
	}

}