/*
 * jQuery pngfix plugin
 * Version 1.2  (20/05/2007)
 * @requires jQuery v1.1.1
 *
 * Examples at: http://khurshid.com/jquery/iepnghack/
 */

(function($) {

	var hack = {
		ltie7 : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		pixel : 'bilder/abstand.png',
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		},
		bgFilter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+src+"')";
		}
	};
	
	$.fn.pngfix = hack.ltie7 ? function() {
    return this.each( function () {
			var $$ = $(this);
			if ($$.is('img')) // hack image tags in dom
				$$.css({filter:hack.filter($$.attr('src')), width:$$.width(), height:$$.height()}).attr({src:hack.pixel}).positionFix();
			else { // hack png css-backgroundImage
				var image = $$.css('backgroundImage');
				/*if (image.match(/^url\(["'](.*\.png)["']\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)}).positionFix();
				}*/
				if (image.indexOf(".png")) {
          image = image.substr(4, image.length-5);
          $$.css("width", $$.width() + "px");
          $$.css("height", $$.height() + "px");
					$$.css({backgroundImage:'none', filter:hack.bgFilter(image)}).positionFix();
        }
			}
		});
	} : function() { return this; };
	
	$.fn.pngunfix = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["'](.*\.png)["']/i)) { // get img source from filter
				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);
