
var accordeon = document.getElementById("als_accordeon");

var volet_title_width = 73;
var volet_width = 586;
var accordeon_width = 1024;
var accordeon_height = 289;
var increment = 40;
var accordeon_back = "transparent";
var accordeon_delay_before_first = 0;	// secondes avant la première transition
var accordeon_delay_beetween = 8;	// secondes entre chaque transition


function mon_volet(no,section) {
	var j = 0;
	var balisedivs = accordeon.getElementsByTagName("div");
	for (var i=0; i<balisedivs.length; i++) {
		if (balisedivs[i].className==section) {
			if (j==no) return balisedivs[i];
			j++;
		}
	}
}

var cur_volet = -1;
var h_increment = 0;
var nb = volet_width/increment;
var h_increment = Math.floor(accordeon_height/nb)+1;
var scroll_in_progress = false;
var bandeau_pos = findPos(accordeon);

function rotate_disable(yes) {
	scroll_in_progress = yes;
}

var nb_volet = 0;
var balisedivs = accordeon.getElementsByTagName("div");
for (var i=0; i<balisedivs.length; i++) {
	if (balisedivs[i].className=="title") {
		balisedivs[i].onclick = new Function("volet_selection("+nb_volet+")");
		balisedivs[i].style.top = (bandeau_pos[1]-accordeon_height).toString()+"px";
		balisedivs[i].style.left = (bandeau_pos[0]+(nb_volet*volet_title_width)).toString()+"px";
		balisedivs[i].style.zIndex = 3;
		balisedivs[i].style.visibility = 'visible';
		nb_volet++;
	}
}
var j = 0;
for (var i=0; i<balisedivs.length; i++) {
	if (balisedivs[i].className=="content") {
		var obj1 = mon_volet(j,"title");
		balisedivs[i].onmouseover = new Function("rotate_disable(true)");
		balisedivs[i].onmouseout = new Function("rotate_disable(false)");
		balisedivs[i].style.left = (parseInt(obj1.style.left)+volet_title_width).toString()+"px";
		balisedivs[i].style.top = (parseInt(obj1.style.top)).toString()+"px";
		balisedivs[i].style.width = volet_width.toString()+"px";
		balisedivs[i].style.zIndex = 0;
		j++;
	}
}

var cdiv = document.createElement("div");
cdiv.id = "initial_cache";
cdiv.style.position = "absolute";
cdiv.style.width = (accordeon_width-(volet_title_width*nb_volet)).toString()+"px";	
cdiv.style.height = accordeon_height.toString()+"px";		
cdiv.style.backgroundColor = accordeon_back;		
var obj1 = mon_volet(0,"title");
cdiv.style.left = (parseInt(obj1.style.left)+(volet_title_width*nb_volet)).toString()+"px";
cdiv.style.top = (parseInt(obj1.style.top)).toString()+"px";
cdiv.style.zIndex = 2;
	// debug
	//cdiv.style.visibility = 'hidden';
document.body.appendChild(cdiv);


var curcontent = null;
var curcontent1 = null;
var curno = 0;
var timer = null;
var repostimer = null;


function reset_timer() {
	if (timer!=null) clearTimeout(timer);
	timer = setTimeout (volet_rotate, accordeon_delay_beetween*1000);
	accordeon_delay_beetween = 4;	// secondes entre chaque transition
}

function set_zindex(no) {
	var j = 0;
	var balisedivs = accordeon.getElementsByTagName("div");
	for (var i=0; i<balisedivs.length; i++) {
		if (balisedivs[i].className=="content") {
			if (j==no) balisedivs[i].style.zIndex = 1; else balisedivs[i].style.zIndex = 0;
			j++;
		}
	}
}

function do_developpe_left() {
	var w = parseInt(curcontent.style.width)-increment;
	if (w<0) w = 0;
	curcontent.style.width = w.toString()+"px";
	var h = parseInt(curcontent.style.height)-h_increment;
	if (h<0) h = 0;
	curcontent.style.height = h.toString()+"px";
	h = parseInt(curcontent1.style.height)+h_increment;
	if (h>accordeon_height) h = accordeon_height;
	curcontent1.style.height = h.toString()+"px";
	var l = parseInt(curcontent.style.left)+w;
	for (var i=cur_volet+1; i<=curno; i++) {
		var ct = mon_volet(i,"title");
		ct.style.left = (l+(volet_title_width*(i-(cur_volet+1)))).toString()+"px";
	}
	if (w>0) setTimeout (do_developpe_left, 20);
	else {
		var curc = mon_volet(cur_volet,"content");
		curc.style.visibility = "hidden";
		cur_volet = curno;
		scroll_in_progress = false;
		reset_timer();
	}
}

function do_developpe_right() {
	var w = parseInt(curcontent.style.width)+increment;
	if (w>volet_width) w = volet_width;
	curcontent.style.width = w.toString()+"px";
	var h = parseInt(curcontent.style.height)+h_increment;
	if (h>accordeon_height) h = accordeon_height;
	curcontent.style.height = h.toString()+"px";
	h = parseInt(curcontent1.style.height)-h_increment;
	if (h<0) h = 0;
	curcontent1.style.height = h.toString()+"px";
	var l = parseInt(curcontent.style.left)+w;
	for (var i=curno+1; i<=cur_volet; i++) {
		var ct = mon_volet(i,"title");
		ct.style.left = (l+(volet_title_width*(i-(curno+1)))).toString()+"px";
	}
	if (w<volet_width) setTimeout (do_developpe_right, 20);
	else {
		var curc = mon_volet(cur_volet,"content");
		curc.style.visibility = "hidden";
		cur_volet = curno;
		scroll_in_progress = false;
		reset_timer();
	}
}

function volet_developpe_left() {
	scroll_in_progress = true;
	set_zindex(cur_volet);
	curcontent1 = mon_volet(curno,"content");
	curcontent1.style.width = volet_width.toString()+"px";
	curcontent1.style.height = "0px";
	curcontent1.style.visibility = "visible";
	curcontent = mon_volet(cur_volet,"content");
	curcontent.style.height = accordeon_height.toString()+"px";
	setTimeout (do_developpe_left, 20);
}

function volet_developpe_right() {
	scroll_in_progress = true;
	curcontent1 = mon_volet(cur_volet,"content");
	//curcontent.style.visibility = "hidden";
	curcontent1.style.height = accordeon_height.toString()+"px";
	curcontent = mon_volet(curno,"content");
	curcontent.style.width = "0px";
	curcontent.style.height = "0px";
	curcontent.style.visibility = "visible";
	set_zindex(curno);
	setTimeout (do_developpe_right, 20);
}

function volet_selection(no) {
	if (scroll_in_progress) return;
	curno = no;
	if (no>cur_volet) volet_developpe_left() ;
	else if (no<cur_volet) volet_developpe_right() ;
}

function volet_rotate() {
	if (scroll_in_progress) {
		reset_timer();
		return;
	}
	curno++;
	if (curno>=nb_volet) curno = 0;
	if (curno>cur_volet) volet_developpe_left() ;
	else if (curno<cur_volet) volet_developpe_right() ;
}

function do_developpe() {
	var w = parseInt(curcontent.style.width)+increment;
	if (w>volet_width) w = volet_width;
	var h = parseInt(curcontent.style.height)+h_increment;
	if (h>accordeon_height) h = accordeon_height;
	var l = parseInt(curcontent.style.left)+w;
	curcontent.style.width = w.toString()+"px";
	curcontent.style.height = h.toString()+"px";
	for (var i=curno+1; i<nb_volet; i++) {
		var ct = mon_volet(i,"title");
		ct.style.left = (l+(volet_title_width*(i-(curno+1)))).toString()+"px";
	}
	if (w<volet_width) setTimeout (do_developpe, 20);
	else {
		var obj2 = document.getElementById("initial_cache");
		obj2.style.visibility = 'hidden';
		if (cur_volet!=-1) {
			var curc = mon_volet(curno,"content");
			curc.style.visibility = "hidden";
		}
		cur_volet = curno;
		scroll_in_progress = false;
		reset_timer();
	}
}

function volet_developpe() {
	scroll_in_progress = true;
	curcontent = mon_volet(curno,"content");
	curcontent.style.width = "0px";
	curcontent.style.height = "0px";
	curcontent.style.visibility = "visible";
	setTimeout (do_developpe, 20);
}

function repos_accordion() {
	if (timer!=null) clearTimeout(timer);
	var bandeau_pos1 = findPos(accordeon);
	incr_x = bandeau_pos1[0]-bandeau_pos[0];
	incr_y = bandeau_pos1[1]-bandeau_pos[1];
	for (var i=0; i<balisedivs.length; i++) {
		if (balisedivs[i].className=="title" || balisedivs[i].className=="content") {
			balisedivs[i].style.top = (parseInt(balisedivs[i].style.top)+incr_y).toString()+"px";
			balisedivs[i].style.left = (parseInt(balisedivs[i].style.left)+incr_x).toString()+"px";
		}
	}
	bandeau_pos[0] = bandeau_pos1[0];
	bandeau_pos[1] = bandeau_pos1[1];
	timer = setTimeout (volet_rotate, accordeon_delay_beetween*1000);
}

/*
function repos_accordion() {
	if (repostimer!=null) clearTimeout(repostimer);
	repostimer = setTimeout (dorepos_accordion, 500);
}
*/

window.onresize = repos_accordion;

scroll_in_progress = true;
curno = 0;
setTimeout (volet_developpe, accordeon_delay_before_first*1000);




