

lesSources=new Array();

//initialisation
i=0;





var bauto = 1;
var dossier="../photos/photos";
var numero = 1;
var nom;
var comm;

function tableau() { 
    this.length = lesSources.length;
    for(j=0;j<lesSources.length;j++){
	this[j+1]=lesSources[j].substr(46,4);
	//this[j+1]=lesSources[j].substr(35,4);
    }
}

function diaporama(){//alert(lesSources.length);
 
    nom=new tableau();	
    MaDiv=document.getElementById("reservoir");
    MaDiv.style.visibility="visible";  
    MaDiv.style.backgroundColor="black";   

    if (window.innerHeight) {
	    pos = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
	    pos = document.documentElement.scrollTop;
	} else if (document.body) {
	    pos = document.body.scrollTop;
	}

    MaDiv.style.top=(pos + 5)+"px";
    MaDiv.style.left="150px";
    changer();
}

function objet(codepho) { 
    var code=codepho.split(',');
    this.length = code.length;
    for(j=0;j<code.length;j++){
	this[j+1]=code[j];
    }
}



function lancerdiapo(codepho,commentaires){
    nom=new objet(codepho);
    comm=new objet(commentaires);
    for(j=1;j<comm.length+1;j++){
	//comm[j]=comm[j].replace(/_/," ");	
	comm[j]=comm[j].replace(/_/," "+j+"/"+comm.length+" ");
	}
    bauto = 1;
    numero = 0;
    document.automat.src="../images/pause.gif";
    document.automat.title="Pause";
    MaDiv=document.getElementById("reservoir");
    MaDiv.style.visibility="visible";  
    MaDiv.style.backgroundColor="black";
    document.image.src = "../images/black.jpg";
    texte=document.createTextNode("");
    zonetexte=document.getElementById("textdiapo");
    while (zonetexte.hasChildNodes()){
    zonetexte.removeChild(zonetexte.firstChild);
    }
    zonetexte.appendChild(texte);
    if (window.innerHeight) {
	    pos = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
	    pos = document.documentElement.scrollTop;
	} else if (document.body) {
	    pos = document.body.scrollTop;
	}

    MaDiv.style.top=(pos + 5)+"px";
    MaDiv.style.left="150px";
    changer();
    //document.image.src = dossier+nom[numero]+"_web.jpg";
 }

function arret() {
bauto =0; initial();
MaDiv=document.getElementById("reservoir");
MaDiv.style.visibility="hidden";
}

function suivante() {
numero += 1;
if (numero == nom.length + 1) numero = 1;
document.image.src = dossier+nom[numero]+"_web.jpg";
texte=document.createTextNode(comm[numero]);
zonetexte=document.getElementById("textdiapo");
zonetexte.removeChild(zonetexte.firstChild);
zonetexte.appendChild(texte);
}

function precedente() {
numero -= 1;
if (numero == 0) numero = nom.length;
document.image.src = dossier+nom[numero]+"_web.jpg";
texte=document.createTextNode(comm[numero]);
zonetexte=document.getElementById("textdiapo");
zonetexte.removeChild(zonetexte.firstChild);
zonetexte.appendChild(texte);
}

function changer() {
numero += 1;
if (numero == nom.length + 1) numero = 1;
document.image.src = dossier+nom[numero]+"_web.jpg";
texte=document.createTextNode(comm[numero]);
zonetexte=document.getElementById("textdiapo");
zonetexte.removeChild(zonetexte.firstChild);
zonetexte.appendChild(texte);
roll=setTimeout("changer()", 4000);
}

function initial() {
window.clearTimeout(roll);
document.image.src = dossier+nom[numero]+"_web.jpg";
texte=document.createTextNode(comm[numero]);
zonetexte=document.getElementById("textdiapo");
zonetexte.removeChild(zonetexte.firstChild);
zonetexte.appendChild(texte);
}

function auto() {
if (bauto == 0) {
	bauto =1; changer();
	document.automat.src="../images/pause.gif";
	document.automat.title="Pause";
	}
else {
	bauto =0; initial();
	document.automat.src="../images/play.gif";
	document.automat.title="Play";
	}
}



function form(lesSources){
    if((lesSources.length==0)||(lesSources.length==1)){
	div=document.getElementById("formu");
	div.style.display = "block";
	div.style.visibility = "visible";
	h2=document.createElement("h2");
	h2.setAttribute("id","rouge");
	div.appendChild(h2);
        erreur=document.createTextNode("Veuillez selectionner au moins 2 photos pour faire un diaporama");
        h2.appendChild(erreur);
    }
    else{
	div=document.getElementById("formu");
	div.style.display = "block";
	form=document.createElement("form");
	form.setAttribute("method","post");
	form.setAttribute("action","../gestion/index.php?a=recorddiapo");
	div.appendChild(form);

	chpSaisie=document.createElement("div");
	chpSaisie.setAttribute("class","chpSaisie");
	form.appendChild(chpSaisie);
	labelt=document.createElement("label");
	labelt.setAttribute("id","champ");
	chpSaisie.appendChild(labelt);
	texte=document.createTextNode("Lieu");
	labelt.appendChild(texte);
	titre=document.createElement("input");
	titre.setAttribute("type","text");
	titre.setAttribute("name","lieu");
	titre.setAttribute("value","");
	chpSaisie.appendChild(titre);
	br=document.createElement("br");
	form.appendChild(br);

/*ajout du select pour acces */
	chpSaisie=document.createElement("div");
	chpSaisie.setAttribute("class","chpSaisie");
	form.appendChild(chpSaisie);
	labelt=document.createElement("label");
	labelt.setAttribute("id","champ");
	chpSaisie.appendChild(labelt);
	texte=document.createTextNode("Acces");
	labelt.appendChild(texte);

	titre=document.createElement("select");
	titre.setAttribute("name","acces");
	o1=document.createElement('option');
        o1.text='public';
        titre.add(o1,null); // standards compliant
	o2=document.createElement('option');
        o2.text='abonne';
        titre.add(o2,null); // standards compliant

	chpSaisie.appendChild(titre);
	br=document.createElement("br");
	form.appendChild(br);

/*fin select*/

	chpSaisie1=document.createElement("div");
	chpSaisie1.setAttribute("class","chpSaisie");
	form.appendChild(chpSaisie1);
	label1=document.createElement("label");
	label1.setAttribute("id","champ");
	chpSaisie1.appendChild(label1);
	texte=document.createTextNode("Date");
	label1.appendChild(texte);
	titre1=document.createElement("input");
	titre1.setAttribute("type","text");
	titre1.setAttribute("name","dated");
	titre1.setAttribute("value","");
	chpSaisie1.appendChild(titre1);
	br=document.createElement("br");
	form.appendChild(br);

	chpSaisie2=document.createElement("div");
	chpSaisie2.setAttribute("class","chpSaisie");
	form.appendChild(chpSaisie2);
	labels=document.createElement("label");
	labels.setAttribute("id","champ");
	chpSaisie2.appendChild(labels);
	texte=document.createTextNode("Commentaires");
	labels.appendChild(texte);
	sujet=document.createElement("textarea");;
	sujet.setAttribute("cols","30");
	sujet.setAttribute("rows","5");
	sujet.setAttribute("name","commentaires");
	sujet.setAttribute("value","");
	chpSaisie2.appendChild(sujet);
	br=document.createElement("br");form.appendChild(br);
	br=document.createElement("br");form.appendChild(br);
	br=document.createElement("br");form.appendChild(br);
	br=document.createElement("br");form.appendChild(br);
	br=document.createElement("br");form.appendChild(br);

	for(i=0;i<(lesSources.length);i++){
	    var re=/[A-Z0-9]{4}/;
	    code=re.exec(lesSources[i]);
	    cache=document.createElement("input");
	    cache.setAttribute("type","hidden");
	    cache.setAttribute("name","diapos[]");
	    cache.setAttribute("value",code);
	    chpSaisie.appendChild(cache);
	}
	chpSaisie3=document.createElement("div");
	chpSaisie3.setAttribute("class","chpSaisie");
	form.appendChild(chpSaisie3);
	chpSaisie4=document.createElement("div");
	chpSaisie4.setAttribute("class","input");
	chpSaisie3.appendChild(chpSaisie4);
	submit=document.createElement("input");
	submit.setAttribute("type","submit");
	submit.setAttribute("name","");
	submit.setAttribute("value","Enregistrer");
	chpSaisie4.appendChild(submit);

    }
}
    


function my_DropFunc () {
    if ((dd.obj.x < 950) && (dd.obj.x > 600)){
	lesSources.push(dd.obj.src);
    }else{
	dd.obj.moveTo(dd.obj.defx,dd.obj.defy);
        for(j=0;j<lesSources.length;j++) {
	    if (lesSources[j]==dd.obj.src) {
		lesSources.splice(j,1);
            }
        }
    }
}


 function go(source, x, y){
	fenetre = window.open(source, "caen", "resizable=yes, screenX=0, screenY=0, width=150px ,height=180px, top=50px, left=400px, scrollbars=yes");
  fenetre.resizeTo(x, y);
  fenetre.focus();

}
