var AlphaPng = new Class({
	defaultOptions: {
		'debug':			0,
		'clearImage':		'/_images/general/blank.gif',
		'backgroundTags':	['div', 'table', 'td', 'a']
	},
 
	initialize: function(options) {
		if (window.ie6)
		{
			this.setOptions(this.defaultOptions, options);
 
			this.fixImages();
			this.fixBackgrounds();
		}
	},

	fixImages: function()
	{
		if (window.ie6)
		{
			$ES('img[src$=png]').each(function(img){
				img.setStyles({
					'filter':	'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', src=\'' + img.getProperty('src') + '\', sizingMethod=\'scale\')',
					'width':	img.getProperty('width'),
					'height':	img.getProperty('height')
				});
				img.setProperty('src', this.options.clearImage);
			}.bind(this));
		}
	},
 
	fixBackgrounds: function()
	{
		if (window.ie6)
		{
			var reBackground = new RegExp('[^\(\)"\']+\.png', 'i');
			for (var i = 0; i < document.styleSheets.length; i++){
				for (var j = 0; j < document.styleSheets[i].rules.length; j++){
					var background = reBackground.exec(document.styleSheets[i].rules[j].style.backgroundImage);
					if (background){
						document.styleSheets[i].rules[j].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'' + document.styleSheets[i].rules[j].style.backgroundImage + '\')';
						document.styleSheets[i].rules[j].style.backgroundImage = 'none';
					}
				}
			}
 
			$ES(this.options.backgroundTags.join(',')).each(function(tag){
				if (new RegExp('\\.png["\']\\)', 'i').exec(tag.getStyle('background-image'))){
					tag.setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'' + tag.getStyle('background-image') + '\')');
					tag.setStyle('background-image', 'none');
				}
			}.bind(this));
		}
	}
});

AlphaPng.implement(new Events, new Options);
