﻿function correctPNG(img) 
{
    var imgName = img.src
    if (imgName.match(/\.png$/i)) 
    {
        var span = null;
        if (img.tid) 
        {
            span = document.getElementById(img.tid);
        }
        else 
        {
            span = document.createElement("span");
            span.id = "_" + Math.random() * 100;
            img.tid = span.id;
            img.parentElement.insertBefore(span, img);
        }
        span.className = img.className ? img.className : "";
        span.title = img.alt ? img.alt : "";
        var imgClass = (img.className) ? "class='" + img.className + "' " : ""
        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
        var imgStyle = "display:inline-block;" + img.style.cssText
        if (img.align == "left") imgStyle = "float:left;" + imgStyle
        if (img.align == "right") imgStyle = "float:right;" + imgStyle
        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
        span.style.cssText = "width:" + img.width + "px;height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');"
        img.style.display = "none";
    }
    else 
    {
        if (img.tid)
         {
            document.getElementById(img.tid).style.display = "none";
        }
        img.style.display = "";
    }
}


function imgInit() 
{
    for (var i = 0, img; img = document.images[i]; i++)
     {
        img.attachEvent("onload", function() { correctPNG(event.srcElement) });
        correctPNG(img);
    }
}
window.attachEvent("onload", imgInit);
