
//***************************************************
// Gestione Slideshow
//***************************************************

var ssMayGo			// finché è false indica che lo slideshow non può procedere (ad es. perché l'img corrente non è ancora stata caricata completamente)
ssMayGo = false  	// per consentire l'avanzamento dello slideshow, la funzione onLoad delle immagini caricate deve settare questa variabile a true
caricamentoCompletato = false
slideshowIsRunning = -1

function changeSlide(modo,nr){
	if(caricamentoCompletato==false){return};
	if(modo==1){ 	// qui nr coincide con l'indice numerico della slide chiamata
		i = nr;
	}else{			// qui nr è l'incremento/decremento da applicare all'indice attuale
		i = iAttuale + nr;
	}
	if((i<0)||(i>iMax)){
		if(slideshowIsRunning==1){stopSlideshow()}
		return;
	}
	if(iAttuale>=0){
		if(ssMayGo){
			ssMayGo = false;
			document.getElementById('slide').innerHTML = slides[i];
		}else{
			slideshow = setInterval("changeSlide("+modo+","+nr+")",1000);
		}
	}else{
		document.getElementById('slide').innerHTML = slides[i];
	}
	iAttuale = i;
	
	document.getElementById('slideDidasc').innerHTML = didasc[i];
	
//	document.getElementById("slide").innerHTML = slides[i];
}
function startSlideshow(){
	if((iAttuale==iMax)||(iAttuale==-1)){
		changeSlide(1,0);
	}else{
		changeSlide(0,1);
	}
	slideshow = setInterval("changeSlide(0,1)",5000);
	slideshowIsRunning = 1;
}
function stopSlideshow(){
	if(slideshow){
		clearInterval(slideshow);
		slideshowIsRunning = -1;
	}
}
//function openThumbnail(){
//	if(slideshowIsRunning == 1){
//		clearTimeout(slideshow);
//	}
//	slideshowIsRunning = 1;
//	location.href="";
//}

//==================================================
// slide object
//==================================================
function slide(src,link,text,window,attr,width,height) {
// This is the constructor function for the slide object.
// It is called automatically when you create a new slide object.
// For example:
// s = new slide();

  // Image URL
  this.src = src;
  
  // Image height
  this.height = height;
  
  // Image width
  this.width = width;

  // Link URL
  this.link = link;

  // Text to display
  this.text = text;

  // Name of the target window ("_blank")
  this.window = window;

  // Attributes for the target window:
  // width=n,height=n,resizable=yes or no,scrollbars=yes or no,
  // toolbar=yes or no,location=yes or no,directories=yes or no,
  // status=yes or no,menubar=yes or no,copyhistory=yes or no
  // Example: "width=200,height=300"
  this.attr = attr;

  // Create an image object for the slide
  if (document.images) {
    this.image = new Image();
  }

  // Public methods
  this.load = slide_load;
  this.hotlink = slide_hotlink;
}


function slide_load() {
// This function loads the image for the slide

  if (!document.images) { return; }

  if (!this.image.src) {
    this.image.src = this.src;
  }
}


function slide_hotlink() {
// This function jumps to the slide's link.
// If a window was specified for the slide, then it opens a new window.
  if (this.link != 0) {
  	this.link = "http://www.viiarchive.com/GetPhotoShare.aspx?PhotoID=" + this.link;	
  	if (this.window) {
		// If window attributes are specified, use them to open the new window
    	if (this.attr) {
      		window.open(this.link, this.window, this.attr);

    	} else {
      		// If window attributes are not specified, do not use them
      		// (this will copy the attributes from the originating window)
      		window.open(this.link, this.window);
    	}

  	} else {
    	// Open the hotlink in the current window
    	location.href = this.link;
  	}
  } else {
  	alert ("Coming soon\nThe ability to download direct from the VII Archive.");
  }
}
