
function ie6png(doit) {
    if (!doit) {
        // call the fix only for IE 6
        if (window.external && typeof window.XMLHttpRequest == "undefined") {
            window.setTimeout(function() { ie6png(true); }, 1);
        }
        return;
    }
    node_visitor(ie6png_fix);
}


function node_visitor(fn, node) {
    if (!node) {
        node = document.getElementsByTagName('BODY')[0];
    }
    // not an actual element, but most likely a text node
    if (!node.tagName || node.nodeType == 3) {
        return;
    }
    if (fn(node)) {
        return;
    }
    var children = node.childNodes;
    for(var i = children.length - 1; i > -1; i--) {
        node_visitor(fn, children[i]);
    }
}

function ie6png_fix(node) {
    var bg = null, src = null, method = null;
    var cStyle = node.currentStyle;
    // fix background images
    if (
        cStyle
        && (bg = cStyle.backgroundImage)
        && bg.indexOf('.png') > 0
    )
    {
        // strip url("")
        src = bg.substring(5, bg.length - 2);
        var method = (
                cStyle.backgroundRepeat &&
                cStyle.backgroundRepeat.indexOf('repeat-') == 0
            ) ? 'scale' : 'crop';
        node.style.backgroundImage = "none";
    }
    // fix images
    if (node.src && node.src.indexOf('.png') > 0) {
        // trace(node.src);
        method = 'crop';
        src = node.src;
        node.src = '/media/layout/blank.gif';
    }
    if (method && src) {
        var filter = " progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src='" + src + "', sizingMethod='" + method + "')";
        // trace(filter);
        node.style.filter = filter;
    }
    return false;
};
