// This file can be included in any page to make elements with
// translucent PNG background images appear correctly in IE.

function FixTranslucentPNGStyles(){
	var ua = navigator.userAgent.toLowerCase();
	// Not necessary on browsers other than IE.
	if(!((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)))
		return;
		
	for(var i = 0; i < document.styleSheets.length; i++) {
		var stylesheet = document.styleSheets[i];
		var rules = stylesheet.rules ? stylesheet.rules : stylesheet.cssRules;
		
		for(var j = 0; j < rules.length; j++) {
			var style = rules[j].style;

			// If there's a png set as the background image, set the
			// background image property to "none" and set a filter
			// to display the image instead.
			if(style.backgroundImage && style.backgroundImage.indexOf("png") > -1) {
				var image = style.backgroundImage.replace(/^url\(/, "");
				image = image.replace(/^\.\.\//, "");
				image = image.replace(/\)$/, "");

				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + image + "', sizingMethod='crop')"
				style.backgroundImage = "none";
			}
		}
	}
}

function FixTranslucentPNGElement(element) {
	var ua = navigator.userAgent.toLowerCase();
	// Not necessary on browsers other than IE.
	if(!((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)))
		return;

	with(element) {
		// If there's a png set as the background image, set the
		// background image property to "none" and set a filter
		// to display the image instead.
		if(style.backgroundImage && style.backgroundImage.indexOf("png") > -1) {
			var image = style.backgroundImage.replace(/^url\(/, "");
			image = image.replace(/^\.\.\//, "");
			image = image.replace(/\)$/, "");

			style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + image + "', sizingMethod='crop')"
			style.backgroundImage = "none";
		}
	}
}

FixTranslucentPNGStyles();