/*
 * This script fixes transparent PNGs in the background-image CSS attributes
 * in IE.
 * 
 * To use it just include the file, and do a <body onLoad="fixPngBackgroundsInIE()">
 * 
 * Notes: The script *scales* the PNG for elements with an 'auto' width or height.
 *        CSS background-repeat is not supported!
 *
 * Feel free to steal this code
 *
 */

function fixPngBackgroundsInIE() {
	// Assume IE7 is OK.
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) return;

	for( var i = 0; i < document.all.length; i++ ) {
		var el = document.all[i];
		var imageUrl = el.currentStyle.backgroundImage;
		urlLen = imageUrl.length;
		if( imageUrl.substring(urlLen - 6) == '.png")' ) {
			el.runtimeStyle.backgroundImage = 'none';
			var sizing = "');";
			if (el.currentStyle.height == 'auto') {
				el.runtimeStyle.height = el.offsetHeight;
				sizing = "', sizingMethod='scale');";
			}
			if (el.currentStyle.width == 'auto') {
				el.runtimeStyle.width = el.offsetWidth;
				sizing = "', sizingMethod='scale');";
			}
			el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageUrl.substring(5, imageUrl.length-2) + sizing;
		}
	}
}
