/*
PNG-Fix by Stefan Bleilevens
not supported: background-repeat, background-position
*/

var isIE = (jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) < 7); // Alle Versionen unter 7.0
var blankImg = "blank.gif";

jQuery(document).ready(function() {
	if(isIE){
		jQuery("div").fixPNG();
		jQuery("img").fixImgPNG();
		jQuery("label").fixPNG();
		jQuery("li").fixPNG();
	}
});

/* <div>-Fix */

jQuery.fn.fixPNG = function() {
	return this.each(function () {
//		alert("PNG-Fix wird ausgefuehrt fuer das Element mit der ID " + this.id + ".");
		var backgroundPosition = jQuery(this).css('backgroundPosition');
		var image = jQuery(this).css('backgroundImage');
		if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
			image = RegExp.$1;
			jQuery(this).css({
						 'backgroundImage': 'none',
						  'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + (jQuery(this).css('backgroundRepeat') == 'repeat' ? 'crop' : 'crop') + ", src='" + image + "')"
						 }).each(function () {
			var position = jQuery(this).css('position');
			if (position != 'absolute' && position != 'relative')
				jQuery(this).css('position', 'relative');
			});
		}
	});
};

/* <img>-Fix */

jQuery.fn.fixImgPNG = function() {
	return this.each(function () {
//		alert("PNG-Fix (img) wird ausgefuehrt fuer das Element mit der ID " + this.id + ".");
		var image = this.src;
//		alert(image);
		
		if (image.match(/^["']?(.*\.png)["']?$/i)) {
			image = RegExp.$1;
//			alert("Es wurde ein PNG-Bild gefunden mit der Aufloesung " + this.width + "x" + this.height);
			var width = this.width;
			var height = this.height;
			this.src = blankImg;
			jQuery(this).css({
						 'backgroundImage': 'none',
						 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + (jQuery(this).css('backgroundRepeat') == 'repeat' ? 'crop' : 'none') + ", src='" + image + "')"
						 }).each(function () {
			var position = jQuery(this).css('position');
			this.style.width = width;
			this.style.height = height;
			if (position != 'absolute' && position != 'relative')
				jQuery(this).css('position', 'relative');
			});
		}
	});
};