1 if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
2 window.attachEvent("onload", pngLoadPngs);
4 // parses all images //public
5 function pngLoadPngs()
6 {
7 var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
8 var itsAllGood = (rslt != null && Number(rslt[1]) > 5.5);
10 if (itsAllGood) {
11 for (var i = 0; i < document.images.length; i++) {
12 pngLoad(document.images[i]);
13 }
14 for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
15 var img = document.getElementsByTagName("input")[i];
16 if(typeof img.type == "string" && img.type == "image") {
17 pngLoad(img);
18 }
19 }
20 }
21 }
23 // loads an image, src is optional // public
24 function pngLoad(img,src)
25 {
26 if (typeof img == "object" && typeof img.tagName == "string" && img.tagName == "IMG")
27 {
28 // this is an image
29 if (typeof src == "string")
30 {
31 // src parameter is present
32 if (src.match(/\.png$/i) != null)
33 {
34 // this is png image
35 img.style.width = null;
36 img.style.height = null;
37 img.style.filter = null;
38 img.src = src;
39 pngSwapPrepare(img);
40 }
41 else
42 {
43 // its not a png
44 img.src = src;
45 }
46 }
47 else if (img.src.match(/\.png$/i) != null)
48 {
49 // no src arameter, but its png -> simply swap
50 pngSwapPrepare(img);
51 }
52 } else if (typeof img.tagName == "string" && img.tagName == "INPUT") {
53 if(img.src.match(/\.png$/i) != null) {
54 pngSwapPrepare(img);
55 }
56 }
58 // swap (if complete) or shedule it to onload event // private
59 function pngSwapPrepare(img)
60 {
61 if (img.complete)
62 pngSwap(img);
63 else
64 img.attachEvent("onload",pngOnLoadSwap);
65 }
67 // supposed to be called when image is loaded into memory //private
68 function pngOnLoadSwap()
69 {
70 event.srcElement.detachEvent("onload",pngOnLoadSwap);
71 pngSwap(event.srcElement);
72 }
74 // Swaps img and background //private
75 function pngSwap(img)
76 {
77 with (img)
78 {
79 style.width = width + "px";
80 style.height = height + "px";
81 style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale') ";
82 src = "images/null.gif";
83 }
84 }
85 }