//
// 	PNGFix for IE 5.5+
//	Lightweight edition for specific IMG tags use only
//
//	Copyright (c) 2006 REDD Media - www.redd.com.au
//	Use on websites without written permission from REDD Media is prohibited by law
//

// edit these as needed
__pngFix_blankImage = "b.gif";
__pngFix_className = "image-png";

//  preload the blank image
__pngFix_blankImg = new Image();
__pngFix_blankImg.src = __pngFix_blankImage;

// other values
__pngFix_filterName = "DXImageTransform.Microsoft.AlphaImageLoader";
__pngFix_browserOkFlag = null;

function __pngFix_isOk ()
{
	// discover if the fix is applicable to this browser and cache the result

	try
	{
		var iever = parseFloat(navigator.userAgent.match(/MSIE (\S+)/)[1]);
		if (__pngFix_browserOkFlag == null)
			__pngFix_browserOkFlag = (iever >= 5.5 && iever < 7);
	}
	catch (e)
	{
		__pngFix_browserOkFlag = false
	}

	return __pngFix_browserOkFlag;
}

function __pngFix_apply (e, skipOkCheck)
{
	// if the browser check is ok apply the fix to this element

	if (typeof skipOkCheck == "undefined")
		skipOkCheck = false;

	if (!skipOkCheck && !__pngFix_isOk())
		return;

	switch (e.tagName)
	{
		case "IMG":
		case "INPUT":
			__pngFix_filter(e);
			break;
	}
}

function __pngFix_filter (e)
{
	// apply fix to given element

	var f = e.filters[__pngFix_filterName];

	if (!f)
	{
		e.width = e.width;
		e.height = e.height;
		e.style.filter = 'progid:'+ __pngFix_filterName +'(enabled=true,src="'+ e.src +'",sizingMethod=scale)';
		e.src = __pngFix_blankImage;
	}
}

function __pngFix_applyAll_repeat ()
{
	// schedule a repeat of the applyAll routine
	// used to wait for incomplete images

	window.setTimeout("__pngFix_applyAll();", 250);
}

function __pngFix_applyAll ()
{
	// scan through images and form elements looking for a specific class name and apply fix where needed

	if (!__pngFix_isOk())
		return;

	var i, j, e, elements, tags = ["input", "img"];
	var incomplete = false;

	for (j = tags.length; j--;)
	{
		var elements = document.getElementsByTagName(tags[j]);

		for (i = elements.length; i--;)
		{
			e = elements[i];

			if (e.className != __pngFix_className)
				continue;

			if (e.complete)
				__pngFix_apply(e, true);
			else
				incomplete = true;
		}
	}

	if (incomplete)
		__pngFix_applyAll_repeat();
}

function __pngFix_attachEvent (o, eventName, handler)
{
	// cross-browser event attach code
	// shouldn't really be needed since this fix is for IE 5.5+ only but using it just incase

	if (typeof o.addEventListener != "undefined")
		o.addEventListener(eventName, handler, false);
	else if (typeof o.attachEvent != "undefined")
		o.attachEvent('on'+ eventName, handler);
}

function __pngFix_OnLoad ()
{
	// call applyAll routine on page load
	__pngFix_applyAll();
}
__pngFix_attachEvent(window, 'load', __pngFix_OnLoad);

