var imgElements = {
	options:{
		my_url: "",
		objAry: new Array("a", "h2", "h6", "strong", "h1", "h2", "h3", "h4", "span", "big", "small"),
		myClassNameFind: "",
		myFont: "",
		shadowColor: "",
		shadowPos:"",
		shadowAlpha: "100"
	},
	init: function(opts) {
		var wrapmode = 'nowrap';
		imgElements.options.shadowAlpha = 100;
		imgElements.options.shadowColor = "";
		for (name in opts) {
			if(name != 'wrapmode' && name != 'shadowAlpha'){
				imgElements.options[name] = opts[name];
			} else {
				if(name = 'wrapmode') wrapmode = opts[name];
				if(name = 'shadowAlpha') imgElements.options.shadowAlpha = 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.indexOf(imgElements.options.myClassNameFind)!=-1) && cella_obj[i_a].firstChild != null){
						if(cella_obj[i_a].firstChild.nodeValue != "" && cella_obj[i_a].firstChild.nodeValue != null){
							if(wrapmode != 'nowrap' && wrapmode == 'wrap'){
								var myTextExplode = cella_obj[i_a].firstChild.nodeValue.split(' ');
								cella_obj[i_a].innerHTML = "";
								for(var iEx = 0; iEx < myTextExplode.length; iEx++){
									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(myTextExplode[iEx]).replace(/&/g, '{amp}').replace(/\+/g, '{plus}')) + '&color='+ getStyle(cella_obj[i_a], "color") + '&size='+ getStyle(cella_obj[i_a], "font-size");
									if(getStyle(cella_obj[i_a], "letter-spacing") != "normal" && getStyle(cella_obj[i_a], "letter-spacing") != 0) mySrcRew = mySrcRew + '&spacing='+ getStyle(cella_obj[i_a], "letter-spacing");
									if(imgElements.options.shadowColor != ""){
										mySrcRew = mySrcRew + '&shadowColor='+ returnsEsa(imgElements.options.shadowColor);
										if(imgElements.options.shadowPos != "")	mySrcRew = mySrcRew + '&shadowPos='+ imgElements.options.shadowPos;
										if(imgElements.options.shadowAlpha != "100") mySrcRew = mySrcRew + '&shadowAlpha='+ imgElements.options.shadowAlpha;
									}
									mySrcRew = mySrcRew.replace(/\ /g, '');
									if(progidIe7()){
										cella_obj[i_a].innerHTML = cella_obj[i_a].innerHTML +'<span style="clear:both;"><img src="/images/blank.gif" alt="' + addslashes(myTextExplode[iEx]) + '" border="0" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ mySrcRew +'\', sizingMethod=\'image\')" /></span>';
									} else {
										cella_obj[i_a].innerHTML = cella_obj[i_a].innerHTML +'<span style="clear:both;"><img src="'+ mySrcRew +'" alt="' + addslashes(myTextExplode[iEx]) + '" border="0" /></span>';
									}
								}
							} else {
								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(getStyle(cella_obj[i_a], "letter-spacing") != "normal" && getStyle(cella_obj[i_a], "letter-spacing") != 0) mySrcRew = mySrcRew + '&spacing='+ getStyle(cella_obj[i_a], "letter-spacing");
								if(imgElements.options.shadowColor != ""){
									mySrcRew = mySrcRew + '&shadowColor='+ returnsEsa(imgElements.options.shadowColor);
									if(imgElements.options.shadowPos != "")	mySrcRew = mySrcRew + '&shadowPos='+ imgElements.options.shadowPos;
									if(imgElements.options.shadowAlpha != "100") mySrcRew = mySrcRew + '&shadowAlpha='+ imgElements.options.shadowAlpha;
								}
								mySrcRew = mySrcRew.replace(/\ /g, '');
								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) {
	return str;
	
}

function getStyle(el, prop) {
	if (el.currentStyle) { // IE, Opera
		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);
	}
	if(y == null || y == undefined)	return false;
	if(y == '100%') y = '14';
	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 = (myEsa[y.substring(0,1).toUpperCase()]*16 + myEsa[y.substring(1,2).toUpperCase()]*1)+","+(myEsa[y.substring(2,3).toUpperCase()]*16 + myEsa[y.substring(3,4).toUpperCase()]*1)+","+(myEsa[y.substring(4,5).toUpperCase()]*16 + myEsa[y.substring(5,6).toUpperCase()]*1);
	}
	return y;
}

function returnsEsa(y){
	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)){
		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 = (myEsa[y.substring(0,1).toUpperCase()]*16 + myEsa[y.substring(1,2).toUpperCase()]*1)+","+(myEsa[y.substring(2,3).toUpperCase()]*16 + myEsa[y.substring(3,4).toUpperCase()]*1)+","+(myEsa[y.substring(4,5).toUpperCase()]*16 + 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;
	}
}

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