<public:component>
<script type="text/javascript">

// IE5.5+ PNG Alpha Fix v2.0 Alpha
// (c) 2004-2008 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};
IEPNGFix.data = IEPNGFix.data || {};


// This must be a path to a blank image, relative to the HTML document(s).
// Chris Paul (mrjeeves): set this to use drupal's base path and default path to module
IEPNGFix.blankImg = (window.BlankImgPath || '/sites/all/modules/pngbehave') + '/blank.gif';


IEPNGFix.fix = function(elm, src, t) {
	// Applies an image 'src' to an element 'elm' using the DirectX filter.
	// If 'src' is null, filter is disabled.
	// Disables the 'hook' to prevent infinite recursion on setting BG/src.
	// 't' = type, where background tile = 0, background = 1, IMG SRC = 2.

	var h = this.hook.enabled;
	this.hook.enabled = 0;
	
	// Chris Paul (mrjeeves): optimize usage of elm.currentStyle
	var elmCS = elm.currentStyle;

	var f = 'DXImageTransform.Microsoft.AlphaImageLoader', scalemethod = '';
		src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');

	if (
		src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) && elm.offsetWidth > 0
	) {
	  if (
	  	elmCS.width == 'auto' && elmCS.height == 'auto'
	  ) {
	  	// Chris Paul (mrjeeves): moved auto size calculations due to new sizingMethod for IMG SRC
	  	if (elmCS.display == 'inline') {
	  		elm.style.display = 'inline-block';
	  	}
  	} else if (
		  // Chris Paul (mrjeeves): if width and height are defined, use the 'scale' method
	  	elmCS.width != 'auto' && elmCS.height != 'auto'
	  ) {
		  scalemethod = 'scale';
		}
	}
  
	if (t == 1) {
		elm.style.backgroundImage = 'url("' + this.blankImg + '")';
	}
	if (t == 2) {
	  // Chris Paul (mrjeeves): using a sizingMethod 'eats' padding on images
	  // attempt to correct this by adding the padding to the margin.
		if (elmCS.paddingTop || elmCS.paddingBottom || elmCS.paddingLeft || elmCS.paddingRight) {
	    var pads = {
		    Top:parseInt(elmCS.paddingTop),
	      Bottom:parseInt(elmCS.paddingBottom),
		    Left:parseInt(elmCS.paddingLeft),
		    Right:parseInt(elmCS.paddingRight)
	    }
	    for (var i = '' in pads) {
			  // Chris Paul (mrjeeves): if theres padding fix it
		    if (!isNaN(pads[i]) && pads[i] > 0) {
				  var tmpMargin = parseInt(elmCS['margin' + i]);
		      elm.style['margin' + i] = ((isNaN(tmpMargin) ? 0 : tmpMargin) + pads[i]) + 'px';
        } else {
				  //Chris Paul (mrjeeves): otherwise, clear it
				  pads[i] = 0;
				}
		  }
		}
		
		elm.src = this.blankImg;
	}

	if (elm.filters[f]) {
		elm.filters[f].enabled = src ? true : false;
		if (src) {
			elm.filters[f].src = src;
		}
	} else if (src) {
		elm.style.filter = 'progid:' + f + '(src="' + src +
		  // Chris Paul (mrjeeves): new scalemethod detects defined sizes
			// used to actually scale an element
			'",sizingMethod="' + (t == 2 ? scalemethod : 'crop') + '")';
		
		if (scalemethod == 'scale' && pads) {
		  // Chris Paul (mrjeeves): if size has been defined, the scalemethod
			// will include padding in the scaled size.
		  // Attempt to correct this by subtracting padding from the height/width
		  if (pads.Top > 0 || pads.Bottom > 0) {
			  elm.style.height = parseInt(elm.currentStyle.height) - (pads.Top + pads.Bottom);
			}
			if (pads.Left > 0 || pads.Right > 0) {
			  elm.style.width = parseInt(elm.currentStyle.width) - (pads.Left + pads.Right);
			}
		}
		
	}
	this.hook.enabled = h;
};


IEPNGFix.process = function(elm, init) {
	// Checks the onpropertychange event (on first 'init' run, a fake event)
	// and calls the filter-applying-functions.

	if (
		!/MSIE (5\.5|6)/.test(navigator.userAgent) ||
		typeof elm.filters == 'unknown'
	) {
		return;
	}
	if (!this.data[elm.uniqueID]) {
		this.data[elm.uniqueID] = {
			className: ''
		};
	}
	var data = this.data[elm.uniqueID],
		evt = init ? { propertyName: 'src,backgroundImage' } : event,
		isSrc = /src/.test(evt.propertyName),
		isBg = /backgroundImage/.test(evt.propertyName),
		isPos = /width|height|background(Pos|Rep)/.test(evt.propertyName),
		isClass = !init && ((elm.className != data.className) &&
			(elm.className || data.className));
	if (!(isSrc || isBg || isPos || isClass)) {
		return;
	}
	data.className = elm.className;
	var blank = this.blankImg.match(/([^\/]+)$/)[1],
		eS = elm.style,
		eCS = elm.currentStyle;

	// Required for Whatever:hover - erase set BG if className changes.
	if (
		isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
		eS.backgroundImage.indexOf(blank) > -1)
	) {
		return setTimeout(function() {
			eS.backgroundImage = '';
		}, 0);
	}

	// Foregrounds.
	if (isSrc && elm.src &&  { IMG: 1, INPUT: 1 }[elm.nodeName]) {
		if ((/\.png/i).test(elm.src)) {
			this.fix(elm, elm.src, 2);
		} else if (elm.src.indexOf(blank) == -1) {
			this.fix(elm, '');
		}
	}

	// Backgrounds.
	var bgSrc = eCS.backgroundImage || eS.backgroundImage;
	if ((bgSrc + elm.src).indexOf(blank) == -1) {
		var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
		if (bgPNG) {
			if (this.tileBG && !{ IMG: 1, INPUT: 1 }[elm.nodeName]) {
				this.tileBG(elm, bgPNG[1]);
				this.fix(elm, '', 1);
			} else {
				if (data.tiles && data.tiles.src) {
					this.tileBG(elm, '');
				}
				this.fix(elm, bgPNG[1], 1);
				this.childFix(elm);
			}
		} else {
			if (data.tiles && data.tiles.src) {
				this.tileBG(elm, '');
			}
			this.fix(elm, '');
		}
	} else if ((isPos || isClass) && data.tiles && data.tiles.src) {
		this.tileBG(elm, data.tiles.src);
	}

	if (init) {
		this.hook.enabled = 1;
		elm.attachEvent('onpropertychange', this.hook);
	}
};


IEPNGFix.childFix = function(elm) {
	// "hasLayout" fix for unclickable children inside PNG backgrounds.
	var tags = [
			'a',
			'input',
			'select',
			'textarea',
			'button',
			'iframe',
			'object'
		],
		t = tags.length,
		tFix = [];
	while (t--) {
		var pFix = elm.all.tags(tags[t]),
			e = pFix.length;
		while (e--) {
			tFix.push(pFix[e]);
		}
	}
	t = tFix.length;
	if (t && (/relative|absolute/i).test(elm.currentStyle.position)) {
		alert('IEPNGFix: Unclickable children of element:' +
			'\n\n<' + elm.nodeName + (elm.id && ' id=' + elm.id) + '>');
	}
	while (t--) {
		if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {
			tFix[t].style.position = 'relative';
		}
	}
};


IEPNGFix.hook = function() {
  // Chris Paul (mrjeeves): added readyState checks to ensure that element is not currently being loaded/unloaded
	// IE6 fires two readystatechange events in some cases (particularly forms), one of which is before the element
	// is ready to be altered.
	if (IEPNGFix.hook.enabled && this.readyState=='interactive') {
		IEPNGFix.process(element, 0);
	}
};


IEPNGFix.process(element, 1);

</script>
</public:component>
