// Configuration for vim {{{1
//	vim: set fdm=marker:
//	vim: ff=unix ts=4 ss=4
// }}}1

/**************************************************************************\
**                                                                        **
**                  ┏┓┏━┓   ┏━┓╻  ╻╺┳┓┏━╸   ┏━┓╻ ╻┏━┓╻ ╻                  **
**                   ┃┗━┓   ┗━┓┃  ┃ ┃┃┣╸    ┗━┓┣━┫┃ ┃┃╻┃                  **
**                 ┗━┛┗━┛   ┗━┛┗━╸╹╺┻┛┗━╸   ┗━┛╹ ╹┗━┛┗┻┛                  **
**                      ———— www.FLogisoft.com ————                       **
**                                                                        **
\**************************************************************************/

/**************************************************************************\
**                                                                        **
** JS Slide Show                                                          **
** Copyright (C) 2009 Fabien Loison                                       **
**                                                                        **
** This program is free software: you can redistribute it and/or modify   **
** it under the terms of the GNU General Public License as published by   **
** the Free Software Foundation, either version 3 of the License, or      **
** (at your option) any later version.                                    **
**                                                                        **
** This program is distributed in the hope that it will be useful,        **
** but WITHOUT ANY WARRANTY; without even the implied warranty of         **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          **
** GNU General Public License for more details.                           **
**                                                                        **
** You should have received a copy of the GNU General Public License      **
** along with this program.  If not, see <http://www.gnu.org/licenses/>.  **
**                                                                        **
\**************************************************************************/


//======================================================= Config ====
	// Configuration {{{1
	var duration = 7000;
	var alphaDuration = 500;

	var ctrlsSize = 22; //!!!

	var imgPlay = "./slide/btPlay.png"
	var imgPause = "./slide/btPause.png"

	var imgPath = "./slide/";
	var thumbPath = "./slide/";
	var imgList = new Array(
			"01_music.png",
			"02_pictures.png",
			"03_other.png");
	//}}}1



//========================================================= Lang ====
// Language strings {{{1
var lngPlaying = 'Lecture...';
var lngPaused = 'En pause';
// }}}1



//========================================================== Var ====
// Variables declaration {{{1
var objImg = document.getElementById('jsSlideShow_picture');
var objCtrls = document.getElementById('jsSlideShow_ctrls');
var objSlideState = document.getElementById('jsSlideShow_state');
var objBtPlayPause = document.getElementById('jsSlideShow_btPlayPause');

var currentImg = -1;
var alpha = 0;
var i = 0;
var sc = false;
var sc0 = false;
var isPlaying = true;
// }}}1



//==================================================== Functions ====
// Functions {{{1 
//----------------------------------------------- main ----
// Functions » Main {{{2
function preload(){
	imgload = new Array();
	for (var j=0 ; j<imgList.length ; j++) {
		imgload[j] = new Image();
		imgload[j].src = thumbPath+'/'+imgList[j];
		//document.write(imgList[j]+"<br />");
	}
}

function pictureNext() {
	currentImg++;
	if (currentImg > imgList.length-1) {
		currentImg = 0;
	}
	opacity0();
	setTimeout("objImg.src=thumbPath+'/'+imgList["+currentImg+"];", alphaDuration+5);
	setTimeout("slideState()", alphaDuration+5);
	setTimeout("opacity1();", alphaDuration+10); 
}

function picturePrev() {
	currentImg--;
	if (currentImg < 0) {
		currentImg = imgList.length-1;
	}
	opacity0();
	setTimeout("objImg.src=thumbPath+'/'+imgList["+currentImg+"];", alphaDuration+5);
	setTimeout("slideState()", alphaDuration+5);
	setTimeout("opacity1();", alphaDuration+10); 
}

function slideState() {
	if (isPlaying) {
		objSlideState.firstChild.data = lngPlaying+' - '+(currentImg+1)+'/'+imgList.length;
	} else {
		objSlideState.firstChild.data = lngPaused+' - '+(currentImg+1)+'/'+imgList.length;
	}
}

function slidePlay() {
	isPlaying = true;
	slideState()
	objBtPlayPause.src = imgPause
	timer = setInterval("pictureNext()", duration);
}

function slidePause() {
	clearInterval(timer);
	isPlaying = false;
	slideState()
	objBtPlayPause.src = imgPlay
}
// }}}2

//-------------------------------------------- effects ----
// Functions » Effects (Alpha blend,...) {{{2
function opacity0() {
	for (alpha=0 ; alpha<=10 ; alpha++) {
		setTimeout("objImg.style.opacity="+alpha/10+";", alphaDuration-alpha*alphaDuration/10);
		setTimeout("objImg.style.filter='alpha(opacity="+alpha*10+")';", alphaDuration-alpha*alphaDuration/10);
	}
}

function opacity1() {
	for (alpha=0 ; alpha<=10 ; alpha++) {
		setTimeout("objImg.style.opacity="+alpha/10+";", alpha*alphaDuration/10);
		setTimeout("objImg.style.filter='alpha(opacity="+alpha*10+")';", alpha*alphaDuration/10);
	}
}

function ctrlsSwitch() {
	if (sc != sc0) {
		if (sc) {
			objCtrls.style.height = "0px";
			for (i=0 ; i<= ctrlsSize ; i=i+2 ) {
				setTimeout("objCtrls.style.height = '"+i+"px'", i*5);
			}
		} else {
			objCtrls.style.height = ctrlsSize+"px";
			for (i=0 ; i<= ctrlsSize ; i=i+2 ) {
				setTimeout("objCtrls.style.height = '"+i+"px'", ctrlsSize*3-i*5);
			}
		}
		sc0 = sc;
	}
}
// }}}2

//--------------------------------------------- Events ----
// Functions » Events (Reaction to events) {{{2
function ctrlsShow() {
	sc = true;
	setTimeout("ctrlsSwitch()", 10);
}

function ctrlsHide() {
	sc = false;
	setTimeout("ctrlsSwitch()", 10);
}

function btNext() {
	slidePause();
	pictureNext();
}

function btPrev() {
	slidePause();
	picturePrev();
}

function togglePlayPause() {
	if (isPlaying) {
		slidePause();
	} else {
		slidePlay();
		pictureNext();
	}
}
// }}}2
// }}}1



//========================================================= MAIN ====
// MAIN program {{{1

//Preload pictures
preload();

//Set ctrlsBar property
objCtrls.style.height = 0;
objCtrls.style.display = 'block';
objCtrls.style.opacity = .7;
objCtrls.style.filter = "alpha(opacity=70)";
objSlideState.firstChild.data = '1/1';

//Run
pictureNext(); //!! +  -1
slidePlay();
// }}}1



