var supersleight = function() {
    
    var root = false;
    var applyPositioning = true;

    // Path to a transparent GIF image
    //this.shim = window.location + 'blank.gif'; //run on server
    this.shim = 'blank.gif';
    
    // RegExp to match above GIF image name
    var shim_pattern = /blank\.gif$/i;
    
    var fnLoadPngs = function() { 
        if (root) {
            obj = document.getElementById(root);
            if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {
                bg_fnFixPng(obj);
            }
            // image elements
            if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
                el_fnFixPng(obj);
            }
            // apply position to 'active' elements
            if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
                obj.style.position = 'relative';
            }
        }
        else{
            root = document;
            for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {
                // background pngs
                if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {
                    bg_fnFixPng(obj);
                }
                // image elements
                if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
                    el_fnFixPng(obj);
                }
                // apply position to 'active' elements
                if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
                    obj.style.position = 'relative';
                }
            }
        }
    };

    var bg_fnFixPng = function(obj) {
        var mode = 'scale';
        var bg    = obj.currentStyle.backgroundImage;
        var src = bg.substring(5,bg.length-2);
        if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
            mode = 'crop';
        }
        obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
        obj.style.backgroundImage = 'url('+shim+')';
    };

    var el_fnFixPng = function(img) {
        var src = img.src;
        img.style.width = img.width + "px";
        img.style.height = img.height + "px";
        img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
        img.src = shim;
    };
    
    return {
        init: function() { 
            fnLoadPngs();
        },

        // limit to part of the page ... pass an ID to limitTo:
        // supersleight.limitTo('header');
        limitTo: function(el) {
            root = el;
            fnLoadPngs();
        },
        
        run: function() {
            fnLoadPngs();
        }
    };
}();

$(document).ready(function(){
// Fix Png for IE6
    if ((/MSIE (5\.5|6\.)/).test(navigator.userAgent)) { //Exception for IE6 and below
            supersleight.init();
    }
})