﻿if(typeof LOC == 'undefined') {
	var LOC = {};
}
LOC.diap;
LOC.diapox;
LOC.num;
LOC.diaporama;
var regalInterv;
$(document).ready(function() {
	LOC.diap = ["regaloeb", 1, 2];
	//element[1] is the index of the current diapo in the left target
	//element[2] is the index of the current diapo in the right target
	//element[0] is regaloeb, it's useless !
	LOC.diapox = ["regaloeb", 0, 630];
	//element[1] is the X position for left diapo
	//element[2] is the X position for right diapo
	//element[0] is regaloeb, it's useless !
	LOC.num = 2;
	//num indicates which element of diap is going to be manipulated
	LOC.diapoAutoLaunch = false;//indicates when the autoLaunch is launched
	LOC.diaporama = function(){
		LOC.num = (LOC.num == 2) ? 1:2;
		var oldDiap = LOC.diap[LOC.num];
		LOC.diap[LOC.num] = LOC.diap[LOC.num] - 1;
		if(LOC.diap[LOC.num]<=0){
			LOC.diap[LOC.num] = 3;
		}
		var curDiap = LOC.diap[LOC.num];
		var pox = LOC.diapox[LOC.num];
		var diapo = $('#diapo' + curDiap);
		$(diapo).hide();
		document.getElementById('diapo' + curDiap).style.zIndex = 32;
		document.getElementById('diapo' + oldDiap).style.zIndex = 30;
		$(diapo).css('left', pox);
		$(diapo).fadeIn(1500);
	}
	
	//activation of the play/stop button
	$('#diapoPlayStop').show();
	$('#diapoPlayStop .diapoStop').click(function(e){
		clearInterval(regalInterv);
		$(this).hide();
		$('#diapoPlayStop .diapoPlay').show();
		e.preventDefault();
	});
	$('#diapoPlayStop .diapoPlay').click(function(e){
		LOC.diaporama();
		regalInterv = setInterval('LOC.diaporama();', 2000);
		$(this).hide();
		$('#diapoPlayStop .diapoStop').show();
		e.preventDefault();
	});
	//diaporama will run when the first image is loaded
	$('#diapo1 img').load(function(){
		if(top.location.hash == "#debug") alert('#diapo1 img onload');
		if(!LOC.diapoAutoLaunch){
			regalInterv = setInterval('LOC.diaporama();', 2000);
			LOC.diapoAutoLaunch = true;
		}
	});
});
//bug connexion intranet chez L'Oréal...
$(window).load(function(){
	if(top.location.hash == "#debug") alert("window jquery onload, LOC.diapoAutoLaunch: " + LOC.diapoAutoLaunch);
	if(!LOC.diapoAutoLaunch){
		regalInterv = setInterval('LOC.diaporama();', 2000);
		LOC.diapoAutoLaunch = true;
	}
});
addEvent(window, "load", function(){
	if(top.location.hash == "#debug") alert("window addEvent onload, LOC.diapoAutoLaunch: " + LOC.diapoAutoLaunch);
	if(!LOC.diapoAutoLaunch){
		regalInterv = setInterval('LOC.diaporama();', 2000);
		LOC.diapoAutoLaunch = true;
	}
});
var forceAutoLaunch = setTimeout('LOC.force();', 5000);
LOC.force = function(){
	if(top.location.hash == "#debug") alert("LOC.force() après 5 secondes, LOC.diapoAutoLaunch: " + LOC.diapoAutoLaunch);
	if(!LOC.diapoAutoLaunch){
		regalInterv = setInterval('LOC.diaporama();', 2000);
		LOC.diapoAutoLaunch = true;
	}
}