/*                   Script realizzato da Mastromatteo Matteo                     */
/* lo script può essere usato liberamente se questo messaggio è mantenuto intatto */

/* Costanti */
PAR="<p class='Nero' align='justify'>"; 
nPAR="</p>"; 
BPAR="<p class='Bianco'>"; 
SPZ=" "; 
NLPAR=PAR+SPZ+nPAR;
VIS="Visitatore n° ";
FNT="<font id='fonttesto'>";
nFNT="</font>";

/* oggetto TColor */
HexVal = new Array ("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
function IntToHex(value){
	var RetVal="00";

	RetVal=HexVal[Math.floor(value / 16)]+HexVal[Math.floor(value % 16)];
	return RetVal;
}

function HexToInt(value){
	var cifra1=0;
	var cifra2=0;
	
	value=value.toUpperCase();
	while (HexVal[cifra1]!=value.charAt(0))
		cifra1++;
	while (HexVal[cifra2]!=value.charAt(1))
		cifra2++;
	
	cifra1=(cifra1*16)+cifra2;
	return cifra1;
}

function TColor(R, G, B){
	this.red = R;
	this.green = G;
	this.blue = B;
}

/* Titolo Scorrevole con fade */
var TitCount=-1;
TitScorr = new Array ();
TitScorr[0]="...Benvenuti nel Mastro3D site...";
TitScorr[1]="...qui troverete informazioni utili per quanto riguarda...";
TitScorr[2]="...la programmazione in Delphi e Pascal...";
TitScorr[3]="...la teoria che sta dietro ad un motore di rendering...";
TitScorr[4]="...le risorse per la programmazione e la grafica...";
TitScorr[5]="...i link ai maggiori siti di programmazione Delphi e OpenGL...";
TitInc=6;
TitDelay=90;
TitStopDelay=3000;
TitFadeDelay=1000;
TitEndDelay=1000;
TitPauseDelay=TitStopDelay-TitFadeDelay;
TitStartColor = new TColor(HexToInt("FF"), HexToInt("FF"), HexToInt("FF"));
TitEndColor = new TColor(HexToInt("00"), HexToInt("66"), HexToInt("99"));
FadeDivisor = 2;
nFadings=0;
nMaxFadings=TitFadeDelay/(TitDelay/FadeDivisor);
var Col = new TColor(TitStartColor.red, TitStartColor.green, TitStartColor.blue);
IncCol = new TColor((TitEndColor.red-TitStartColor.red)/nMaxFadings+1, 
					(TitEndColor.green-TitStartColor.green)/nMaxFadings+1,
					(TitEndColor.blue-TitStartColor.blue)/nMaxFadings+1);
TitStart=635;
var TitX=TitStart;

/* Banner siti internet */
BannerCount=-1;
Banner = new Array ();
Banner[0]="gpi.jpg";
Banner[1]="html.jpg";
Banner[2]="sulaco.jpg";
Banner[3]="nehe.jpg";
Banner[4]="delphigamer.jpg";
Banner[5]="about.jpg";
Banner[6]="torry.jpg";
BannerDir="banners/";
BannerUrl=new Array ();
BannerUrl[0]="http://gameprog.it/";
BannerUrl[1]="http://www.html.it/";
BannerUrl[2]="http://www.sulaco.co.za/";
BannerUrl[3]="http://nehe.gamedev.net/";
BannerUrl[4]="http://www.delphigamer.com/";
BannerUrl[5]="http://delphi.about.com/";
BannerUrl[6]="http://www.torry.net/";

var Counter=1;
ID_BANNER="banner";
ID_MARQUEE="testoscorr";
ID_COUNTER="contatore";
ID_OROLOGI="orologio";
ID_TITOLO="titolo";
ID_PAGINA="pagina";

function WriteText(aLayer, text){
	aLayer.innerHTML=text;
}

function initall(){
	objbanner=document.getElementById(ID_BANNER);
	objtesto=document.getElementById(ID_MARQUEE);
	objora=document.getElementById(ID_OROLOGI);
	objconta=document.getElementById(ID_COUNTER);
	objtitolo=document.getElementById(ID_TITOLO);
	objpagina=document.getElementById(ID_PAGINA);

	// Inizializzazioni
	objtesto.style.overflow='hidden';
	objtesto.style.position='relative'; 
	document.search.query.style.width='146px';

	// Loops
	UpdateBanner();
	UpdateScrollTitle();
	UpdateTime();
}

function UpdateBanner(){
	BannerCount++;
	if (BannerCount > Banner.length-1) BannerCount=0;

	newbanner = '<a href="'+BannerUrl[BannerCount]+'" title="'+BannerUrl[BannerCount]+'"><img src="'+BannerDir+Banner[BannerCount]+'" border="0"></a>';

	WriteText(objbanner, newbanner);

	setTimeout("UpdateBanner()", 5000);
}

function setLeft(aLayer, value){
	aLayer.style.left=value;
}

function Timer(){
	TitX-=TitInc;
	setLeft(objtesto, TitX);

	if (TitX <= 0){
		TitX=0;
		setLeft(objtesto, TitX);

		setTimeout("initFade()", TitPauseDelay);
	}
	else setTimeout("Timer()", TitDelay);
}

function initFade(){
	Col.red = TitStartColor.red;
	Col.green = TitStartColor.green;
	Col.blue = TitStartColor.blue;
	nFadings=0;
	WriteText(objtesto, FNT+TitScorr[TitCount]+nFNT);
	FadeTitle();
}

function FadeTitle(){
	Col.red += IncCol.red;
	Col.green += IncCol.green;
	Col.blue += IncCol.blue;

	document.getElementById('fonttesto').color="#"+IntToHex(Col.red)+IntToHex(Col.green)+IntToHex(Col.blue);
	
	if (nFadings++ < nMaxFadings)
		setTimeout("FadeTitle()", Math.floor(TitDelay/FadeDivisor));
	else setTimeout("UpdateScrollTitle()", TitEndDelay);
}

function UpdateScrollTitle(){
	TitX=TitStart;
	TitCount++;

	if (TitCount > TitScorr.length-1) TitCount=0;
	WriteText(objtesto, TitScorr[TitCount]);

	Timer();
}

function UpdateTime(){
	var Oggi = new Date();
	var sOggi = Oggi.toGMTString();
	
	WriteText(objora, sOggi);

	setTimeout("UpdateTime()", 1000);
}

ImgNames = new Array();
ImgNames[0]="trova";
ImgNames[1]="artrova";

function LoadImage(num, Dest, Kind){
	var Img = new Image();
	Img.src = "images/"+ImgNames[num]+Kind+".gif";

	eval("document."+Dest+".src=Img.src");
}

