/**
* PNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/PNG/
* Version: 0.0.7a
* Licensed under the MIT License: http://dillerdesign.com/experiment/PNG/#license
*
* Example usage:
* PNG.fix('.png_bg'); // argument is a CSS selector
* PNG.fixPng( someNode ); // argument is an HTMLDomElement
**/
/*
PLEASE READ:
Absolutely everything in this script is SILLY.  I know this.  IE's rendering of certain pixels doesn't make sense, so neither does this code!
*/
var PNG={ns:"PNG",imgSize:{},createVmlNameSpace:function(){document.namespaces&&!document.namespaces[this.ns]&&document.namespaces.add(this.ns,"urn:schemas-microsoft-com:vml"),window.attachEvent&&window.attachEvent("onbeforeunload",function(){PNG=null})},createVmlStyleSheet:function(){var a=document.createElement("style");document.documentElement.firstChild.insertBefore(a,document.documentElement.firstChild.firstChild);var b=a.styleSheet;b.addRule(this.ns+"\\:*","{behavior:url(#default#VML)}"),b.addRule(this.ns+"\\:shape","position:absolute;"),b.addRule("img."+this.ns+"_sizeFinder","behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;"),this.styleSheet=b},readPropertyChange:function(){var a=event.srcElement;(event.propertyName.search("background")!=-1||event.propertyName.search("border")!=-1)&&PNG.applyVML(a);if(event.propertyName=="style.display"){var b=a.currentStyle.display=="none"?"none":"block";for(var c in a.vml)a.vml[c].shape.style.display=b}event.propertyName.search("filter")!=-1&&PNG.vmlOpacity(a)},vmlOpacity:function(a){if(a.currentStyle.filter.search("lpha")!=-1){var b=a.currentStyle.filter;b=parseInt(b.substring(b.lastIndexOf("=")+1,b.lastIndexOf(")")),10)/100,a.vml.color.shape.style.filter=a.currentStyle.filter,a.vml.image.fill.opacity=b}},handlePseudoHover:function(a){setTimeout(function(){PNG.applyVML(a)},1)},fix:function(a){var b=a.split(",");for(var c=0;c<b.length;c++)this.styleSheet.addRule(b[c],"behavior:expression(PNG.fixPng(this))")},applyVML:function(a){a.runtimeStyle.cssText="",this.vmlFill(a),this.vmlOffsets(a),this.vmlOpacity(a),a.isImg&&this.copyImageBorders(a)},attachHandlers:function(a){var b=this,c={resize:"vmlOffsets",move:"vmlOffsets"};if(a.nodeName=="A"){var d={mouseleave:"handlePseudoHover",mouseenter:"handlePseudoHover",focus:"handlePseudoHover",blur:"handlePseudoHover"};for(var e in d)c[e]=d[e]}for(var f in c)a.attachEvent("on"+f,function(){b[c[f]](a)});a.attachEvent("onpropertychange",this.readPropertyChange)},giveLayout:function(a){a.style.zoom=1,a.currentStyle.position=="static"&&(a.style.position="relative")},copyImageBorders:function(a){var b={borderStyle:!0,borderWidth:!0,borderColor:!0};for(var c in b)a.vml.color.shape.style[c]=a.currentStyle[c]},vmlFill:function(a){if(!a.currentStyle)return;var b=a.currentStyle;for(var c in a.vml)a.vml[c].shape.style.zIndex=b.zIndex;a.runtimeStyle.backgroundColor="",a.runtimeStyle.backgroundImage="";var d=b.backgroundColor=="transparent",e=!0;if(b.backgroundImage!="none"||a.isImg){a.isImg?a.vmlBg=a.src:(a.vmlBg=b.backgroundImage,a.vmlBg=a.vmlBg.substr(5,a.vmlBg.lastIndexOf('")')-5));var f=this;if(!f.imgSize[a.vmlBg]){var g=document.createElement("img");f.imgSize[a.vmlBg]=g,g.className=f.ns+"_sizeFinder",g.runtimeStyle.cssText="behavior:none; position:absolute; left:-10000px; top:-10000px; border:none;",g.attachEvent("onload",function(){this.width=this.offsetWidth,this.height=this.offsetHeight,f.vmlOffsets(a)}),g.src=a.vmlBg,g.removeAttribute("width"),g.removeAttribute("height"),document.body.insertBefore(g,document.body.firstChild)}a.vml.image.fill.src=a.vmlBg,e=!1}a.vml.image.fill.on=!e,a.vml.image.fill.color="none",a.vml.color.shape.style.backgroundColor=b.backgroundColor,a.runtimeStyle.backgroundImage="none",a.runtimeStyle.backgroundColor="transparent"},vmlOffsets:function(a){var b=a.currentStyle,c={W:a.clientWidth+1,H:a.clientHeight+1,w:this.imgSize[a.vmlBg].width,h:this.imgSize[a.vmlBg].height,L:a.offsetLeft,T:a.offsetTop,bLW:a.clientLeft,bTW:a.clientTop},d=c.L+c.bLW==1?1:0,e=function(a,b,c,d,e,f){a.coordsize=d+","+e,a.coordorigin=f+","+f,a.path="m0,0l"+d+",0l"+d+","+e+"l0,"+e+" xe",a.style.width=d+"px",a.style.height=e+"px",a.style.left=b+"px",a.style.top=c+"px"};e(a.vml.color.shape,c.L+(a.isImg?0:c.bLW),c.T+(a.isImg?0:c.bTW),c.W-1,c.H-1,0),e(a.vml.image.shape,c.L+c.bLW,c.T+c.bTW,c.W,c.H,1);var f={X:0,Y:0},g=function(a,b){var d=!0;switch(b){case"left":case"top":f[a]=0;break;case"center":f[a]=.5;break;case"right":case"bottom":f[a]=1;break;default:b.search("%")!=-1?f[a]=parseInt(b)*.01:d=!1}var e=a=="X";f[a]=Math.ceil(d?c[e?"W":"H"]*f[a]-c[e?"w":"h"]*f[a]:parseInt(b)),f[a]==0&&f[a]++};for(var h in f)g(h,b["backgroundPosition"+h]);a.vml.image.fill.position=f.X/c.W+","+f.Y/c.H;var i=b.backgroundRepeat,j={T:1,R:c.W+d,B:c.H,L:1+d},k={X:{b1:"L",b2:"R",d:"W"},Y:{b1:"T",b2:"B",d:"H"}};if(i!="repeat"){var l={T:f.Y,R:f.X+c.w,B:f.Y+c.h,L:f.X};if(i.search("repeat-")!=-1){var m=i.split("repeat-")[1].toUpperCase();l[k[m].b1]=1,l[k[m].b2]=c[k[m].d]}l.B>c.H&&(l.B=c.H),a.vml.image.shape.style.clip="rect("+l.T+"px "+(l.R+d)+"px "+l.B+"px "+(l.L+d)+"px)"}else a.vml.image.shape.style.clip="rect("+j.T+"px "+j.R+"px "+j.B+"px "+j.L+"px)"},fixPng:function(a){a.style.behavior="none";if(a.nodeName=="BODY"||a.nodeName=="TD"||a.nodeName=="TR")return;a.isImg=!1;if(a.nodeName=="IMG")if(a.src.toLowerCase().search(/\.png$/)!=-1)a.isImg=!0,a.style.visibility="hidden";else return;else if(a.currentStyle.backgroundImage.toLowerCase().search(".png")==-1)return;var b=PNG;a.vml={color:{},image:{}};var c={shape:{},fill:{}};for(var d in a.vml){for(var e in c){var f=b.ns+":"+e;a.vml[d][e]=document.createElement(f)}a.vml[d].shape.stroked=!1,a.vml[d].shape.appendChild(a.vml[d].fill),a.parentNode.insertBefore(a.vml[d].shape,a)}a.vml.image.shape.fillcolor="none",a.vml.image.fill.type="tile",a.vml.color.fill.on=!1,b.attachHandlers(a),b.giveLayout(a),b.giveLayout(a.offsetParent),b.applyVML(a)}};try{document.execCommand("BackgroundImageCache",!1,!0)}catch(r){}PNG.createVmlNameSpace(),PNG.createVmlStyleSheet()
