/*
 * jQuery pngfix plugin
 * Version 1.2  (20/05/2007)
 * @requires jQuery v1.1.1
 *
 * Copyright (c) 2007 Khurshid M.
 * Licensed under the MIT license
 */
 
(function($) {

	var correction = {
		ltie7 : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		pixel : 'pixel.gif',
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+src+"')";
		}
	};

	$.fn.pngfix = correction.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			if ($$.is('img')) {
				$$.css({filter:correction.filter($$.attr('src')), width:$$.width(), height:$$.height()})
				  .attr({src:correction.pixel})
				  .positionFix();
			} else { /* correction png css properties present inside css */
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["'](.*\.png)["']\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:correction.filter(image)})
					  .positionFix();
				}
			}
		});
	} : function() { return this; };

	$.fn.pngunfix = correction.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["'](.*\.png)["']/i)) {
				src = RegExp.$1;
				if ($$.is('img')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}	
			}
		});
	} : function() { return this; };

	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);

$(document).ready( function () { $('img[@src$=.png]').pngfix(); } );