﻿/**
 * Emanuele Poglinai
 * Etnoteam S.p.A
 * 20 dicembre 2007
 *
 * NOTA: necessario il file x.gif nello stesso folder dei .js, necessario al funzionamento
 *       della funzione bg_fnFixPng
 */


/**
 * ottiene la proprietà di uno stile dato l'id di un elemento sul quale è applicato
 *
 * @param el 				 : id elemanto 
 * @param styleProp  : propretà da cui ottenere le info
 * @return proprietà : stringa che contiene la proprietà
 */	
function getStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (x.currentStyle) {
		var y = x.currentStyle[styleProp];
	 	if (y == null && styleProp.match('background-image')) y = x.currentStyle.backgroundImage;
	}
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
		
/**
 * funzione che sistema il problema di visualizzazione dei livelli di sfumatura trasparente dei .png
 * su ie, viene applicato sul background
 *
 * @param objId : id dell'elemento sul quale è applicato lo stile contente il background png
 */
function bg_fnFixPng(objId) {
	var shim = 'x.gif';
	var mode = 'scale';
	var obj = document.getElementById(objId);
	var bg	= getStyle(objId,'background-image');
	var src = bg.substring(5,bg.length-2);
	if (!obj.currentStyle) return;
	if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
		mode = 'crop';
	}
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
	obj.style.backgroundImage = 'url('+shim+')';
}