// vim: set tabstop=4 shiftwidth=4 foldmethod=marker :
/**
 * Correctly handle PNG transparency in Win IE 5.5 to IE 6
 *
 * Best way to instantiate this:
 * <script type="text/javscript">function pngfix() {}</script>
 * <!--[ if lt IE 7]>
 * <script defer type="text/javascript" src="pngfix.js"></script>
 * <![ endif]-->
 *
 * Why? It will not load unless it is IE5.5 to 6. If using the defer keyword
 * you can remove the window.attachEvent() at the end and you remove the
 * flickr at the end.
 *
 * @author Original code <http://homepage.ntlworld.com/bobosola>
 *      Updated 2004-03-02
 * @author Terry Chay <tychay@plaxo.com> Revised to fix image inputs, supports
 *      Exploder 7. Updated 2006-11-15
 * @author Ryan Moore <rmoore@plaxo.com> removed a lot of extraneous code
 * @todo escape attr.value
 * @todo fix for css bg images
 * @todo in css bg images. Should find a way to clean up this duplicate code (tried using cssRules/rules as array property but it seems to upset IE when you use .length)
 */
var pngfix_blank = '/css/m/im/com/sp.gif';

// {{{ pngfix_xform(obj,src,shouldReplace)
function pngfix_xform(obj,src)
{
    // Don't apply to non png
    if (src.substring(src.length-3,src.length).toLowerCase() != 'png') { return; }

    if(obj['width']) obj.style.width = obj['width'] + "px";
    if(obj['height']) obj.style.height = obj['height'] + "px";
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')";
    obj.src = pngfix_blank;
}
// }}}
// {{{ pngfix()
function pngfix()
{
    // extra trap for Exploder up tup to version 7o version 7
    if (typeof document.body.style.maxHeight != "undefined") { return; }

    for(var i=0; i < document.images.length; i++) {
        var obj = document.images[i];
        var src = obj.getAttribute('src');
        if (src) {
            pngfix_xform(obj,src);
        }
    }
    // We didn't get the form inputs
    var tags = document.getElementsByTagName('input');
    for (var i=0; i < tags.length; ++i) {
        var obj = tags.item(i);
        var src = obj.getAttribute('src');
        var input_type = obj.getAttribute('type');
        if (input_type && (input_type.toLowerCase() == 'image') && src) {
            pngfix_xform(obj,src);
        }
    }
/*
    // fix css bg images too {{{
    // CHANGED: check for cssRules vs rules to get this to work in IE, Opera, and FF (Garret, 13/9/06)
    // COMMENT: It is a really bad idea to be using the ActiveX filter for
    // pngs. We should use gifs insteadl.
    // FIXME: This seems to hide transparent pngs in opera however...
    
    if (document.styleSheets[0].rules) {

      for (var s = 0; s < document.styleSheets.length; s++) {
        for (var r = 0; r < document.styleSheets[s].rules.length; r++) {
          var obj = document.styleSheets[s].rules[r].style;
          var bi = obj.backgroundImage;
          if (bi && (bi != "none") && (bi.indexOf(".png") != -1)) {
              var url = bi.split("(")[1].split(")")[0];
              obj.backgroundImage = "";
  // uncomment when we fix the rounded-rects
  //            obj.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + url + "')";
          }
        }
      }
      
    } else if (document.styleSheets[0].cssRules) {

      for (var s = 0; s < document.styleSheets.length; s++) {
        for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) {
          var obj = document.styleSheets[s].cssRules[r].style;
          var bi = obj.backgroundImage;
          if (bi && (bi != "none") && (bi.indexOf(".png") != -1)) {
              var url = bi.split("(")[1].split(")")[0];
              obj.backgroundImage = "";
  // uncomment when we fix the rounded-rects
  //            obj.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + url + "')";
          }
        }
      }
    }
     // }}}
*/

}
// }}}
SafeAddOnload(pngfix);
