/************************************************************************************************************/
/* Updates an html img with a new photo, using previous/next commands navigating in a series of pics.
/* The html img must have a name and id defined, eg "diapo"
/* The pictures to display have to be named "diapo_1.jpg", "diapo_2.jpg", "diapo_3.jpg" etc. or
/* "diapo_1_lg.jpg", "diapo_2_lg.jpg", "diapo_3_lg.jpg" where lg is the language of the pic, if the pic contains text.
/* 
/* Variables path_photos and nb_photos MUST BE defined in document.diapo object. 
/* If required, lg, ind_this_photo (rank of currently displayed picture) and tablabels can also be defined in the object. 
/* tablabels should then be a table of strings containing nb_photos elements corresponding to labels that should
/* be displayed for each photo, in a span html field named <name fo the diapo>_label ("diapo_label" in our example).
/*
/* Example of code initiating the object:
document.slide1.tablabels = new Array('Το καμηλάρι','Το σπίτι μας','Το μπαλκόνι του σπιτιού','Ηλιοβασίλεμα στον κόλπο της Μεσαράς','Παραλία του Καλαμακίου');
document.slide1.nb_photos = 5;
document.slide1.path_photos = "./photos/";
/************************************************************************************************************/

// setting previous to true will update the img field named nom_diapo with the previous picture of the <nom_diapo>_*.jpg list. 
function previous_next_photo(nom_diapo, previous) {
	tmp = eval("document." + nom_diapo);
	if((tmp.path_photos==null) || (tmp.nb_photos==null)) {
	  return;
  }
	if((tmp.lg==null)) {    tmp.lg = "";
  }
   if((tmp.ind_this_photo==null)) {
		tmp.ind_this_photo = (previous==true ? tmp.nb_photos : 2);
	} else {
		tmp.ind_this_photo = (previous==true ? (tmp.ind_this_photo-1) : (tmp.ind_this_photo + 1));
	}
	if(tmp.ind_this_photo > tmp.nb_photos) {
		tmp.ind_this_photo = 1;
	}
	if(tmp.ind_this_photo <= 0) {
		tmp.ind_this_photo = tmp.nb_photos;
	}

	tmp.src = tmp.path_photos + nom_diapo + "_" + tmp.ind_this_photo + (tmp.lg!="" ? ("_" + tmp.lg) : "") + ".jpg";

	// label of the slide, if exists.
	tmp2 = document.getElementById(nom_diapo + "_label");
	if((tmp2!=null) && tmp.tablabels!=null) {
		document.getElementById(nom_diapo + "_label").innerHTML = tmp.tablabels[tmp.ind_this_photo-1];
	}
}

// starts automatic change of pictures
function start_diapo(mytime,nom_diapo) {
   tmp = eval("document." + nom_diapo);

	strcmd = "previous_next_photo(\"" + nom_diapo + "\",false)";
//	alert(strcmd);
	tmp.idInterval = setInterval(strcmd,mytime);
}
// pauses automatic change of pictures
function pause_diapo(nom_diapo) {
	tmp = eval("document." + nom_diapo);
	if((tmp.idInterval==null)) {    return;
  }

	clearInterval(tmp.idInterval);
	tmp.idInterval = "";
}

// toggles between pause and run slideshow, and updates the pause/play icon if found
// NEEDS PATHs TOWARDS <<, >>, pause andf play icons
// in the html doc, this image must ber named <nom_diapo> + "_startpauseimg
var pause_icon_path = "./resources/pause.jpg";
var play_icon_path = "./resources/play.jpg";

function toggle_pause_start(nom_diapo) {
	tmp = eval("document." + nom_diapo);
	// switch slideshow on
	if((tmp.idInterval==null) || (tmp.idInterval =="")) {
		start_diapo(5000, nom_diapo);
		tmp2 = eval("document." + nom_diapo + "_startpauseimg");
		if((tmp2!=null)) {
			tmp2.src = pause_icon_path;
		}
  } else { // switch slideshow off
		pause_diapo(nom_diapo);
		tmp2 = eval("document." + nom_diapo + "_startpauseimg");
		if((tmp2!=null)) {
			tmp2.src = play_icon_path;
		}
  }
}
