//\/////
//\  overLIB PNG Fix Plugin
//\			Created 5/12/2006.  Applies the procedure explained
//\			in http://homepage.ntlworld.com/bobosola.
//\
//\  You may not remove or change this notice.
//\  Copyright Erik Bosrup 1998-2003. All rights reserved.
//\  Contributors are listed on the homepage.
//\  See http://www.bosrup.com/web/overlib/ for details.
//\/////
////////
// PRE-INIT
// Ignore these lines, configuration is below.
////////
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.14)) alert('overLIB 4.14 or later is required for the PNG Fix Plugin.');
else {
registerCommands('pngfix');
////////
// DEFAULT CONFIGURATION
// Settings you want everywhere are set here. All of this can also be
// changed on your html page or through an overLIB call.
////////
if (typeof ol_pngfix=='undefined') var ol_pngfix=0;
////////
// END OF CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////
////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_pngfix=0;
// PLUGIN FUNCTIONS
////////
// Set runtime variables
function setPNGFixVariables() {
	o3_pngfix=ol_pngfix;
}
// Parses Exclusive Parameters
function parsePNGFixExtras(pf,i,ar) {
	var k=i,v;
	if (k < ar.length) {
		if (ar[k]==PNGFIX) { eval(pf +'pngfix=('+pf+'pngfix==0) ? 1 : 0'); return k; }
	}
	return -1;
}
///////
//  HELPER FUNCTIONS
///////
function pngFix(img) {
	var imgID = (img.id) ? "id=\'" + img.id + "\' " : "";
	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.parentNode.href) imgStyle = "cursor:hand; " + imgStyle;
	if (img.align == "left") imgStyle = "float:left; " + imgStyle;
	if (img.align == "right") imgStyle = "float:right; " + imgStyle;
	imgStyle = imgStyle.replace(/;\s+$/,';');
	var strNewHTML = "<span " + imgID + imgClass + imgTitle
	+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle 
	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	+ "(src=\'" + img.src + "\', sizingMethod=\'scale\');\"></span>" 
	return strNewHTML;
}
function applyPNGFix(obj) {
	if ( !o3_pngfix || (olIe4&&(isMac||olOp)) || !olIe4 ) return;
	if (olIe5 || olIe55) {
		if (!obj) obj = over;
		var nStr, content=obj.innerHTML, imgs = obj.getElementsByTagName('img');
		if (imgs && imgs.length) {
			for (var i=0; i<imgs.length; i++) {
				if (!/\.png/i.test(imgs[i].src)) continue;
				nStr = pngFix(imgs[i]);
				content = content.replace(/<img.*?\s?\/?>/i, nStr);
			}
			obj.innerHTML = content;
		}
	}
}
function fixImage(img) {
	if ( (olIe4&&(isMac||olOp)) || !olIe4 ) return;
	if (olIe5 || olIe55) {
		var nStr;
		if (/\.png/i.test(img.src)) {
			nStr = pngFix(img);
			img.outerHTML = nStr;
		}
	}
}
////////
// PLUGIN REGISTRATIONS
////////
registerRunTimeFunction(setPNGFixVariables);
registerCmdLineFunction(parsePNGFixExtras);
registerHook("showObject",applyPNGFix,FBEFORE);
if (olInfo.meets(4.14)) registerNoParameterCommands('pngfix');
}
