/*******************************************************************************\
|	Name:		Portable Network Graphics Transform								|
|																				|
|	Filename:	png_transform.js												|
|	Version:	1.0.0															|		
|	Author:		Eric van Blokland												|
|	Project:	Shared library													|
|																				|
|	Copyright:	2006, Footsteps													|
|																				|
|	Summary:	Replaces png images with a DirectX Transform filter in Internet |
|				Explorer 5.5 and 6.x											|
|				Feel free to use this library, if you have suggestions for		|
|				possible additions, please contact us at:						|
|																				|
|				http://www.footsteps.nl											|
|																				|
\*******************************************************************************/

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

function png_transform(sElementTypes,scale) {	
	if(is_ie5_5 || is_ie6) {		
		aImg=Array();
		aImg=window.document.getElementsByTagName('img');
		for(i=0;i<aImg.length;i++) {
			var sSrc=aImg[i].src.toLowerCase();
			if(sSrc.indexOf('.png') ==aImg[i].src.length-4 ) {
				oImg=aImg[i];				
				oImg.style.visibility='hidden';
				oSpan=document.createElement('span');				
				if(oImg.height) {
					oSpan.style.height=oImg.height+'px';
					oSpan.style.width=oImg.width+'px';
				}
				else if(oImg.style.height) {
					oSpan.style.height=oImg.style.height;
					oSpan.style.width=oImg.style.width;
				}
				if(!oImg.height && !oImg.style.height) {
					oImg.onresize=png_transform_this;
				}
				else {
					oSpan.style.display='inline-block';
					oSpan.style.position='relative';
					oImg.style.display='none';
					oSpan.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oImg.src+"')";				
					oImg.insertAdjacentElement('beforeBegin', oSpan);
				}
								
			}
		}
		aElementTypes=sElementTypes.split(';');
		for(x=0;x<aElementTypes.length;x++) {
			aElements=Array();
			aElements=window.document.getElementsByTagName(aElementTypes[x]);
			for(i=0;i<aElements.length;i++) {
				if(aElements[i].style.backgroundImage) {
					var sSrc=aElements[i].style.backgroundImage.toLowerCase();
					if(sSrc.indexOf('.png)') == aElements[i].style.backgroundImage.length-5 ) {
						oElement=aElements[i];												
						oElement.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oElement.style.backgroundImage.substring(4,oElement.style.backgroundImage.length-1)+"'"+(scale ? ",sizingMethod='scale'" : "")+")";					
						oElement.style.backgroundImage='';	
					}
				}
			}
		}
	}
}
function png_transform_byid(id,scale) {
	if(is_ie5_5 || is_ie6) {
		oElement=document.getElementById(id);
		if(oElement && oElement.style.backgroundImage) {
			var sSrc=oElement.style.backgroundImage.toLowerCase();
			if(sSrc.indexOf('.png)') == oElement.style.backgroundImage.length-5 ) {			
				oElement.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oElement.style.backgroundImage.substring(4,oElement.style.backgroundImage.length-1)+"'"+(scale ? ",sizingMethod='scale'" : "")+")";					
				oElement.style.backgroundImage='';					
			}
		}
	}
}
function png_transform_byclass(classname,scale) {
	if(is_ie5_5 || is_ie6) {
		aElements=Array();
		aElements=window.document.getElementsByTagName(aElementTypes[x]);
		for(i=0;i<aElements.length;i++) {
			if(aEelements[i].className==classname && aElements[i].style.backgroundImage) {
				var sSrc=aElements[i].style.backgroundImage.toLowerCase();
				if(sSrc.indexOf('.png)') == aElements[i].style.backgroundImage.length-5 ) {
					oElement=aElements[i];												
					oElement.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oElement.style.backgroundImage.substring(4,oElement.style.backgroundImage.length-1)+"'"+(scale ? ",sizingMethod='scale'" : "")+")";					
					oElement.style.backgroundImage='';	
				}
			}
		}
	}
}
function png_transform_this() {
	this.onresize=null;
	if(is_ie5_5 || is_ie6) {
		if(this.src) {
			var sSrc=this.src.toLowerCase();
			if(sSrc.indexOf('.png') ==this.src.length-4 ) {
				oImg=this;				
				oImg.style.visibility='hidden';
				oSpan=document.createElement('span');	
				if(oImg.height) {
					oSpan.style.height=oImg.height+'px';
					oSpan.style.width=oImg.width+'px';
				}
				else if(oImg.style.height) {
					oSpan.style.height=oImg.style.height;
					oSpan.style.width=oImg.style.width;
				}
				if(!oImg.height && !oImg.style.height) {			
					oImg.onresize=png_transform_this;
				}
				else {					
					oSpan.style.display='inline-block';
					oSpan.style.position='relative';
					oImg.style.display='none';
					oSpan.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oImg.src+"')";				
					oImg.insertAdjacentElement('beforeBegin', oSpan);
				}
			}
		}
		else if(this.style.backgroundImage) {
			var sSrc=this.style.backgroundImage.toLowerCase();
			if(sSrc.indexOf('.png)') == this.style.backgroundImage.length-5 ) {			
				this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+get_base_href()+oElement.style.backgroundImage.substring(4,oElement.style.backgroundImage.length-1)+"'"+(scale ? ",sizingMethod='scale'" : "")+")";					
				this.style.backgroundImage='';					
			}
		}
	}	
}
