// JavaScript Document
	var aBnrManagers = new Array(); // Array con i gestori dei banner.
	var bnrMan = null;				

// Nota: Non uso le collezioni di immagini e link per ritrovare gli elementi nella pagina 
// a causa di una implementazione errata in Internet Explorer della collezione links: essa
// sembra non supportare la scelta di un elemento con le parentesi quadre.
	function getBannerElement(id) {
	// Tenta con getElementByID
		if(document.getElementById) 
			return document.getElementById(id);	
	// e poi con document.all	
		else if(document.all) 
			return document.all[id];	
		return null;
	}

// Oggetto Banner
	function Banner(mn, fn, w, h, tit, lnk, trg, tt) {
		this.manager = mn;
		this.bnrImage = new Image(w, h);  // Pre-caching dell'immagine.
		this.bnrImage.src = fn;
		this.title = tit;
		this.url = lnk;
		this.target = trg;
		this.transTime = tt;
		this.ShowBanner = ShowBanner;
	}
	
	function ShowBanner() {
		var img = getBannerElement('pic' + this.manager.placeCode);
		var lnk = getBannerElement('link' + this.manager.placeCode);		
	// Sostituisce l'immagine solo se il caricamento è completato.
		if (this.bnrImage && this.bnrImage.complete && img && lnk) {   
			with (img) {
				src = this.bnrImage.src;
				if (width != this.bnrImage.width) // Cerca di evitare lampeggiamenti inutili
					width = this.bnrImage.width;
				if (height !=  this.bnrImage.height) 
					height = this.bnrImage.height;
				alt = this.title;
			}
			with (lnk) {
				href = this.url;
				target = this.target;
				title = this.title;			
			}
		}
	}
		
// Oggetto BnrManager
	function BnrManager(placeCode) {
		this.placeCode = placeCode;
		this.actPos = 0;	
		this.halted = false;
		this.aBanners = new Array();
		this.AddBanner = AddBanner;
		this.StartSlideshow = StartSlideshow;
		this.ShowNextBanner = ShowNextBanner;
	}
	
	function AddBanner(fn, w, h, tit, lnk, trg, tt) {
		this.aBanners[this.aBanners.length] = new Banner(this, fn, w, h, tit, lnk, trg, tt);
	}

	function ShowNextBanner() {
		if (this.aBanners.length < 2) return; // Nessuna slideshow se non ci sono almeno due banner.
		if (!this.halted) {	
			this.actPos++;
			if (this.actPos >= this.aBanners.length) this.actPos = 0;
			this.aBanners[this.actPos].ShowBanner();	
		}
		var tt = this.aBanners[this.actPos].transTime * 1000; // Valore in ms.
		var methodName = 'aBnrManagers[\'' + this.placeCode + '\'].ShowNextBanner();';
		setTimeout(methodName, tt);	
	}
	

	function StartSlideshow() {
		if (this.aBanners.length < 2) return; // Nessuna slideshow se non ci sono almeno due banner.
		var tt = this.aBanners[0].transTime * 1000; // Valore in ms.
		var methodName = 'aBnrManagers[\'' + this.placeCode + '\'].ShowNextBanner();';
		setTimeout(methodName, tt);	
	}
	
// Funzione accessoria per creare i BnrManager necessari.
	function getBnrManager(placeCode) {
		if (aBnrManagers[placeCode])
			return aBnrManagers[placeCode];
		var res = new BnrManager(placeCode);
		aBnrManagers[placeCode] = res;
		return res;
	}

	function pauseSlideshow(placeCode, ssHalt) {
		if (aBnrManagers[placeCode])
			aBnrManagers[placeCode].halted = ssHalt;
	}