var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var IE = navigator.appName.indexOf ("Internet Explorer") > -1;
var FF = navigator.appName.indexOf ("Netscape") > -1;
var timer = 0;
var mx, my;

var menu = new Array();
var Voce_Attiva = new Array();
var sottomenu_attivo = false;

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 45;
// -----------------------------------------------------------------------------

document.write ('<script src="/js/AC_RunActiveContent.js" language="javascript"></script>');

function mostraPagina() {
	document.getElementById("pg").style.visibility = "visible";
	document.getElementById("loading").style.visibility = "hidden";
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function vg1_DoFSCommand(command, args) {
	//var vg1Obj = isIE ? document.all.vg1 : document.vg1;
	/*if (command == "apri") {
		window.open("/inc/photoParser.php?photo=" + args, "_blank", "toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no, resizable=no'");
	}*/
	
	var mwBG = document.getElementById("mwBG");
	if (!mwBG) {
		mwBG = document.createElement("div");
		mwBG.id = "mwBG";
		mwBG.style.position = "fixed";
		mwBG.style.top = "0px";
		mwBG.style.left = "0px";
		mwBG.style.background = "#111";
		mwBG.style.opacity = '.5';
        mwBG.style.filter = 'alpha(opacity=50)';
		document.body.appendChild(mwBG);
	}
	mwBG.style.zIndex = 200;
	mwBG.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
	mwBG.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
	mwBG.style.display = 'block';
		
	
	var pu = document.getElementById("popupVG");
	if (!pu) {
		pu = document.createElement("div");
		pu.id = "popupVG";
		pu.style.position = "fixed";
		pu.style.display = 'none';
		pu.style.width = "660px";
		pu.style.height = "600px";
		document.body.appendChild(pu);
	}
	pu.style.zIndex = 201;
	if (command == "apri") {
		param = args.split(",");
		argomenti = "?idGlr=" + param[0] + "&mastro=" + param[1] + "&idLng=" + param[2] + "&clicbl=1&idImg=" + param[3];
		pu.innerHTML = "<table id='imgPU' border=0 cellspacing=1 cellpadding=5 bgcolor='#cccccc' width=100% height=100%>" +
				   "<tr><td bgcolor='#ffffff' width=660 height=550><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'" +
				   "id='vgGrande' width='660' height='550' align='middle'><param name='allowScriptAccess' value='sameDomain' />" +
				   "<param name='movie' value='/inc/vg.swf" + argomenti + "' /><param name='quality' value='high' /><param name='wmode' value='transparent' />"+
				   "<param name='bgcolor' value='#ffffff' />" +
				   "<embed src='/inc/vg.swf" + argomenti + "' quality='high' wmode='transparent' bgcolor='#ffffff' width='660' height='550' swLiveConnect=true id='vgGrande'" +
				   "name='vgGrande' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
					"</object><tr><td bgcolor='#ffffff' align=center><a style='cursor: pointer; cursor: hand' onclick='chiudiPopup()'><small>chiudi</small></a></td></tr></table>";
	} else if (command == "mostraVideo") {
		param = args.split("xfsnetx");
		param[1] = unescape(param[1]);
		ext = param[0].split('.');
		ext = "." + ext[ext.length-1].toLowerCase();
		immagini = ".jpg,.png,.gif,.tif,.jpeg,.tiff";
		flash = ".flv";
		video = ".wmv,.mpg,.mpeg,.avi,.mov";
		if (immagini.search(ext) >= 0) {
/*			var lrgImm = this.lrgImm != undefined ? this.lrgImm + 10 : 500;
			var altImm = this.altImm != undefined ? this.altImm + 10 : 420;*/
			var lrgImm = document.body.clientWidth * .75;
			var altImm = document.body.clientHeight * .75;
			var inner = "<table id='imgPU' border=0 cellspacing=1 cellpadding=5 bgcolor='#cccccc'>" +
						"<tr><td align=center valign=middle bgcolor='#ffffff' height=50>" + param[1] + "</td></tr><tr><td bgcolor='#ffffff' align=center valign=middle style='width: " + lrgImm + "px; height: " + altImm + "px'><img src='" + param[0] + "'></td></tr>";
			if (document.getElementById('play')) {
				inner += "<tr><td bgcolor='#ffffff' align=center valign=middle><img id='indietro' src='/imgs/icone/prevNew.gif' title='indietro' style='cursor:hand;cursor:pointer' onclick='scorriImmagini(-1,1)'/>&nbsp;" + 
								"<img id='fsPlay' src='/imgs/icone/playNew.gif' title='play' style='cursor:hand;cursor:pointer;display:" + document.getElementById('play').style.display + "' onclick='document.getElementById(\"play\").style.display=\"none\";document.getElementById(\"pause\").style.display=\"\";scrollView(1,1);'/>" + 
								"<img id='fsStop' src='/imgs/icone/pauseNew.gif' style='display: " + document.getElementById('pause').style.display + ";cursor:hand;cursor:pointer' title='stop' onclick='document.getElementById(\"pause\").style.display=\"none\"; this.style.display=\"none\"; document.getElementById(\"play\").style.display=\"\"; document.getElementById(\"fsPlay\").style.display=\"\";scrollView(0,1)'/>&nbsp;" +
								"<img id='avanti' src='/imgs/icone/nextNew.gif' title='avanti' style='cursor:hand;cursor:pointer' onclick='scorriImmagini(1,1)'/>&nbsp;" +
								"<img id='chiudi' src='/imgs/icone/chiudiNew.gif' title='avanti' style='cursor:hand;cursor:pointer' onclick='document.getElementById(\"play\").style.display=\"\"; document.getElementById(\"stop\").style.display=\"none\"; scrollView(0,1);chiudiPopup()'/></td></tr>";
			} else {
				inner += "<tr><td bgcolor='#ffffff' align=center valign=middle><img id='chiudi' src='/imgs/icone/chiudiNew.gif' title='avanti' style='cursor:hand;cursor:pointer' onclick='chiudiPopup()'/></td></tr>";
			}
			inner += "</table>";
			pu.innerHTML = inner;
		} else if (video.search(ext) >= 0) {
			pu.innerHTML = "<table id='imgPU' border=0 cellspacing=1 cellpadding=5 bgcolor='#cccccc' width=500 height=450>" +
						"<tr><td bgcolor='#ffffff' width=500 height=450 align=center valign=middle>" +
						'<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" ' +
						'width="320" height="290" id="VG" title="' + (param[1]) + '">' +
						'	<param name="AutoStart" value="true">' +
						'	<param name="ShowControls" value="true">' +
						'	<param name="ShowStatusBar" value="true">' +
						'	<param name="ShowDisplay" value="false">' +
						'	<param name="AutoRewind" value="false">' +
						'	<param name="windowlessVideo" value="false">' +
						'	<param name="SendPlayStateChangeEvents" value="true">' +
						'	<param name="stretchToFit" value="false">' +
						'	<param name="FullScreen" value="false">' +
						'	<param name="URL" value="' + param[0] + '">' + 
						'	<param name="Filename" value="' + param[0] + '">' + 
						'	<embed ' +
						'		type="application/x-mplayer2" ' +
						'		pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
						'		src="' + param[0] + '" ' +
						'		width="173" height="180" ' +
						'		autostart="true" ' +
						'		showcontrols="true" ' +
						'		showstatusbar="true" ' +
						'		showdisplay="false" ' +
						'		autorewind="false" ' +
						'		windowlessVideo="false" ' +
						'		fullScreen="false" ' +
						'		SendPlayStateChangeEvents="true" ' +
						'		stretchToFit="false">' +
						'	</embed>' +
						"</object><br><br>" + param[1] + "<tr><td bgcolor='#ffffff' align=center><a style='cursor: pointer; cursor: hand' onclick='chiudiPopup()'><small>chiudi</small></a></td></tr></table>";
		} else if (flash.search(ext) >= 0) {
		}
	}
	dimensionaPopup();
}

function chiudiPopup() {
	var pu = document.getElementById("popupVG");
	if (pu) { 
		pu.innerHTML = "";
		pu.style.display = "none"; 
	}
	var mwBG = document.getElementById("mwBG");
	if (mwBG) { mwBG.style.display = "none"; }
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub vg1_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call vg1_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

function caricaVG (idSwf, idGlr, mastro, idLng, clicbl, idImg, albm) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion) {  // if we've detected an acceptable version
		// embed the flash movie
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
			'width', '100%',
			'height', '100%',
			'src', '/inc/vg?mastro=' + mastro + '&idGlr=' + idGlr + "&idLng=" + idLng + "&clicbl=" + clicbl + "&idImg=" + idImg + "&albm=" + albm,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', idSwf,
			'bgcolor', '#ffffff',
			'name', idSwf,
			'menu', 'false',
			'allowScriptAccess','sameDomain',
			'allowFullScreen','false',
			'movie', '/inc/vg?mastro=' + mastro + '&idGlr=' + idGlr + "&idLng=" + idLng + "&clicbl=" + clicbl + "&albm=" + albm,
			'salign', ''
			); //end AC code
	} else {  // flash is too old or we can't detect the plugin
		var alternateContent = 'Per la corretta visualizzazione di questo sito, '
			+ 'scaricare ed installare Adobe Flash Player.'
			+ '<a href=http://www.macromedia.com/go/getflash/>Clicca qui.</a>';
		document.write(alternateContent);  // insert non-flash content
	}
}

/*function caricaFlash(fileName, w, h, id) {	
	document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="' + id + '" width="' + w + '" height="' + h + '">');
	document.write ('  <param name="allowScriptAccess" value="sameDomain" />');
	document.write ('  <param name="movie" value="' + fileName +  '">');
	document.write ('  <param name="wmode" value="transparent"');	
	document.write ('  <param name="quality" value="high">');
	document.write ('  <embed src="' + fileName + '" quality="high" wmode="transparent" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" id="' + id + '" width="' + w + '" height="' + h + '"></embed>');
	document.write ('</object>');
}*/

function caricaTV(id, tt, l, a, sc, sb, as, sd, ar, wl, fs) {
	if (sc == 'true') { a += 25; }
	if (sb == 'true') { a += 25; }
	//document.write ('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" width="' + l + '" height="' + a + '" id="' + id + '" title="' + tt + '">');
	document.write ('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-mplayer2" width="' + l + '" height="' + a + '" id="' + id + '" title="' + tt + '">');
	document.write ('	<param name="AutoStart" value="' + as + '">');
	document.write ('	<param name="ShowControls" value="' + sc + '">');
	document.write ('	<param name="ShowStatusBar" value="' + sb + '">');
	document.write ('	<param name="ShowDisplay" value="' + sd + '">');
	document.write ('	<param name="AutoRewind" value="' + ar + '">');
	document.write ('	<param name="windowlessVideo" value="' + wl + '">');
	document.write ('	<param name="SendPlayStateChangeEvents" value="true">');
	document.write ('	<param name="stretchToFit" value="false">');
	document.write ('	<param name="FullScreen" value="' + fs + '">');
	document.write ('	<embed ');
	document.write ('		type="application/x-mplayer2" ');
	document.write ('		pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ');
	document.write ('		width="' + l + '" height="' + a + '" ');
	document.write ('		autostart="' + as + '" ');
	document.write ('		showcontrols="' + sc + '" ');
	document.write ('		showstatusbar="' + sb + '" ');
	document.write ('		showdisplay="' + sd + '" ');
	document.write ('		autorewind="' + ar + '" ');
	document.write ('		windowlessVideo="' + wl + '" ');
	document.write ('		fullScreen="' + fs + '" ');
	document.write ('		SendPlayStateChangeEvents="true" ');
	document.write ('		stretchToFit="false">');
	document.write ('	</embed>');
	document.write ('</object>');
}

function caricaVideo (id, titolo) {
	TVmon = document.getElementById(id);
	mtdT="";
	for (mtd in TVmon) { 
		mtdT = mtdT + ", " + mtd 
	}
	TVmon.URL= titolo;
	TVmon.start();
	//TVmon.play(); 
}

function videoNewsPlay(idBoxTV, idTV, idImg, idBtPlay, titolo) {
	BoxTV = document.getElementById(idBoxTV);
	Img = document.getElementById(idImg);
	btnPlay = document.getElementById(idBtPlay);
	BoxTV.style.visibility = "visible";
	Img.style.visibility = "hidden";
	btnPlay.style.visibility = "hidden";
	caricaVideo(idTV, titolo);
	
}

function videoNewsStop(idBoxTV, idTV, idImg, idBtPlay, azione) {
	BoxTV = document.getElementById(idBoxTV);
	Img = document.getElementById(idImg);
	TV = document.getElementById(idTV);
	btnPlay = document.getElementById(idBtPlay);
	switch (azione) {
		case "stop":
			BoxTV.style.visibility = "hidden";
			Img.style.visibility = "visible";
			btnPlay.style.visibility = "visible";
			TV.stop();
			break;
		case "pausa":
			TV.Pause();
			break;
		case "play":
			TV.play();
			break;
		case "fullScreen":
			if (TV.playState == 3) {
            	TV.fullScreen = 'true';
			}
			break;
	}
}

function GestMouse (evnt) {	
	if (IE) { 
		MouseX = event.clientX + document.body.scrollLeft;
		MouseY = event.clientY + document.body.scrollTop;
	} else {
		MouseX = evnt.pageX;
		MouseY = evnt.pageY;
	}

}

function Switch_Menu() {
	var trovato = false;
	for (i=0; i < itm; i++) {
		if (Voce_Attiva [i]) {
			if (i >= menu.length) { document.getElementById("menu_td_" + i).className = "HighLightIt"; }
			if ((i < menu.length) && (menu[i] > 0) && (document.getElementById("sm_" + i).style.visibility != "visible")){
				document.getElementById("sm_" + i).style.visibility = "visible";
				document.getElementById("sm_" + i).style.zIndex = 100;
				//document.getElementById("cp").style.opacity = "0.5";
				//document.getElementById("cp").style.filter = "alpha(opacity=50)";
				document.getElementById("sm_" + i).style.top = (getY("menu_td_" + i) + document.getElementById("menu_td_" + i).offsetHeight) + "px";
				var posMenu = Math.min(getX("menu_td_" + i), document.getElementById("menu").offsetWidth - document.getElementById("sm_" + i).offsetWidth);
	 			document.getElementById("sm_" + i).style.left = posMenu + "px";
				document.getElementById("sm_" + i).width = (document.getElementById("sm_" + i).scrollWidth + 10) + "px";
			}
			trovato = true;
		} else {
			if (i >= menu.length) { document.getElementById("menu_td_" + i).className = "UnLightIt"; }
			if (i < menu.length) {
				if (menu[i] > 0) { document.getElementById("sm_" + i).style.visibility = "hidden" }
			}
		}
	}
	if (trovato) { Menu_Check = window.setTimeout("Switch_Menu()", 100); }
}

function getX(obj) {
	var temp = document.getElementById(obj);
	var left = 0;
	while (temp.offsetParent) {
		if (temp.id != "pg" && temp.id != "cp" && temp.id != "head") {	left += temp.offsetLeft;  }
		temp = temp.offsetParent;
	}
	return left - document.body.scrollLeft;
}

function getY(obj) {
	var temp = document.getElementById(obj);
	var top = 0;
	while (temp.offsetParent) {
		if (temp.id != "pg" && temp.id != "cp" && temp.id != "head") { top += temp.offsetTop; }
		temp = temp.offsetParent;
	}
	return top - document.body.scrollTop;
}

function Menu_On (quale) {
	Voce_Attiva [quale] = true;
	Switch_Menu();
}

function Menu_Off (quale) {
	Voce_Attiva [quale] = false;
}

function SottoMenu_On (quale, par) {
	Voce_Attiva [quale] = true;
	Voce_Attiva [par] = true;
}

function SottoMenu_Off (quale, par) {
	Voce_Attiva [quale] = false;
	Voce_Attiva [par] = false;
}

function Apri(a, b) {

	if (href [a][b] != "") {
		frames['frameWork'].location.href = href [a][b];
	}
	
}

// CONVERSIONE DA HEX A RGB
function hex2rgb(colore) {
	colore = (colore.charAt(0)=="#") ? colore.substring(1, 7) : colore;
	var R = parseInt(colore.substring(0, 2), 16);
	var G = parseInt(colore.substring(2, 2), 16);
	var B = parseInt(colore.substring(4, 2), 16);
	return Array(R, G, B);
}
// CONVERSIONE DA HEX A RGB FINE
function ritardaAdattaSfondo (sec) {
	setTimeout("adattaSfondoAlContenuto()",sec);
}

function adattaSfondoAlContenuto() {
	if (/MSIE (5\.5|6)/.test(navigator.userAgent)) {
		ext = screen.width > 800 ? "2.gif" : "1.gif";
		document.getElementById('lb').style.backgroundImage = "url(/imgs/cornice/top" + ext + ")";
		document.getElementById('cr').style.backgroundImage = "url(/imgs/cornice/bottom" + ext + ")";
		document.getElementById('cp').style.backgroundImage = "url(/imgs/cornice/middle" + ext + ")";
		document.getElementById('ft').style.backgroundImage = "url(/imgs/cornice/middle" + ext + ")";
	}
	var centro = (document.body.clientWidth - document.getElementById("pg").offsetWidth) / 2;
	fineCSx = document.getElementById("cSx").offsetHeight + document.getElementById("cSx").offsetTop;
	fineHead = document.getElementById("head").offsetHeight + document.getElementById("head").offsetTop;
	document.getElementById("corpo").style.top = (fineHead + 2) + "px";
	fineCorpo = document.getElementById("corpo").offsetHeight + document.getElementById("corpo").offsetTop;
	var cpHeight = fineCSx > fineCorpo ? fineCSx : fineCorpo;
	cpHeight -= 10;
	document.getElementById('ft').style.top = (cpHeight) + "px";
	document.getElementById('nomePagina').style.top = (cpHeight - 25) + "px";
	cpHeight += document.getElementById("ft").offsetHeight;
	document.getElementById('cp').style.height = cpHeight + "px";
	var pgHeight = document.getElementById("pg").offsetHeight > document.body.clientHeight ? document.getElementById("pg").offsetHeight : document.body.clientHeight;
	document.getElementById("bg").style.height = pgHeight + "px";
	document.getElementById("pg").style.left = centro + "px";
	document.getElementById('ft').style.visibility = "visible";
	document.getElementById('cr').style.visibility = "visible";
	var mwBG = document.getElementById("mwBG");
	if (mwBG) {
		mwBG.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
		mwBG.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
	}
	var pu = document.getElementById("popupVG");
	if (pu) {
		var imm = document.getElementById("imgPU");
		lp = Math.max(document.body.scrollWidth,document.body.clientWidth);
		ap = Math.max(document.body.scrollHeight,document.body.clientHeight);
		li = imm.offsetWidth;
		ai = imm.offsetHeight;
		tu = (ap - ai) / 2;
		lu = (lp - li) / 2;
		pu.style.width = li + "px";
		pu.style.height = ai + "px";
		pu.style.top = tu + "px";
		pu.style.left = lu + "px";
	}
}

function dimensionaPopup() {
	var pu = document.getElementById("popupVG");
	if (pu) {
		pu.style.display = "block";
		var imm = document.getElementById("imgPU");
		lp = Math.max(document.body.scrollWidth,document.body.clientWidth);
		ap = Math.max(document.body.scrollHeight,document.body.clientHeight);
		li = imm.offsetWidth;
		ai = imm.offsetHeight;
		//li = 660;
		//ai = 550;
		tu = (ap - ai) / 2;
		lu = (lp - li) / 2;
		pu.style.width = li + "px";
		pu.style.height = ai + "px";
		pu.style.top = tu + "px";
		pu.style.left = lu + "px";
	}
}

function cambiaOverflow (obj, val) {
	if (val == 0) {
		obj.style.overflow = "hidden";
		//obj.style.padding = "0px 25px 0px 7px";
	} else {
		obj.style.overflow = "auto";
		//obj.style.padding = "0px 15px 0px 7px";
	}
}

function scrollaNews(obj, par) {
	var obj1 = obj + "1";
	if (document.getElementById(obj1).style.visibility == "hidden") {
		document.getElementById(obj1).style.visibility = "visible"; //ripristinare il valore a visible dopo il debug su offsetHeight non interpretato da FireFox
		document.getElementById(obj1).style.top = (document.getElementById(obj).offsetTop + document.getElementById(obj).offsetHeight) + "px";
	}	
	if (document.getElementById(par).style.overflow == "auto") {
		if (document.getElementById(obj).offsetTop != 0) {
			posScroll = document.getElementById(obj).offsetTop;
			document.getElementById(obj).style.top = "0px";
			document.getElementById(obj1).style.top = (document.getElementById(obj).offsetTop + document.getElementById(obj).offsetHeight) + "px";
			document.getElementById(par).scrollTop = -(posScroll);
		}
		scrNwsSI = setTimeout('scrollaNews(\"scrollNews\", \"news\")', 100);
		return false;
	}
	if (document.getElementById(par).scrollTop != 0) {
		document.getElementById(obj).style.top = -document.getElementById(par).scrollTop;
		document.getElementById(obj1).style.top = (document.getElementById(obj).offsetTop + document.getElementById(obj).offsetHeight) + "px";
		document.getElementById(par).scrollTop = 0;
	}
	
	pos = document.getElementById(obj).offsetTop - 1;
	if (pos < -(document.getElementById(obj).offsetHeight)) {
		document.getElementById(obj).style.top = (document.getElementById(obj1).offsetTop) + "px";
		document.getElementById(obj1).style.top = (document.getElementById(obj).offsetTop + document.getElementById(obj).offsetHeight) + "px";
	} else {
		document.getElementById(obj).style.top = pos + "px";
	}
	
	pos = document.getElementById(obj1).offsetTop - 1;
	if (pos < -(document.getElementById(obj1).offsetHeight)) {
		pos = document.getElementById(obj).offsetTop + document.getElementById(obj).offsetHeight;
	}
	document.getElementById(obj1).style.top = pos + "px";
	
	scrNwsSI = setTimeout('scrollaNews(\"scrollNews\", \"news\")', 100);
}

function scrollaAppuntamenti(obj, par, larg, att) {
	prosX = -(Math.floor(Math.abs(document.getElementById(obj).offsetLeft / larg)) + 1) * larg;
	if (prosX <= -document.getElementById(obj).offsetWidth) {
		step = 20;
	} else {
		step = Math.floor(Math.abs((document.getElementById(obj).offsetLeft - prosX) * 10)) / 40;
	}
	if (Math.floor(step) == 0) {
		pos = prosX;
		document.getElementById(obj).style.left = pos + "px";
		timeOut = att * 1000;
	} else {
		pos = document.getElementById(obj).offsetLeft - step;
		if (pos < -(document.getElementById(obj).offsetWidth)) {
			pos = document.getElementById(par).offsetWidth;
		}
		document.getElementById(obj).style.left = pos + "px";
		timeOut = 100;
	}
	setTimeout('scrollaAppuntamenti("' + obj + '", "' + par + '", ' + larg + ', ' + att + ')', timeOut);
}

function creaFeed (indirizzo, titolo) {
	var rssLink = document.createElement("link");
	var headID = document.getElementsByTagName("head")[0];       
	rssLink.type = 'application/rss+xml';
	rssLink.rel = 'alternate';
	rssLink.href = indirizzo;
	rssLink.title = titolo;
	headID.appendChild(rssLink);
}

/*function ajaxCall(strURL, cnt, fnct, form, prnt, exscr) {
	
	// il parametro fnct puņ essere una funzione o una chiamata a funzione passata come stringa. 
	// In quest'ultimo caso si puņ inserire la parola chiave _ajaxResult nell'elenco dei
	// parametri per ottenere il risultato AJAX come argomento.

	
	var xmlHttpReq = false;
	var self = (prnt == undefined || prnt == "") ? this : prnt;
	var cnt = document.getElementById(cnt);
	cnt.innerHTML = "<table width=100% height=100%><tr><td height=100% width=100% align=center valign=middle><img src=/imgs/ajax-loader.gif></td></tr></table>";
	// Xhr per Mozilla/Safari/Ie7
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// per tutte le altre versioni di IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	method = (form == undefined || form == "") ? "get" : "post";
	self.xmlHttpReq.open(method, strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			_ajaxResult = self.xmlHttpReq.responseText;
			if (exscr != undefined && exscr == true) {
				var script = self.xmlHttpReq.responseText.match(/(<script\b\s*language=["']?javascript["']?[^>]*>){1}([^<]*)(<\/script>){1}/ig);
				for (scrpt in script) {
					if (script[scrpt].length > 6 && script[scrpt].substr(0,7) =='<script') { 
						eval (script[scrpt].replace(/(<script\b\s*language=["']?javascript["']?[^>]*>)/, "").replace(/(<\/script>)/, ""));
					}
				}
			}
			if (cnt) { cnt.innerHTML = self.xmlHttpReq.responseText; }
			if (fnct != undefined && fnct != "") { eval(fnct); }
		}
	}
	parametri = (method == "get") ? "" : getQueryString(form);
	self.xmlHttpReq.send(parametri);
}*/

function ajaxCall(strURL, cnt, fnct, form, prnt, exscr, loader, finestraModale, messaggioModale, resultInModale, async) {
	
	// il parametro fnct puņ essere una funzione o una chiamata a funzione passata come stringa. 
	// In quest'ultimo caso si puņ inserire la parola chiave _ajaxResult nell'elenco dei
	// parametri per ottenere il risultato AJAX come argomento.
	
	var xmlHttpReq = false;
	var self = (prnt == undefined || prnt == "") ? this : prnt;
	var cnt = document.getElementById(cnt);
	asyn = (async == undefined || async == "") ? true : async;
	if (loader != undefined && loader == true) { cnt.innerHTML = "<table width=425 height=240><tr><td height=100% width=100% align=center valign=middle><img src=/imgs/ajax-loader.gif></td></tr></table>"; }
	// Xhr per Mozilla/Safari/Ie7
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// per tutte le altre versioni di IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	method = (form == undefined || form == "") ? "get" : "post";
	self.xmlHttpReq.open(method, strURL, async);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			_ajaxResult = self.xmlHttpReq.responseText;
			if (exscr != undefined && exscr == true) {
				var script = self.xmlHttpReq.responseText.match(/(<script\s*language[\s]*=[\s]*["']?javascript["']?[^>]*>){1}((.|\s)*?)(<\/script>){1}/ig);
				for (scrpt in script) {
					if (script[scrpt].length > 6 && script[scrpt].substr(0,7) =='<script') { 
						//alert(script[scrpt].replace(/(<script\b\s*language=["']?javascript["']?[^>]*>)/, "").replace(/(<\/script>)/, ""));
						eval (script[scrpt].replace(/(<script\b\s*language=["']?javascript["']?[^>]*>)/, "").replace(/(<\/script>)/, ""));
					}
				}
			}
			if (cnt) { cnt.innerHTML = self.xmlHttpReq.responseText; }
			if (fnct != undefined && fnct != "") { eval(fnct); }
		}
	}
	parametri = (method == "get") ? "" : getQueryString(form);
	self.xmlHttpReq.send(parametri);
}

function getQueryString(form) {
	form = document.getElementById(form);
	qstr = "";
	for (campo in form) {
		if (form[campo] 
		 && campo != "firstElementChild" 
		 && campo != "firstChild" 
		 && form[campo].value) { qstr += "&" + campo + "=" + form[campo].value; }
	}
	return qstr;
}

//---------------- funzioni mediagallery

function caricaDescrizione (elementi, quale, ind, fs, lrg, alt) {
	//alert (elementi + " " + quale + " " + ind + " " + fs + " " + lrg + " " + alt);
	lrg = lrg == undefined ? 425 : lrg;
	alt = alt == undefined ? 240 : alt;
	if (ind >= elementi[quale].length) ind = 0;
	if (ind < 0) ind = elementi[quale].length - 1;  
	this.ind = ind;
	this.quale = quale;
	var path, imgG, titolo, url;
	cntPlayer = document.getElementById("divPlayer");
	switch (quale) {
		case 0:
		case 1:
		case 4:
			path = elementi[quale][ind]['path'];
			imgG = elementi[quale][ind]['imgG'];
			titolo = elementi[quale][ind]['titolo'];
			url = elementi[quale][ind]['url'];
			cntPlayer.innerHTML = "<table width=425 height=240><tr><td height=100% width=100% align=center valign=middle>" +
															 "<img src=/imgs/ajax-loader.gif></td></tr></table>";
			cntPlayer.innerHTML = "<table width=425 height=240><tr><td width=100% height=100% valign=middle align=center>" +
													 " <img src='"+path+"'></td></tr></table>";
			setControls("img", imgG, titolo);
			if (fs) { vg1_DoFSCommand("mostraVideo", imgG + "xfsnetx" + titolo); }
			break;
		default:
			titolo = elementi[quale][ind]['titolo'];
			url = elementi[quale][ind]['url'];
			video = elementi[quale][ind]['video'];
			switch (elementi[quale][ind]['tipo']) {
				case "esternoYT":
				case "esternoFP":
				case "internoFP":
					setControls("flash");
					cntPlayer.innerHTML = creaFlash("videoBoxFlash", titolo, lrg, alt+40, video);
					break;
				case "internoWM":
				case "esternoWM":
				case "mms":
					setControls("wmp");
					if ((vbWMP = document.getElementById("videoBoxWMP")) && IE) { 
						//vbWMP.filename = video; 
						//vbWMP.title = titolo;
						vbWMP.stop();
						cntPlayer.innerHTML = "";
					}
					cntPlayer.innerHTML = creaWMP("videoBoxWMP", titolo, lrg, alt, true, false, true, false, true, false, true, video);
					break;
				case "internoQT":
				case "esternoQT":
					setControls("qt");
					cntPlayer.innerHTML = creaQT("videoBoxQT", titolo, lrg, alt, true, false, true, false, true, false, true, video);
					break;
			}
			break;
	}
	ajaxCall(url, "divDescr", "adattaSfondoAlContenuto()", "", document.getElementById("divDescr"), false);
}

function setControls(tipo, imgG, titolo) {
	var bordino = document.getElementById("bordino");
	var divController = document.getElementById("divController");
	var playCntr = document.getElementById("play");
	var pauseCntr = document.getElementById("pause");
	var stopCntr = document.getElementById("stop");
	var fullscreen = document.getElementById("fullscreen");
	var videoBox = document.getElementById("videoBoxWMP");
	switch (tipo) {
		case "img":
			bordino.onclick = function() { scrollView(0, 0); vg1_DoFSCommand("mostraVideo", imgG + "xfsnetx" + titolo); }
			bordino.style.cursor = "hand";
			bordino.style.cursor = "pointer";
			bordino.style.display = "";
			divController.style.visibility = "visible";
			fullscreen.onclick = function() { scrollView(0, 0); vg1_DoFSCommand("mostraVideo", imgG + "xfsnetx" + titolo); }
			fullscreen.style.cursor = "hand";
			fullscreen.style.cursor = "pointer";
			stopCntr.style.display = "none";
			playCntr.onclick = function() { document.getElementById("play").style.display="none"; document.getElementById("pause").style.display=""; scrollView(1,0); }
			pauseCntr.onclick = function() { document.getElementById("pause").style.display="none"; document.getElementById("play").style.display=""; scrollView(0,0); }
			break;
		case "wmp":
			bordino.onclick = "";
			bordino.style.cursor = "";
			bordino.style.cursor = "";
			bordino.style.display = "none";
			//divController.style.visibility = FF ? "hidden" : "visible";
			divController.style.visibility = "hidden";
			//fullscreen.onclick = function() { alert (document.getElementById("videoBoxWMP").playState); }//document.getElementById("videoBoxWMP"); }
			fullscreen.style.cursor = "hand";
			fullscreen.style.cursor = "pointer";
			playCntr.style.display = "none";
			pauseCntr.style.display = "";
			stopCntr.style.display = "";
			playCntr.onclick = function() { document.getElementById("play").style.display="none"; document.getElementById("pause").style.display=""; document.getElementById("videoBoxWMP").play(); }
			pauseCntr.onclick = function() { document.getElementById("pause").style.display="none"; document.getElementById("play").style.display=""; document.getElementById("videoBoxWMP").pause(); }
			stopCntr.onclick = function() { document.getElementById("pause").style.display="none"; document.getElementById("play").style.display=""; document.getElementById("videoBoxWMP").stop(); }
			break;
		case "flash":
			bordino.onclick = "";
			bordino.style.cursor = "";
			bordino.style.cursor = "";
			//bordino.style.display = "none";
			divController.style.visibility = "hidden";
			break;
		case "qt":
			bordino.onclick = "";
			bordino.style.cursor = "";
			bordino.style.cursor = "";
			bordino.style.display = "none";
			divController.style.visibility = "hidden";
			break;
	}
}

function scorriImmagini (dove,fs) {
	this.ind += dove;
	caricaDescrizione (elementi,this.quale,this.ind,fs);
}

function scrollView (azione,fs) {
	if (azione) {
		scorriImmagini(1,fs);
		this.svTo = setTimeout("scrollView(1,"+fs+")",6000);
	} else {
		clearTimeout(this.svTo);
	}
}

function creaQT (id, tt, l, a, sc, sb, as, sd, ar, wl, fs, vd) {
	//alert(id + ' - ' + tt + ' - ' + l+ ' - ' +  a+ ' - ' +  sc+ ' - ' +  sb+ ' - ' +  as+ ' - ' +  sd+ ' - ' +  ar+ ' - ' +  wl+ ' - ' +  fs+ ' - ' +  vd);
	// id = id del video
	// tt = titolo
	// l = larghezza
	// a = altezza
	// sc = showControls
	// sb = showStatusBar
	// as = autoStart
	// sd = showDisplay
	// ar = autoRewind
	// wl = windowLess
	// fs = fullScreen
	// vd = url del video
	if (!wl) {
		if (sc) { a += 25; }
		if (sb) { a += 25; }
	}
	var urlObj = "";
	var urlEmb = "";
	if (vd != undefined) {
		urlObj = '	<param name="src" value="' + video + '">' +
					 '	<param name="qtsrc" value="' + video + '">';
		urlEmb = '		qtsrc="' + video + '" ' +
					 '		src="' + video + '" ';
	}
	var res = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="' + a + '" width="' + l + '"> ' + urlObj + 
				' <param name="autoplay" value="' + as + '"> ' +
				' <param name="controller" value="' + sc + '"> ' +
				' <param name="scale" value="TOFIT"> ' +
				' <param name="type" value="video/quicktime" height="'+a+'" width="'+l+'"> ' +
				' <embed ' + urlEmb + ' height="'+a+'" width="'+l+'" ' + 
				' autoplay="' + as + '" ' + 
				' pluginspage="http://www.apple.com/quicktime/download/" ' + 
				' controller="' + sc +'"' + 
				' scale="TOFIT" ' +
			  ' </object> ';
	return res;
}

function creaFlash(id, tt, l, a, vd) {
	res = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="' + id + '" width="' + l + '" height="' + a + '">' +
	'  <param name="allowScriptAccess" value="sameDomain" />' +
	'  <param name="movie" value="/inc/boxVideo.swf?noCache=' + (new Date().getTime()) + '&video=' + vd +  '">' +
	'  <param name="wmode" value="transparent"' +
	'  <param name="quality" value="high">' +
	'  <param name="allowFullScreen" value="true">' +
	'  <embed src="/inc/boxVideo.swf?video=' + vd + '" allowFullScreen="true" quality="high" wmode="transparent" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" id="' + id + '" width="' + l + '" height="' + a + '"></embed>' +
	'</object>';
	return res;
}

function creaWMP(id, tt, l, a, sc, sb, as, sd, ar, wl, fs, vd) {
	// id = id del video
	// tt = titolo
	// l = larghezza
	// a = altezza
	// sc = showControls
	// sb = showStatusBar
	// as = autoStart
	// sd = showDisplay
	// ar = autoRewind
	// wl = windowLess
	// fs = fullScreen
	// vd = url del video
	if (FF) { wl = true; }
	if (!wl) {
		if (sc) { a += 25; }
		if (sb) { a += 25; }
	}
	var urlObj = "";
	var urlEmb = "";
	if (vd != undefined) {
		urlObj = '	<param name="URL" value="' + vd + '">' +
					 '	<param name="FileName" value="' + vd + '">';
		typeObj = '		url="' + vd + '" ' +
				 '		data="' + vd + '" '; 
		urlEmb = '		url="' + vd + '" ' +
					 '		src="' + vd + '" ';
		//urlEmb = '		src="' + vd + '" '
	}
	var res = '<object ' + 
				' codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 ' +
				//' type=application/x-oleobject ' +
				' type="video/x-ms-asf" ' + 
				' standby="Loading Microsoft Windows Media Player components..."' +
				' height=' + a +
				' width=' + l +
				' align=absmiddle ' +
				//' classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 ' +
				' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' + 
				' id=' + id + 
				' title="' + tt + '">' +
				' <param name="animationatStart" value="true"> <param name="transparentatStart" value="true"> ' +
				'	<param name="AutoStart" value="' + as + 'true">' +
				'	<param name="ShowControls" value="' + sc + '">' +
				'	<param name="ShowStatusBar" value="' + sb + '">' +
				'	<param name="ShowDisplay" value="' + sd + '">' +
				'	<param name="AutoRewind" value="' + ar + '">' +
				'	<param name="windowlessVideo" value="' + wl + '">' +
				'	<param name="SendPlayStateChangeEvents" value="true">' +
				'	<param name="stretchToFit" value="false">' +
				'	<param name="autoSize" value="false">' +
				'   <param name="uiMode" value="full">' +
				//'	<param name="FullScreen" value="' + fs + '">' +	
				urlObj +
				'	<embed ' +
				//'		type=application/x-oleobject ' +
				'		type="application/x-mplayer2" ' +
				//'		pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
				'	    pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ' +
				'		width="' + l + '" height="' + a + '" ' +
				'		autostart= ' + as +
				'		showcontrols= ' + sc +
				'		showstatusbar= ' + sb +
				'		showdisplay= ' + sd +
				'		autorewind= ' + ar +
				'		windowlessVideo= ' + wl +
				//'		fullScreen= ' + fs + 
				urlEmb + 
				'		SendPlayStateChangeEvents=1 ' +
				'		autosize=0 ' +
				'		stretchToFit=0>' +
				'	</embed>' +
				'</object>';
	return res;
/* ESEMPIO DI PLUGIN DA W3C
	<object width="100%" height="100%"
			type="video/x-ms-asf" 
			url="http://www.santegidio.org/videoGalleries/1065/Bear.wmv" 
			data="http://www.santegidio.org/videoGalleries/1065/Bear.wmv"
			classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
		<param name="url" value="http://www.santegidio.org/videoGalleries/1065/Bear.wmv">
		<param name="filename" value="http://www.santegidio.org/videoGalleries/1065/Bear.wmv">
		<param name="autostart" value="1">
		<param name="uiMode" value="full" />
		<param name="autosize" value="1">
		<param name="playcount" value="1">
		<embed type="application/x-mplayer2" 
			   src="http://www.santegidio.org/videoGalleries/1065/Bear.wmv" 
			   width="100%" height="100%" 
			   autostart="true" 
			   showcontrols="true" 
			   pluginspage="http://www.microsoft.com/Windows/MediaPlayer/">
		</embed>
	</object-->
*/
}

function setStreamingStatus(val, url) {
	if (window.setStreamingStatusLastIdMG == window.setStreamingStatusIdMG
	 && window.setStreamingStatusLastURL == url
	 && window.setStreamingStatusLastVal == val) return false;
	var cIdPc = getCookie("idPc");
	if (cIdPc == "") {
		cIdPc = MD5(new Date().getTime().toString());
		setCookie("idPc", cIdPc, 1);
	}
	idMG = (window.setStreamingStatusIdMG != undefined) ? window.setStreamingStatusIdMG : "";
	if (window.setStreamingStatusLastIdMG != undefined && window.setStreamingStatusLastURL != undefined 
	&& (window.setStreamingStatusLastIdMG != window.setStreamingStatusIdMG || window.setStreamingStatusLastURL != url)) {
		//$.post('/loadersAjax/streamingStats.php', { idPc: cIdPc, val: 9, url: window.setStreamingStatusLastURL, idMG: window.setStreamingStatusLastIdMG }, function (data) {  });
		$.ajax({
			url: '/loadersAjax/streamingStats.php', 
			data: { idPc: cIdPc, val: 9, url: window.setStreamingStatusLastURL, idMG: window.setStreamingStatusLastIdMG }, 
			async: false,
			type: 'post'
		});
	}
	//$.post('/loadersAjax/streamingStats.php', { idPc: cIdPc, val: val, url: url, idMG: idMG }, function (data) {  });
	$.ajax({
		url: '/loadersAjax/streamingStats.php', 
		data: { idPc: cIdPc, val: val, url: url, idMG: idMG }, 
		type: 'post',
		async: false
	});
	window.setStreamingStatusLastIdMG = window.setStreamingStatusIdMG;
	window.setStreamingStatusLastURL = url;
	window.setStreamingStatusLastVal = val;
}
//---------------- fine funzioni mediagallery

//---------------- funzioni aggiornatore
	var aggMessaggi, aggDelay, aggCnt, aggLink;
	var cur = 0;

	function aggIniziaScroll(arrayMessaggi, arrayLink, delay, cnt) {
		aggMessaggi = arrayMessaggi;
		aggLink = arrayLink;
		aggDelay = delay;
		aggCnt = cnt;
		aggInit();
	}
	
	function aggInit() {
		var obj = document.getElementById(aggCnt);
		var alt = (obj.offsetHeight * 2);
		var loop = IE ? "2" : "1";
		obj.innerHTML = "<marquee height=" + alt + " scrollamount=2 direction=up behavior=alternate id='aggMrq' loop=" + loop + ">" + (aggMessaggi[cur]) + "</marquee>";
		document.getElementById("aggLink").href = aggLink[cur];
		var mrq = document.getElementById("aggMrq");
		if (mrq.addEventListener) {	mrq.addEventListener("finish", aggAspetta, true); }
		if (mrq.attachEvent) { mrq.attachEvent("onbounce", aggAspetta); }
	}
	
	function aggAspetta() {
		var mrq = document.getElementById("aggMrq");
		if (mrq.removeEventListener) {	mrq.removeEventListener("finish", aggAspetta, true); }
		if (mrq.detachEvent) { mrq.detachEvent("onbounce", aggAspetta); }
		if (IE) { mrq.stop(); }
		setTimeout(aggFuori, aggDelay*1000);
	}
	
	function aggFuori() {
		var mrq=document.getElementById("aggMrq");
		if (mrq.addEventListener) {	mrq.addEventListener("finish", aggProssimo, true); }
		if (mrq.attachEvent) { mrq.attachEvent("onbounce", aggProssimo); }
		mrq.start();
	}
	
	function aggProssimo() {
		var mrq = document.getElementById("aggMrq");
		if (mrq.removeEventListener) {	mrq.removeEventListener("finish", aggProssimo, true); }
		if (mrq.detachEvent) { mrq.detachEvent("onfinish", aggProssimo); }
		cur++;
		if (cur >= aggMessaggi.length) { cur=0; }
		aggInit();
	}

//---------------- fine funzioni aggiornatore

//---------------- funzioni preghiere per la pace INIZIO

function chClass (obj) {
	$('.serverStreamAtt').removeClass('serverStreamAtt').addClass('serverStream');
	$(obj).removeClass('serverStream').addClass('serverStreamAtt');
}

function cambiaVideo(url, titolo, descrizione, idGlr, idLng, larg, alt) {
	var ext = url.split(".")[url.split(".").length - 1];
	var prt = url.split("://")[0];
	var tipo = ext == "wmv" || ext == "asf" || prt == "mms" ? "wmv" : "altro";
	larg = (larg != undefined) ? larg : 425;
	alt = (alt != undefined) ? alt : 280;
	//$('#player').css('background-color','');
	switch (tipo) {
		case "wmv":
			document.getElementById("player").innerHTML = creaWMP("objplayer", titolo, larg, alt, true, true, true, false, true, true, true, url);
			break;
		default:
			document.getElementById("player").innerHTML = creaFlash('objplayer', '', larg, alt, url);
			break;
	}
	if (titolo != undefined) $('#descrVideo').html('<div style="height:' + alt + 'px; overflow:auto"><span class="titoloPPel">' + titolo + '</span><br>' + descrizione + '</div>');
	if (idGlr != undefined) {
		window.setStreamingStatusIdMG = idGlr;
		$.post("/loadersAjax/lingueVideoPP.php",
			   { idGlr: idGlr,
				 idLng: idLng ,
				 larg: larg,
				 alt: alt},
			   function (data) {
				   $('#lingueVideo').show();
				   $('#lingueVideo').html(data);
			   });		   
	}
}

function caricaTweets(cnt, username, qta) {
	if ($("#" + cnt + " #tweetsContainer").length == 0) {
		$("<div></div>").appendTo($("#" + cnt ))
						.attr("id", "tweetsContainer")
						.css("position", "relative")
						.css("overflow", "hidden")
						.css("width","100%");
	}
	$.ajax({ 
		url: "/loadersAjax/leggiTweets.php",
		data: { user: username, qnt: qta },
		type: "get",
		success: function(data) { 
			twitterCallback2(data, cnt);
			setTimeout("caricaTweets('"+cnt+"','"+username+"',"+qta+")", 60000);
		}
	});
}

function twitterCallback2(twitters, cnt) {
  /*var statusHTML = [];
  var idStr;
  for (var i=0; i<twitters.length; i++){
	var username = twitters[i].user.screen_name;
	var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
	  return '<a href="'+url+'">'+url+'</a>';
	}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
	  return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
	});
	idStr = twitters[i].id_str;
	statusHTML.push('<span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a>');
  }*/
  var statusHTML = twitters.split("__fsnet__");
  window.newTweets = statusHTML;
  if (window.scrollTweetsTO == undefined) scrollTweets(cnt);
  //var tweetToWrite = statusHTML.join('');
  /*if (window.caricaTweetsVIdStr != idStr) {
	  $("#" + cnt).fadeOut("slow", function() { $("#" + cnt).html(tweetToWrite).fadeIn("slow"); });
	  window.caricaTweetsVIdStr = idStr;
  } else {
	  $("#" + cnt).html(tweetToWrite);
  }*/
}

function scrollTweets(cnt) {
	if (window.tweets == undefined) window.tweets = window.newTweets;
	if (window.scrollTweetsInd == undefined) window.scrollTweetsInd = 0;
	if (window.scrollTweetsHM == undefined) window.scrollTweetsHM = 0;
	if (window.scrollTweetsMaxHeight == undefined) window.scrollTweetsMaxHeight = 45;
	var lInd = window.scrollTweetsInd == 0 ? window.scrollTweetsHM - 1 : window.scrollTweetsInd - 1;
	var tc = $("#" + cnt + " #tweetsContainer");
	if ($("#" + cnt + " #tweetsContainer #tweet" + window.scrollTweetsInd).length == 0) {
		var obj = $("<div></div>").appendTo(tc)
								  .attr("id", "tweet" + window.scrollTweetsInd)
								  .width($("#" + cnt).parents(".tweetsList").width());
	} else {
		obj = $("#" + cnt + " #tweetsContainer #tweet" + window.scrollTweetsInd);
	}

	obj.css("position", "relative").html(window.tweets[window.scrollTweetsInd]);
	window.scrollTweetsMaxHeight = Math.max(window.scrollTweetsMaxHeight, obj.height());	
	tc.height(window.scrollTweetsMaxHeight);
	$("#" + cnt).parents(".twitterListContainer").height(window.scrollTweetsMaxHeight + 50);
	if (lInd != window.scrollTweetsInd) {
		if ($("#" + cnt + " #tweetsContainer #tweet" + lInd).length > 0) {
			var lObj = $("#" + cnt + " #tweetsContainer #tweet" + lInd);
			lObj.animate({ top: -window.scrollTweetsMaxHeight - 20 }, 500);
		}
		obj.css("position", "absolute").css("top", window.scrollTweetsMaxHeight + 20).animate({ top: 0 }, 500);
	} else {
		obj.css("position", "absolute").css("top", "0");
	}
	
	if (window.scrollTweetsInd == 0) window.scrollTweetsHM = window.tweets.length;
	window.scrollTweetsHM = Math.max(window.scrollTweetsInd + 1, window.scrollTweetsHM);
	
	window.scrollTweetsInd++;
	if (window.scrollTweetsInd >= window.tweets.length) {
		window.scrollTweetsInd = 0;
		window.tweets = window.newTweets;
	}
	
	window.scrollTweetsTO = setTimeout("scrollTweets('" + cnt + "')", 6000);
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
	return 'less than a minute ago';
  } else if(delta < 120) {
	return 'about a minute ago';
  } else if(delta < (60*60)) {
	return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
	return 'about an hour ago';
  } else if(delta < (24*60*60)) {
	return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
	return '1 day ago';
  } else {
	return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

//---------------- funzioni preghiere per la pace FINE

function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" ;
	}

function startBlink() {
	if (document.all) {
		setInterval("doBlink()",1000)
	}
}

function setCookie(sNome, sValore, iGiorni) {
	var dtOggi = new Date()
	var dtExpires = new Date()
	dtExpires.setTime
	(dtOggi.getTime() + 24 * iGiorni * 3600000)
	document.cookie = sNome + "=" + escape(sValore) + "; expires=" + dtExpires.toGMTString() + "; path=/";
}

function getCookie(sNome) {
	var asCookies = document.cookie.split("; ");
	for (var iCnt = 0; iCnt < asCookies.length; iCnt++) {
		var asCookie = asCookies[iCnt].split("=");
		if (sNome == asCookie[0]) {
			return (unescape(asCookie[1]));
		}
	}
	return "";
}


function MD5(string) {
 
	function RotateLeft(lValue, iShiftBits) {
		return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
	}
 
	function AddUnsigned(lX,lY) {
		var lX4,lY4,lX8,lY8,lResult;
		lX8 = (lX & 0x80000000);
		lY8 = (lY & 0x80000000);
		lX4 = (lX & 0x40000000);
		lY4 = (lY & 0x40000000);
		lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
		if (lX4 & lY4) {
			return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
		}
		if (lX4 | lY4) {
			if (lResult & 0x40000000) {
				return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			}
		} else {
			return (lResult ^ lX8 ^ lY8);
		}
 	}
 
 	function F(x,y,z) { return (x & y) | ((~x) & z); }
 	function G(x,y,z) { return (x & z) | (y & (~z)); }
 	function H(x,y,z) { return (x ^ y ^ z); }
	function I(x,y,z) { return (y ^ (x | (~z))); }
 
	function FF(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function GG(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function HH(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function II(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function ConvertToWordArray(string) {
		var lWordCount;
		var lMessageLength = string.length;
		var lNumberOfWords_temp1=lMessageLength + 8;
		var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
		var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
		var lWordArray=Array(lNumberOfWords-1);
		var lBytePosition = 0;
		var lByteCount = 0;
		while ( lByteCount < lMessageLength ) {
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
			lByteCount++;
		}
		lWordCount = (lByteCount-(lByteCount % 4))/4;
		lBytePosition = (lByteCount % 4)*8;
		lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
		lWordArray[lNumberOfWords-2] = lMessageLength<<3;
		lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
		return lWordArray;
	};
 
	function WordToHex(lValue) {
		var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
		for (lCount = 0;lCount<=3;lCount++) {
			lByte = (lValue>>>(lCount*8)) & 255;
			WordToHexValue_temp = "0" + lByte.toString(16);
			WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
		}
		return WordToHexValue;
	};
 
	function Utf8Encode(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;
	};
 
	var x=Array();
	var k,AA,BB,CC,DD,a,b,c,d;
	var S11=7, S12=12, S13=17, S14=22;
	var S21=5, S22=9 , S23=14, S24=20;
	var S31=4, S32=11, S33=16, S34=23;
	var S41=6, S42=10, S43=15, S44=21;
 
	string = Utf8Encode(string);
 
	x = ConvertToWordArray(string);
 
	a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
 
	for (k=0;k<x.length;k+=16) {
		AA=a; BB=b; CC=c; DD=d;
		a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
		d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
		c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
		b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
		a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
		d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
		c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
		b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
		a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
		d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
		c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
		b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
		a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
		d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
		c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
		b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
		a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
		d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
		c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
		b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
		a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
		d=GG(d,a,b,c,x[k+10],S22,0x2441453);
		c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
		b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
		a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
		d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
		c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
		b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
		a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
		d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
		c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
		b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
		a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
		d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
		c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
		b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
		a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
		d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
		c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
		b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
		a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
		d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
		c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
		b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
		a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
		d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
		c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
		b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
		a=II(a,b,c,d,x[k+0], S41,0xF4292244);
		d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
		c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
		b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
		a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
		d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
		c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
		b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
		a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
		d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
		c=II(c,d,a,b,x[k+6], S43,0xA3014314);
		b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
		a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
		d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
		c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
		b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
		a=AddUnsigned(a,AA);
		b=AddUnsigned(b,BB);
		c=AddUnsigned(c,CC);
		d=AddUnsigned(d,DD);
	}
 
	var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
	return temp.toLowerCase();
}

function microtime (get_as_float) {
    // Returns either a string or a float containing the current time in seconds and microseconds  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/microtime    // +   original by: Paulo Freitas
    // *     example 1: timeStamp = microtime(true);
    // *     results 1: timeStamp > 1000000000 && timeStamp < 2000000000
    var now = new Date().getTime() / 1000;
    var s = parseInt(now, 10); 
    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}

function mostraStatistiche() {
	if ($('.statistiche').css('left') == '0px') {
		$('.statistiche').animate({left:'-250px'});
	} else {
		$('.statistiche').animate({left: '0px'});
	}
}

function modale (cnt) {
	var modalBg = $("<div></div>").css("background-color", "#fff")
								  .css("position", "fixed")
								  .css("opacity", 0.8)
								  .css("z-index", 99998)
								  .width($(window).width())
								  .height($(window).height())
								  .appendTo($('body'))
								  .bind("click", function () {
									  					$(this).remove();
														$('#' + cnt).hide();
									  			   });
	var altezza = $(window).height() * 0.8;
	var larghezza = $(window).width() * 0.8;
	$('#' + cnt).width(Math.min(larghezza, $('#' + cnt).width()))
				.height(Math.min(altezza, $('#' + cnt).height()))
				.css('position', 'fixed')
				.css('top', ($(window).height() - $('#' + cnt).height()) / 2 )
				.css('left', ($(window).width() - $('#' + cnt).width()) / 2 )
				.css("overflow", "auto")
				.addClass("modalShadow")
				.show();
}

function showThumb (url) {
	$(document).mousemove(function (e) {
							window.posMouseX = e.pageX;
							window.posMouseY = e.pageY;
						  });
	if (window.posMouseX != undefined && window.posMouseY != undefined) {
		var img = new Image();
		img.src = url;
		var h = img.height;
		var w = img.width;
		var larg = (w > 100) ? "width=100" : "";
		var modalImg = $("<div id='imm'><img src='"+url+"' " + larg + "></div>")
						.css('border', '1px solid black')
						.css('position','absolute')
						.css('top',window.posMouseY + 10)
						.css('left',window.posMouseX + 10)
						.css('z-index', 99999)
						.delay(300)
						.appendTo($('body'));
	}
	return false;
}

function hideThumb () {
	$('#imm').remove();
	return false;
}

function cliccato (chi) {
	if (chi == 'archivio') {
		$('#tableArchivio').show();
		$('#tableDirette').hide();
	} else { 
		$('#tableArchivio').hide();
		$('#tableDirette').show();
	}
	
}

function stripslashes (str) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   input by: Brant Messenger (http://www.brantmessenger.com/)    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"    return (str + '').replace(/\\(.?)/g, function (s, n1) {
    return (str + '').replace(/\\(.?)/g, function (s, n1) {
    	switch (n1) {
        	case '\\':
            	return '\\';
        	case '0':
				return '\u0000';
        	case '':
            	return '';
	        default:
            	return n1;        }
    	}
	);
}
