/*

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('load', function(){$$('img.fixPNG').each(function(png){fixPNG(png)});});

/* do not edit below this line */   

/* Section: Change Log 



$Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/browser.fixes/fixpng.js,v $

$Log: fixpng.js,v $

Revision 1.8  2007/08/25 00:05:33  newtona

moved ProductToolbar to global implementations

handled ie6 slightly differently in fixPNG, added some dbug lines for when it failes

updated commerce global cat file for new location of ProductToolbar

rebuilt redball.common.full



Revision 1.7  2007/08/03 22:01:14  newtona

refactored fixPng; the big change is that it now clones events from the old element to the new one.



Revision 1.6  2007/07/27 19:55:36  newtona

removing dependency on Element.shortcuts.js



Revision 1.5  2007/05/29 22:01:53  newtona

Split element.cnet.js into seperate files; updated docs in files to note this

Changed element.visible to element.isVisible (left old namespace for legacy support)

Fixed Element.empty in prototype.compatibility.js

Removed as many dependencies in common code to element.*.js as possible (espeically element.shortcuts.js)



Revision 1.4  2007/05/16 20:17:52  newtona

changing window.onDomReady to window.addEvent('domready'



Revision 1.3  2007/01/26 05:46:32  newtona

syntax update for mootools 1.0



Revision 1.2  2007/01/19 01:21:47  newtona

changed event.ondomready > window.ondomready



Revision 1.1  2007/01/09 02:39:35  newtona

renamed addons directory to "common" directory



Revision 1.3  2007/01/09 01:26:38  newtona

changed $S to $$



Revision 1.2  2006/11/02 21:26:42  newtona

checking in commerce release version of global framework.



notable changes here:

cnet.functions.js is the only file really modified, the rest are just getting cvs footers (again).



cnet.functions adds numerous new classes:



$type.isNumber

$type.isSet

$set



*/
