 // JavaScript Document
function writeUnderLink(classStyle, textString, linkPage) {
	rightMargin = 50; //Distanza dal margine destro della pagina
	linkTopMargin = 50; //Margine alto del link
	noLinkTopMargin = 30; //Margine alto dell'eventuale testo aggiuntivo non-link
	if (!linkPage == "") { //Si desidera scrivere un link
		document.write  ("<div style=\"position: absolute; top: " + linkTopMargin + "; right: " + rightMargin + "\">");
		document.write  ("<a href=\"" + linkPage + "\" class=\"" + classStyle + "\">");
		document.writeln("<u>" + textString + "</u></a></div>");
	}
	else { //Si desidera scrivere del testo aggiuntivo non formattato come link
		document.write  ("<div class=\"" + classStyle + "\" ");
		document.write  ("style=\"position: absolute; top: " + noLinkTopMargin + "; right: " + rightMargin + "\">");
		document.writeln(textString + "</div>");
	}
} //writeUnderLink


function showPhoto(imgName, numLevels) {
	dirLevel = "";
	for (i = 0; i < numLevels; i++) { //Legge i sottolivelli rispetto alla directory radice del sito
		dirLevel = dirLevel + "../";  //(passati tramite numLevels) e costruisce la stringa dirLevel
	}								  //aggiungendo "../" per ogni sottolivello. Serve per lo sfondo
	
	winWidth = 600;  //Larghezza della finestra popup
	winHeight = 600; //Altezza della finestra popup
	leftMargin = (screen.width - winWidth) / 2; //Margine sinistro della finestra popup
	topMargin = (screen.height - winHeight) / 2; //Margine superiore della finestra popup
	propString = "scrollbars,width=" + winWidth + ",height=" + winHeight;  //Costruisce la stringa con le
	propString = propString + ",left=" + leftMargin + ",top=" + topMargin; //proprietà della finestra popup
	photoWin = window.open("", "photoWin", propString); //Visualizza il popup

	//Scrive nel popup
	photoWin.document.writeln("<HTML>");
	photoWin.document.writeln("<TITLE>Image Viewer</TITLE>");
	photoWin.document.writeln("<link href=\"" + dirLevel + "siteStyle.css\" rel=\"stylesheet\" type=\"text/css\">");
	photoWin.document.write  ("<BODY background=\"" + dirLevel + "immagini/sfondo.jpg\" ");
	photoWin.document.writeln("leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">");
	photoWin.document.writeln("<DIV align=\"center\"><IMG src=\"" + imgName + ".jpg\"><br>");
	photoWin.document.write  ("<font size=\"2\"><A href=\"javascript:window.close()\" class=\"signVerde\">");
	photoWin.document.writeln("<strong>Chiudi</strong></A></font>");
	photoWin.document.writeln("</BODY>");
	photoWin.document.writeln("</HTML>");
} //showPhoto


function openPopup(linkString, toolbarFlag, winWidth, winHeight) {
	/* toolbarFlag = 0: non visualizza la toolbar
	   toolbarFlag = 1: visualizza la toolbar */
	leftMargin = (screen.width - winWidth) / 2;  //Margine sinistro della finestra popup
	topMargin = (screen.height - winHeight) / 2; //Margine superiore della finestra popup
	if (toolbarFlag == 1) {	propString = "toolbar,"	} else { propString = "" }
	propString = propString + "scrollbars,width=" + winWidth + ",height=" + winHeight;  //Costruisce la stringa con le
	propString = propString + ",left=" + leftMargin + ",top=" + topMargin; //proprietà della finestra popup
	
	fsWin = window.open(linkString, "fsWin", propString);
} //openPopup


function openIndexLink(indexLink) {
	document.writeln("<HTML>");
	document.writeln("<TITLE>Parrocchia dei Ss. Simone e Giuda</TITLE>");
	document.writeln("<FRAMESET ROWS=\"80,*\" FRAMESPACING=\"0\" FRAMEBORDER=\"0\">");
	document.writeln("<FRAME src=\"top.htm\" SCROLLING=\"NO\" name=\"topFrame\">");
	document.writeln("<FRAME src=\"" + indexLink + "\" name=\"mainFrame\">");
	document.writeln("</FRAMESET>");
	document.writeln("</HTML>");
} //openIndexLink


function photoShowcase(maxPhoto, numLevels) {
	dirLevel = "";
	for (i = 0; i < numLevels; i++) { //Legge i sottolivelli rispetto alla directory radice del sito
		dirLevel = dirLevel + "../";  //(passati tramite numLevels) e costruisce la stringa dirLevel
	}								  //aggiungendo "../" per ogni sottolivello. Serve per lo sfondo
	
	document.writeln("<HTML>");
	document.writeln("<TITLE>Images Showcase</TITLE>");
	document.writeln("<link href=\"" + dirLevel + "siteStyle.css\" rel=\"stylesheet\" type=\"text/css\">");
	document.writeln("<script language=\"JavaScript\" src=\"" + dirLevel + "siteScript.js\"></script>");
	document.write  ("<BODY background=\"" + dirLevel + "immagini/sfondo.jpg\" ");
	document.writeln("leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">");
	document.writeln("<table width=\"750\" height=\"550\" align=\"center\"><tr><td width=\"600\">");
	document.writeln("<DIV align=\"center\"><IMG name=\"imgPhoto\"></div>"); //Placeholder per l'immagine
	document.writeln("</td><td><div align=\"center\">");
	document.write  ("<img src=\"" + dirLevel + "immagini/left_arrow.gif\" "); //Freccia "Indietro"
	document.writeln("onClick=\"changeImg(0, " + maxPhoto + ")\" style=\"cursor:hand\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	document.write  ("<img src=\"" + dirLevel + "immagini/right_arrow.gif\" "); //Freccia "Avanti"
	document.writeln("onClick=\"changeImg(1, " + maxPhoto + ")\" style=\"cursor:hand\">");
	document.writeln("<input name=\"txtNumPhoto\" type=\"text\" id=\"txtNumPhoto\" style=\"background-color: #669999; ");
	document.write  ("color: #FFFFFF; border: 0px; font-weight: bold; text-align: center;\" readonly=\"true\">");
	document.write  ("<br><br><font size=\"2\"><a href=\"javascript:history.go(-1)\" class=\"signVerde\">");
	document.writeln("<strong>Indietro</strong></A></font></td></tr></table>");
	document.writeln("<script language=\"JavaScript\">changeImg(1, " + maxPhoto + ");</script>"); //1a foto
	document.writeln("</BODY>");
	document.writeln("</HTML>");
} //photoShowcase


function changeImg(dirChange, maxPhoto) {
	/*** DirChange: 1 = avanti, 0 = indietro ***/
	actualImg = document.imgPhoto.src; //Legge la foto attualmente caricata
	//Estrae il numero di foto dal percorso completo del file
	actualImgLen = actualImg.length;
	actualImg = actualImg.substring(actualImgLen - 6, actualImgLen - 4);
	tmp = parseInt(actualImg); //Converte il numero di foto in numero

	switch(dirChange) {
		case 1: //Direzione: avanti
			if (tmp < maxPhoto) //Non siamo ancora alla fine dello showcase
				tmp = tmp + 1; //Avanti di 1 foto
			else
				tmp = 1; //Fine dello showcase: riparte da 1
			break;
		case 0: //Direzione: indietro
			tmp = tmp - 1; //Indietro di 1 foto
			if (tmp < 1) //Se si è alla foto 1 e si sceglie "Indietro", va all'ultima foto
				tmp = maxPhoto;
			break;
	}

	if (tmp < 10) //Se il numero di foto è < 10, aggiunge uno 0 davanti (01, 02, 03, ecc.)
		actualImg = "0" + tmp;
	else
		actualImg = tmp;
		
	document.all.imgPhoto.src = "showcase/" + actualImg + ".jpg"; //Carica la nuova foto
	document.all.txtNumPhoto.value = "Immagine " + tmp + " di " + maxPhoto;
} //changeImg