var lang=0;

function doit() {
    b=new backgr();
    thed=document.getElementById("d");
    somd=document.createElement("div");
    somd.id="somd";
    thed.appendChild(somd);
    setdiv(thed,b);
    paragrapheblanc(somd,560);
    interligne(somd,560);
    interligneblanc(somd,560);
    menu(somd);
    interligneblanc(somd,560);
    interligne(somd,560);
    paragrapheblanc(somd,560);
    paragraphe(somd,560);
    build();
    correctPNG();
}

function set_langage(l) {
    lang=l;
    somd=document.getElementById("somd");
    //    alert(somd+" "+somd.parent);
    somd.parentNode.removeChild(somd);
    doit();
}
	
	

function menu(thed) {
    var p=0;
    if (lang==0)   p=mprint("Anglais",thed,560,0,"<a href=\"#\" onClick=\"set_langage(1);return false;\">","</a>",false,0);
    else p=mprint("Français",thed,560,0,"<a href=\"#\" onClick=\"set_langage(0);return false;\">","</a>",false,0);
    if (lang==0)   p=mprint("Écrivez moi",thed,560,2,"<a href=\"mailto:filh@filh.org\">","</a>",false,0);
    else p=mprint("Mail me",thed,560,2,"<a href=\"mailto:filh@filh.org\">","</a>",false,0);
    if (lang==0)   p=mprint("Liens",thed,560,2,"<a href=\"liensN.htm\">","</a>",false,0);
    else p=mprint("Links",thed,560,2,"<a href=\"liensN.htm\">","</a>",false,0);
}


function unfold(chap) {
    b=new backgr();
    thed=document.getElementById("d");
    setdiv(thed,b);

    var chapdone=document.getElementById("d-"+chap);
    var unf=document.getElementById("s-"+chap);
    //    alert(typeof(unf)+unf);
    if (unf!=null) {
	chapdone.removeChild(unf);
	return;
    }
    var sl=sommaire.length;
    for(var i=0;i<sl;i+=5) 
	if (sommaire[i+lang]==chap) break;
    var thed=document.getElementById("d");

    var unfolding=document.createElement("div");
    unfolding.id="s-"+chap;
    chapdone.appendChild(unfolding);
    interligne(unfolding,560);
    for(;i<sl;i+=5) {
	if (sommaire[i+lang]!=chap) break;
	mprint(sommaire[i+3+lang],unfolding,560,40,"<a href=\""+sommaire[i+2]+"\" target=\"_blank\">","</a>",true,0);
	interligne(unfolding,560);
    }
    correctPNG();
}


function build() {
    var sl=sommaire.length;
    var curchap="";
    var thed=document.getElementById("somd");
    //    interligneblanc(thed,560);
    //    interligne(thed,560);
    //    paragraphe(thed,560);
    for(var i=0;i<sl;i+=5) {
	if (curchap==sommaire[i+lang]) continue;
	curchap=sommaire[i+lang]
	var adiv=document.createElement("div");
	adiv.id="d-"+curchap;
	thed.appendChild(adiv);
	mprint(curchap,adiv,560,0,"<a href=\"#\" onClick=\"unfold('"+curchap+"');return false;\">","</a>",true,0);
	paragraphe(thed,560);
	// interligne(thed,560);
	//interligneblanc(thed,560);
	//interligne(thed,560);
    }
}
	
	