var imgElements = {
	options:{
		my_url: "",
		objAry: new Array("a", "h2", "h6", "strong", "h1", "h4"),
		myClassNameFind: "avantG",
		myFont: "AVGARDM.TTF"
	},
	init: function(opts) {
		for (name in opts) imgElements.options[name] = opts[name];
		if(document.getElementsByTagName && document.createTextNode) {
			for(var iObj=0; iObj < imgElements.options.objAry.length; iObj++){
				var cella_obj = document.getElementsByTagName(imgElements.options.objAry[iObj]);
				for(i_a=0; i_a < cella_obj.length; i_a++){
					if(cella_obj[i_a].className && cella_obj[i_a].className == imgElements.options.myClassNameFind && cella_obj[i_a].firstChild.nodeValue != null){
						var mySrcRew = imgElements.options.my_url+'/bunker/img_inc_java.php?font=' + imgElements.options.myFont + '&class=' + cella_obj[i_a].className + '&valore=' + Base64.encode(addslashes(cella_obj[i_a].firstChild.nodeValue).replace(/&/g, '{amp}').replace(/\+/g, '{plus}')) + '&color='+ getStyle(cella_obj[i_a], "color") + '&size='+ getStyle(cella_obj[i_a], "font-size");
						if(progidIe7()){
							cella_obj[i_a].innerHTML = '<img src="/images/blank.gif" alt="' + addslashes(cella_obj[i_a].firstChild.nodeValue) + '" border="0" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ mySrcRew +'\', sizingMethod=\'image\')" />';
						} else {
							cella_obj[i_a].innerHTML = '<img src="'+ mySrcRew +'" alt="' + addslashes(cella_obj[i_a].firstChild.nodeValue) + '" border="0" />';
						}
					}
				}
			}
		} else {
			alert("Metodo non supportato!");	
		}
	}
}


function progidIe7(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if (ievs){
		var iev = new Number(RegExp.$1);
		if (iev < 7) return true;
	}
	return false;
}

function addslashes(str) {
	if(str != null){
		str = str.replace("'","`");
		str = str.replace("€","{euro}");
	}
	return str;
}

function getStyle(el, prop) {
	if(el.currentStyle) {
		if(prop.indexOf('-') > -1)
			prop = prop.split('-')[0]+prop.split('-')[1].substr(0, 1).toUpperCase()+prop.split('-')[1].substr(1);
		var y = el.currentStyle[prop];
	}else if(window.getComputedStyle) {
		var y = document.defaultView.getComputedStyle(el,'').getPropertyValue(prop);
	}
	y = y.replace("px", "");
	if (y.indexOf('rgb') != -1){
		y = y.replace("rgb(", "");
		y = y.replace(")", "");
		y = y.replace(/" "/g, "");
	} else if (y.indexOf('#') != -1 && (y.length == 7 || y.length == 4) && prop == "color"){
		y = y.replace("#", "");
		if(y.length == 3){
			y = y.substring(0,1)+y.substring(0,1)+y.substring(1,2)+y.substring(1,2)+y.substring(2,3)+y.substring(2,3);
		}
		var myEsa = new Array();
		myEsa["0"] = 0;
		myEsa["1"] = 1;
		myEsa["2"] = 2;
		myEsa["3"] = 3;
		myEsa["4"] = 4;
		myEsa["5"] = 5;
		myEsa["6"] = 6;
		myEsa["7"] = 7;
		myEsa["8"] = 8;
		myEsa["9"] = 9;
		myEsa["A"] = 10;
		myEsa["B"] = 11;
		myEsa["C"] = 12;
		myEsa["D"] = 13;
		myEsa["E"] = 14;
		myEsa["F"] = 15;
		y = parseInt(myEsa[y.substring(0,1).toUpperCase()]*14 + myEsa[y.substring(1,2).toUpperCase()]*1)+","+parseInt(myEsa[y.substring(2,3).toUpperCase()]*14 + myEsa[y.substring(3,4).toUpperCase()]*1)+","+parseInt(myEsa[y.substring(4,5).toUpperCase()]*14 + myEsa[y.substring(5,6).toUpperCase()]*1);
	}
	return y;
}


var Base64 = {
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_,",
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) output = output + String.fromCharCode(chr2);
			if (enc4 != 64) output = output + String.fromCharCode(chr3);
		}
		output = Base64._utf8_decode(output);
		return output;
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
