// JavaScript Document - Author: Guido

var IMG_MAX = 10; 		// slides number
var DIR = "img/qansa/0"; 	// images URL
var EXT = ".jpg";		// file extention
var ITV = 2000; 		// delay in milleseconds

var images = new Array(IMG_MAX);
var captions = new Array(IMG_MAX);
var frame = 0;
var timeout_id = null;
var auto = false;


captions[0] = "Il sito di Adi Qansā";
captions[1] = "La cavitā delle pitture";
captions[2] = "L'insieme delle pitture";
captions[3] = "Bovini, rare figure umane e altri animali";
captions[4] = "Uomo con lancia";
captions[5] = "Uomo con tunica a grosse quadrettature";
captions[6] = "Bovini dalla forma allungata";
captions[7] = "Figura antropomorfa circondata da animali";
captions[8] = "Bovini domestici";
captions[9] = "Leone ferito";

function aggiornaIndice()
{
	var txt;

	txt = 'foto ' + (frame + 1) + ' di ' + IMG_MAX;
	document.getElementById("caption").firstChild.nodeValue = captions[frame];
	document.getElementById("index").firstChild.nodeValue = txt;
}

function caricaImmagini ()
{
	for (i = 0; i < IMG_MAX; i++)
	{
		images[i] = new Image();
	  	images[i].src = DIR + (i + 1) + EXT;
	}
	aggiornaIndice();
	//document.slideshow.play.focus();
}

function scorriImmagini ()
{
	frame++;
    if (frame == IMG_MAX) frame = 0;
    document.immagine.src = images[frame].src;
	aggiornaIndice();
	timeout_id = setTimeout("scorriImmagini()", ITV);
}

function avvia ()
{
	if (timeout_id == null)
	{
		auto = true;
		document.slideshow.play.value = "stop";
		scorriImmagini();
	}
	else
	{
		clearTimeout(timeout_id);
		timeout_id = null;
		document.slideshow.play.value = "start";
	}
}

function avanti (last)
{
	if (auto)
	{
    	clearTimeout(timeout_id);
		timeout_id = null;
		document.slideshow.play.value = "start";
        auto = false;
   	}

    if (last)
	{
		frame = IMG_MAX - 1;
	}
	else
	{
		frame++;
	}

	if (frame == IMG_MAX) frame = 0;
	document.immagine.src = images[frame].src;
	aggiornaIndice();
}

function indietro (first)
{
    if (auto)
	{
    	clearTimeout(timeout_id);
		timeout_id = null;
 		document.slideshow.play.value = "start";
        auto = false;
    }

	if (first)
	{
		frame = 0;
	}
	else
	{
		frame--;
	}

    if (frame < 0) frame = IMG_MAX - 1;
	document.immagine.src = images[frame].src;
	aggiornaIndice();

}