/***********************************************************************************
 * Arquivo: PNGSuporteIE.js
 * Dependência(s) (outros arquivos): Nenhum arquivo
 * Funções: verificarIE55_6 e habilitarPNGSuporteIE
 * Descrição: Fornece suporte a transparências alfa de imagens Portable Network
 *            Graphics (PNG) no Internet Explorer 5.5 e 6.0
 * Autor: Rogério Moraes de Carvalho (rogeriom@gmx.net) / Thiago Sousa (www.thsl.com.br)
***********************************************************************************/

/***********************************************************************************
* Função: verificarIE55_6
* Argumentos: Nenhum
* Retorno: Valor booleano indicando se o browser é o Internet Explorer 5.5 ou 6.0
* Descrição: Verifica se o browser é o Internet Explorer 5.5 ou 6.0
***********************************************************************************/
function verificarIE55_6() {
	var pos = navigator.userAgent.indexOf("MSIE ");
	var ie = (pos != -1);
	var ie55_6 = false;

	if (ie) {
		var versao = navigator.userAgent.substring(pos + 5);
		ie55_6 = ((versao.indexOf("5.5") == 0) || (versao.indexOf("6") == 0));
	}

	return ie55_6;
}
		
/***********************************************************************************
* Função: habilitarPNGSuporteIE
* Argumentos: Nenhum
* Retorno: Nenhum
* Descrição: Modifica todos os tags IMG com imagens PNG para tags SPAN com suporte
*            a transparências alfa (AlphaImageLoader)
***********************************************************************************/
function habilitarPNGSuporteIE() {
	var img, imgID, imgClasse, imgTitulo, imgEstilo, spanHTML;
	
	if (verificarIE55_6()) {
		for(var i = 0; i < document.images.length; i++) {
			img = document.images[i];
			if (img.src.substring(img.src.length - 3).toUpperCase() == "PNG") {
				imgID = (img.id) ? " id='" + img.id + "'" : "";
				imgClasse = (img.className) ? " class='" + img.className + "'" : "";
				imgTitulo = (img.title) ? " title='" + img.title + "'" : ((img.alt) ? " title='" + img.alt + "' " : "");
				imgEstilo = " style=\"display:inline-block;";
				imgEstilo += "width:" + img.width + "px;";
				imgEstilo += "height:" + img.height + "px;";
				imgEstilo += (img.align == "left") ? "float:left;" : "";
				imgEstilo += (img.align == "right") ? "float:right;" : "";
				imgEstilo += (img.parentElement.href) ? "cursor:hand;" : "";
				imgEstilo += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
				imgEstilo += "(src='" + img.src + "',sizingMethod='scale');";
				imgEstilo += img.style.cssText + "\"";
				spanHTML = "<span" + imgID + imgClasse + imgTitulo + imgEstilo + "></span>";
				img.outerHTML = spanHTML;
				i--; // Ajusta o contador, uma vez que um elemento IMG foi retirado do documento HTML
			}
		}
	}
}


if (verificarIE55_6()) {
	window.attachEvent("onload", habilitarPNGSuporteIE);
}
