/************************************************************************************************************/
/* 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.SL_" + nom_diapo + "_obj");
	if(tmp==null) {
		return;
	}
	if((tmp.lg==null)) {
    	tmp.lg = "";
	}
	if((tmp.ind_this_photo==null)) {
		tmp.ind_this_photo = (previous==true ? (tmp.pixtab.length -1) : 1);
	} else {
		tmp.ind_this_photo = (previous==true ? (tmp.ind_this_photo-1) : (tmp.ind_this_photo + 1));
	}
	if(tmp.ind_this_photo >= tmp.pixtab.length) {
		tmp.ind_this_photo = 0;
	}
	if(tmp.ind_this_photo < 0) {
		tmp.ind_this_photo = tmp.pixtab.length - 1;
	}

	// change photo
	img = eval("document." + nom_diapo);
	img.src = tmp.pixtab[tmp.ind_this_photo].path;
	img.alt = tmp.alt[tmp.ind_this_photo];
	img.title = tmp.title[tmp.ind_this_photo];

	// label and legend of the image, if fields exist.
	labelhtmlfield = document.getElementById(nom_diapo + "_label");
	if((labelhtmlfield!=null) && tmp.label!=null) {
		document.getElementById(nom_diapo + "_label").innerHTML = tmp.label[tmp.ind_this_photo];
	}
	legend = document.getElementById(nom_diapo + "_legend");
	if((legend!=null) && tmp.title!=null) {
		document.getElementById(nom_diapo + "_legend").innerHTML = tmp.title[tmp.ind_this_photo];
	}
}

// starts automatic change of pictures
function start_diapo(nom_diapo,mytime) {
   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;
		}
  }
}
