/*


Makes 32 bit PNG's transparency work in Internet Explorer 6
 * Dependent on Prototype 1.6
 * Works on img elements and on background images of elements
 * Image tiling will not work
 * Refer to the readme

Example Usages:
 
 $('yourPNG').pngHack();
 $$('div#fixMe', 'img#andMe', 'img.andUsTo').invoke('pngHack');
 
*/
Element.addMethods({
  pngHack: function(el){
    var el = $(el);
    var transparentGifPath = '/shop/library/images/transparent.gif';
    if (Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == '6'){
      /* if it's an img and a png */
      if ((el.match('img')) && (el.src.include('png'))){
        var alphaImgSrc = el.src;
        var sizingMethod = 'scale';
        el.src = transparentGifPath;
        /* if it's an element with a background png */
      } else if (el.getStyle('backgroundImage').include('png')){
    	var newBg = '';
        var bgColor = el.getStyle('backgroundColor');
        if (bgColor) {
          newBg = bgColor + ' ';
        }
        var elBg = el.getStyle('backgroundImage');
        var alphaImgSrc = elBg.slice(5, elBg.length - 2);
        var sizingMethod = 'crop';
        newBg += 'url("' + transparentGifPath + '")';
        el.setStyle({ 'background': newBg });
      }
      if (alphaImgSrc) el.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="#{al}",sizingMethod="#{sz}")'.interpolate({ al: alphaImgSrc, sz: sizingMethod });
    }
    return el;
  }
});