
/*
Script: fixpng.js

Dependancies:
	 mootools - <Moo.js>, <String.js>, <Array.js>, <Function.js>, <Element.js>, <Dom.js>
	
Author:
	Aaron Newton, <aaron [dot] newton [at] cnet [dot] com>

		Function: fixPNG
		this will make transparent pngs show up correctly in IE. This function 
		is based almost entirely on the function found here: 
		<http://homepage.ntlworld.com/bobosola/pnginfo.htm>
		
		Arguments:
		myImage - the image element or id to fix
		
		Note: 
		there is an instances of this already set to fire onDOMReady that
		will fix any png files with the class "fixPNG". This means any producer
		can just give the class "fixPNG" to any img tag and they are set BUT, the
		ping will look wrong until the DOM loads, which may or may not be noticeable.
		
		The alternative is to embed the call right after the image like so:
		
		><img src="png1.png" width="50" height="50" id="png1">
		><img src="png2.png" width="50" height="50" id="png2">
		><script>
		>	$$('#png1', '#png2').each(function(png) {fixPNG(png);});
		>	//OR
		>	fixPNG('png1');
		>	fixPNG('png2');
		></script>
*/

function fixPNG(myImage) 
{
	try {
		if (window.ie6){
			myImage = $(myImage);
			var vis = myImage.getStyle('display') != 'none';
			if(!vis) myImage.setStyle('display','block');
			var width = $(myImage).offsetWidth;
			var height = $(myImage).offsetHeight;
			if(!vis) myImage.hide();
			var replacement = new Element('span', {
				id:(myImage.id)?myImage.id:'',
				'class':(myImage.className)?myImage.className:'',
				title:(myImage.title)?myImage.title:(myImage.alt)?myImage.alt:'',
				styles: {
					display: 'inline-block',
					width: width,
					height: height,
					filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" 
						+ myImage.src + "', sizingMethod='scale');"
				},
				src: myImage.src
			});
			if(myImage.style.cssText) {
				try {
					var styles = {};
					var s = myImage.style.cssText.split(';');
					s.each(function(style){
						var n = style.split(':');
						styles[n[0]] = n[1];
					});
					replacement.setStyle(styles);
				} catch(e){ dbug.log('fixPNG1: ', e)}
			}
			if(replacement.cloneEvents) replacement.cloneEvents(myImage);
			myImage.replaceWith(replacement);
		}
	} catch(e) {dbug.log('fixPNG2: ', e)}
};
if(window.ie6) 
	{
	window.addEvent('domready', function(){$$('img.fixPNG').each(function(png){ png.setStyle('opacity', '0');  });});
	window.addEvent('load', function(){$$('img.fixPNG').each(function(png){fixPNG(png)});});
	}

