// slidingBlackBoard1.0
// --------------------

// imposta variabili di controllo avvenuto caricamento
var slidingBlackboard = 1;

// verifica avvenuto caricamento delle librerie necessarie
// -------------------------------------------------------
if (typeof(checkBrowser)=="undefined") alert("Attenzione!\n--------------\n La libreria \"slidingBlackboard\" necessita della libreria \"checkBrowser\".");
if (typeof(gestioneLivelli)=="undefined") alert("Attenzione!\n--------------\n La libreria \"slidingBlackboard\" necessita della libreria \"gestioneLivelli\".");

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Lavagna a scorrimento orizzontale (inizio Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function buildBlackboard(bbName, xCoord, yCoord, bbWidth, bbHeight, bbText, bbBorderColor, bbBgColor, bbDelay)
{
	// -----------------------
	// Costruisce la "lavagna"
	// -----------------------
	// bbName --> nome della lavagna
	// xCoord --> Coordinata X della lavagna
	// yCoord --> Coordinata Y della lavagna
	// bbWidth --> Larghezza della lavagna
	// bbHeight --> Altezza della lavagna
	// bbBorderColor (opzionale) --> colore bordo
	// bbBgColor (opzionale) --> colore sfondo
	// bbText --> testo da inserire nella lavagna
	var bbCode = new String();
	var marginWidth // <-- Distanza dai bordi sinistro e destro della tabella
	var marginHeght // <-- Distanza dai bordi inferiore e superiore della tabella

	if (bbBorderColor=="") bbBorderColor = "#000000";
	if (bbBgColor=="") bbBgColor = "#FFFFFF";
	if (bbDelay=="") bbDelay="55";
	marginWidth = 5;
	marginHeight = 5;

	var	theClientBrowser = clientBrowser(); // <-- funzione istanziata in "checkBrowser.js"
	var lay; // <-- Variabile interna. Contiene oggetto layer da "scrollare";
	var layHeight // <-- Variabile interna. Contiene altezza layer da "scrollare";
	var tim;

	if (theClientBrowser=="netscape4.x") {bbCode += "<LAYER ID=\""+bbName+"(border)\" LEFT=\""+xCoord+"\" TOP=\""+yCoord+"\" WIDTH=\""+bbWidth+"\" HEIGHT=\""+bbHeight+"\"> \n"; }
	else {bbCode += "<DIV ID=\""+bbName+"(border)\" STYLE=\"position:absolute; left:"+xCoord+"; top:"+yCoord+"; width:"+bbWidth+"; height:"+bbHeight+";\"> \n"; };
	bbCode += "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" WIDTH=\""+bbWidth+"\" HEIGHT=\""+bbHeight+"\" BGCOLOR=\""+bbBorderColor+"\"> \n";
	bbCode += "<TR> \n";
	bbCode += "	<TD ALIGN=\"center\" VALIGN=\"middle\"> \n";
	bbCode += "	<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" WIDTH=\""+(bbWidth-2)+"\" HEIGHT=\""+(bbHeight-2)+"\" BGCOLOR=\""+bbBgColor+"\"> \n";
	bbCode += "	<TR> \n";
	bbCode += "		<TD>&nbsp; \n";
	if (theClientBrowser=="netscape4.x") {bbCode += "		<LAYER ID=\""+bbName+"(clip)\" LEFT=\""+marginWidth+"\" TOP=\""+marginHeight+"\" WIDTH=\""+(bbWidth-marginWidth-marginWidth)+"\" HEIGHT=\""+(bbHeight-marginHeight-marginHeight)+"\" CLIP=\"0,0,"+(bbWidth-marginWidth-marginWidth)+","+(bbHeight-marginHeight-marginHeight)+"\"> \n"; }
	else {bbCode += "		<DIV ID=\""+bbName+"(clip)\" STYLE=\"position:absolute;left:"+marginWidth+";top:"+marginHeight+";width:"+(bbWidth-marginWidth-marginWidth)+";height:"+(bbHeight-marginHeight-marginHeight)+"; overflow:hidden;\"> \n"; };
	if (theClientBrowser=="netscape4.x") {bbCode += "		<LAYER ID=\""+bbName+"\" LEFT=\"0\" TOP=\"0\" WIDTH=\""+(bbWidth-marginWidth-marginWidth)+"\" > \n"; }
	else {bbCode += "		<DIV ID=\""+bbName+"\" STYLE=\"position:absolute;left:0;top:0;width:"+(bbWidth-marginWidth-marginWidth)+";\"> \n"; };
	// inserisce il contenuto nella lavagna
	bbCode += bbText +"\n";
	// -------------------------------------
	if (theClientBrowser=="netscape4.x") {bbCode += "		</LAYER> \n"; }
	else {bbCode += "		</DIV> \n"; };
	if (theClientBrowser=="netscape4.x") {bbCode += "		</LAYER> \n"; }
	else {bbCode += "		</DIV> \n"; };
	bbCode += "		</TD> \n";
	bbCode += "	</TR> \n";
	bbCode += "	</TABLE> \n";
	bbCode += " </TD> \n";
	bbCode += "</TR> \n";
	bbCode += "</TABLE> \n";
	if (theClientBrowser=="netscape4.x") {bbCode += "</LAYER> \n";}
	else {bbCode += "</DIV> \n"; };
	document.write(bbCode);
	if (theClientBrowser=="netscape4.x") {lay = document.layers[bbName+"(border)"].layers[bbName+"(clip)"].layers[bbName]}
	else {lay = document.getElementById(bbName) };
	moveLayBy(lay, 0, (bbHeight+10));
	layHeight = getLayHeight(lay); // <-- funzione istanziata in "gestioneLivelli.js"
	scrollLay(bbName, layHeight, bbHeight, parseInt(bbDelay));
};

function scrollLay(layId, layHeight, blackboardHeight, delay)
{
	// -------------------------
	// "scrolla" l'oggetto layer
	// ricevuto come parametro;
	// -------------------------
	var lay;
	var layTop;
	var theClientBrowser = clientBrowser();
	if (theClientBrowser=="netscape4.x")
	{
		lay = document.layers[layId+"(border)"].layers[layId+"(clip)"].layers[layId];
	}
	else
	{
		lay = document.getElementById(layId);
	};
	layTop = getLayTop(lay); // <-- funzione istanziata in "gestioneLivelli.js"
	if ((layHeight+layTop)<0) { moveLayBy(lay, 0, (layHeight+blackboardHeight+10));}
	moveLayBy(lay, 0, -1); // <-- funzione istanziata in "gestioneLivelli.js"
	tim2 = setTimeout("scrollLay('"+layId+"',"+layHeight+","+blackboardHeight+", "+delay+")", delay);
};


function moveBuildBlackboardTo(bbName, xCoord, yCoord)
{
	// ------------------------------------------
	// Sposta la lavagna alle coordinate indicate
	// ------------------------------------------
	bbName += "(border)";
	if (clientBrowser()=="netscape4.x")
	{
		lay = document.layers[bbName];
	}
	else
	{
		lay = document.getElementById(bbName);
	};
	moveLayTo(lay, xCoord, yCoord);
}

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Lavagna a scorrimento orizzontale (fine Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
