/*****************************************************************************
 * PNG Alpha Channel Fix for Internet Explorer 5.5 and 6.0                   *
 *****************************************************************************
 * This code was written by Kirsle using documentation freely available on   *
 * the Internet. None of this code was copied from any other existing        *
 * sources. Thus this code is copyright (C) 2008 Casey Kirsle @ Cuvou.com    *
 * and I'd like it if you ask permission before using this script on any     *
 * other website.                                                            *
 *****************************************************************************/

function initPng4IE() {
	// Only worry about IE 5.5 or 6.0
	var isMSIE = 0;
	if (navigator.appVersion.match(/MSIE (6\.0|5\.5)/)) {
		isMSIE = 1;
	}
	if (isMSIE == 0) {
		return;
	}

	// Path to a completely invisible gif image.
	var invis = "/js/png4ie.gif";

	// Loop through all the elements on the page.
	for (var i = 0; i < document.all.length - 1; i++) {
		var tag = document.all[i];

		// Background PNG images.
		if (tag.style.backgroundImage.match(/\.png/i) != null) {
			var bg = tag.style.backgroundImage;
			var src = bg.substring(5, bg.length - 2);
			var mode = "scale";
			if (tag.style.backgroundRepeat == "no-repeat") {
				mode = "crop";
			}
			tag.style.filter = "progid:DXImageTransform.Microsoft."
				+ "AlphaImageLoader(src='" + src + "', "
				+ "sizingMethod='" + mode + "')";
			tag.style.backgroundImage = "url(" + invis + ")";
		}

		// Image elements.
		if (tag.tagName == 'IMG' && tag.src.match(/\.png/i) != null) {
			var src = tag.src;
			tag.style.width = tag.width + "px";
			tag.style.height = tag.height + "px";
			tag.style.filter = "progid:DXImageTransform.Microsoft."
				+ "AlphaImageLoader(src='" + src + "', "
				+ "sizingMethod='scale')";
			tag.src = invis;
		}

		// Apply positioning to active elements.
		if ((tag.tagName == 'A' || tag.tagName == 'INPUT') &&
		tag.style.position == '') {
			tag.style.position = "relative";
		}
	}
}

initPng4IE();
