var PngFixDone = 0;

/**
* Special function to fix alpha channel png images onload.
*/
__ie6_fixpngimage = function(e)
{
	var el = e.srcElement;
	// Check if the image source has been changed.
	if (el.src.match(/jscripts\/clear\.gif$/) == 'jscripts/clear.gif')
		return;
	//
	var rep = el.getAttribute('method');
	//
	el.height = el.height;
	el.width = el.width;
	el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
	el.src + "',sizingMethod='" + rep + "')";
	el.src = 'jscripts/clear.gif';
}

__ie6_pngfix = function()
{
	if (PngFixDone)
		return;
	// Prevent reentry.
	PngFixDone++;
	//
	var els = document.getElementsByTagName('*');
	var i_p = /\.png/i;
	var i = els.length;
	while (i-- >0)
	{
		var el = els[i];
		var es = el.style;
		if (el.tagName == 'IMG' && el.src && el.currentStyle.filter.match(/^png-/))
		{
			var rep = el.currentStyle.filter.substring(4);
			//DebugOut("Image rep = " + rep + " src = " + el.src);
			// When set to none skip this one.
			if (rep == 'none')
				continue;
			//
			el.setAttribute('method', rep)
			this.srcElement = el;
			__ie6_fixpngimage(this);
			el.attachEvent('onload', __ie6_fixpngimage);
		}
		//
		if (el.src && el.src.match(i_p) && es.filter == '')
		{
			el.height = el.height;
			el.width = el.width;
			es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
				el.src + "',sizingMethod='crop')";
			el.src = 'jscripts/clear.gif';
		}
		else
		{
			var elb = el.currentStyle.backgroundImage;
			if (elb.match(i_p) || el.currentStyle.filter.match(/^png-/))
			{
				var path = elb.split('"');
				var rep = 'scale';
				if (el.currentStyle.filter.match(/^png-/))
				{
					rep = el.currentStyle.filter.substring(4);
					// When set to none skip this one.
					if (rep == 'none')
						continue;
				}
				DebugOut("Filter bg: " + el.className + ':' + el.currentStyle.filter + ':' + elb);
				es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
					path[1] + "',sizingMethod='" + rep + "')";
				es.height = (el.clientHeight) + 'px';
				es.backgroundImage = "none";
			}
		}
		/*
		if (el.currentStyle.position != 'absolute' && !es.filter && !el.tagName.match(/(body|html|script)/gi))
			es.position = "relative";
		*/
		if (es.filter && el.currentStyle.position == "relative")
			es.position = "static";
	}
}

// Only for IE6 browser.
if (BrowserDetect && BrowserDetect.browser == 'Explorer' && BrowserDetect.version <= 6)
		window.attachEvent('onload', __ie6_pngfix);

