/*--------------------------------------------------------------------------
	mooPNG Fix
	An Alpha PNG Fix for Internet Explorer 6 using MooTools.

	Project:		mooPNG Fix
	Version:		1.0
	Author:			Les Argonautes (cv)
	URL:			www.les-argonautes.com
	Date :			January 18th, 2009

	Use:			Just insert it on your page with
					<script type="text/javascript" src="mootools.pngfix.js"></script>

					The script detects Internet Explorer 6,
					so insert it with conditionnal comments.

					You can specify the url of the gif in the
					properties of the class.
					e.g:
						//if you want to specify a gif replacement image
						var pngFix = new mooPng('/images/blank.gif');
						// else it will use a "blank.gif" image in the same folder of the page
						var pngFix = new mooPNG();

	Require:		Mootools 1.2 (core)
							+ (plugin) Assets [optional]
--------------------------------------------------------------------------*/


if(window.MooTools && Browser.Engine.trident4) {
	var mooPNG = new Class({
		initialize: function(blankImg) {
			if(blankImg!=false)
				this.blankImg = blankImg;
			else
				this.blankImg = 'blank.gif';
				
			window.addEvent('domready', function() {
				if(window.Asset) {
					this.blankImg = new Asset.image(this.blankImg, {onload: this.run});
				}	
				else {
					this.blankImg = new Element('img',{src:this.blankImg});
					this.run(this.blankImg);
				}
			}.bind(this));
		},
		
		run: function(blankImg) {
			$$('img').each(function(img) {
				if(img.src.test('.png$', 'i')) {
					if(img.getProperty('width')==null)
						img.setProperty('width',img.offsetWidth);
						
					if(img.getProperty('height')==null)
						img.setProperty('height',img.offsetHeight);

					img.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');");
					img.src = blankImg.src;
				}
			});
		}
	});


	/* ================================
	 * !Running Script
	 * ================================*/
	if(typeof(blankImg)=='undefined')
		blankImg = false;

	var pngFix = new mooPNG(blankImg);
 }
