﻿/*
pour diaporama et équivalents 2010
*/

var xw = screen.width*2/3;
var yw = screen.height/2;
var xw_max=xw/2*3;

var nav=(document.all) ? false : true;
var pos_x=0;
var pos_y=0;
var dra_drag=false;//déplacer
//var dra2_drag=false;//dimensionner
var drag_dx=0;
var drag_dy=0;
var drag_w=0;
var drag_dw=0;
var drag_d=0;
var posit_x=0;
var posit_y=0;

var attente_= new Image;
attente_.src= "../s3_attente.gif";


////dom
function $(o){return document.getElementById(o)}

function met_deplace(o,p,q){
	document.getElementById(o).style.left=p;
	document.getElementById(o).style.top=q;
	return;
}
function met_dim(o,p,q){
	document.getElementById(o).style.width=p;
	document.getElementById(o).style.height=q;
	return;
}
function pour_deplacex(o,p){
	if (p=="quoi_") {return parseInt(document.getElementById(o).style.left);}
	document.getElementById(o).style.left=p;
	return;
}
function pour_deplacey(o,p){
	if (p=="quoi_") {return parseInt(document.getElementById(o).style.top);}
	document.getElementById(o).style.top=p;
	return;
}
function pour_visibility(o,p){
	if (p=="quoi_") {return document.getElementById(o).style.visibility;}
	document.getElementById(o).style.visibility=p;
	return;
}
function pour_display(o,p){
	if (p=="quoi_") {return document.getElementById(o).style.display;}
	document.getElementById(o).style.display=p;
	return;
}
function pour_fontsize(o,p){
	if (p=="quoi_") {return parseInt(document.getElementById(o).style.fontSize);}
	document.getElementById(o).style.fontSize=p;
	return;
}
function pour_width(o,p){
	if (p=="quoi_") {return parseInt(document.getElementById(o).style.width);}
	document.getElementById(o).style.width=p;
	return;
}
function pour_height(o,p){
	if (p=="quoi_") {return parseInt(document.getElementById(o).style.height);}
	document.getElementById(o).style.height=p;
	return;
}
function pour_first(o,p){
	if (p=="quoi_") {return document.getElementById(o).firstChild.nodeValue;}
	document.getElementById(o).firstChild.nodeValue=p;
	return;
}
function pour_attribute(o,p,q){
	if (q=="quoi_") {return document.getElementById(o).getAttribute(p);}
	document.getElementById(o).setAttribute(p,q);
	return;
}
function pour_bgc(o,p){
	if (p=="quoi_") {return document.getElementById(o).style.backgroundColor;}
	document.getElementById(o).style.backgroundColor=p;
	return;
}
function pour_couleur(o,p){
	if (p=="quoi_") {return document.getElementById(o).style.color;}
	document.getElementById(o).style.color=p;
	return;
}
function pour_scroll_t(o,p,q){
	if (p=="quoi_") {return document.getElementById(o).scrollTop;}
	document.getElementById(o).scrollTop=p;
	return;
}

/////


if (nav) {document.addEventListener('mousemove', position_souris, true);}

document.onmousemove=position_souris;

var que_deplacer="commandes_";


function position_souris(e){
	pos_x=(nav)?e.pageX:window.event.x
	pos_y=(nav)?e.pageY:window.event.y
	deplacer_();
}
////// déplacements

function deplacer_(){
	if(dra_drag){
		met_deplace(que_deplacer,(pos_x-drag_dx)+'px',(pos_y-drag_dy)+'px');
		return;	
	}
	return;
}

function prend_pad(o){//pour pad_
	if (!pad_) {return;}

	if (window.prend_local) {o=prend_local(o);}//dans local
	if (o=="prend_rien") {return;}

	dra_drag=!dra_drag;

	que_deplacer = o;

	if (dra_drag){
		drag_dx = pos_x - parseInt($(o).style.left);
		drag_dy = pos_y - parseInt($(o).style.top);
	}
return;
}
function prend_(o){
	if (pad_){return;}

	if (window.prend_local) {o=prend_local(o);}//dans local
	if (o=="prend_rien") {return;}

	dra_drag=!dra_drag;

	que_deplacer = o;
	if (dra_drag){
		drag_dx = pos_x - parseInt($(o).style.left);
		drag_dy = pos_y - parseInt($(o).style.top);
	}
	return;
}


function lache_(){
	dra_drag=false;
	return;
}




///bulle d'aide mobile
///bulle d'aide
var largeur_doc=screen.width/2;
var hauteur_doc=screen.height-150;
var hauteur_aide=0;
function mets_pre_aide(o,p){
	o=$("g_"+o).firstChild.nodeValue;
	p=(p==1)?pour_bulle[12]:pour_bulle[11];//"e_12":"e_11";
	mets_aide(o,p);
	return;
}

function mets_aide(o,r){
	hauteur_aide=(o+r).length/1.4+20;

	p=(largeur_doc>pos_x)? pos_x+20 : pos_x-180;
	q=(hauteur_doc-pos_y>hauteur_aide)? pos_y-10 : pos_y-hauteur_aide+(hauteur_doc-pos_y)/2;

	$("aide_").firstChild.nodeValue=o;

	$("aide_2").firstChild.nodeValue=r;
	$("aide_").style.visibility="visible";
	$("aide_").style.top=q.toString()+"px";
	$("aide_").style.left=p.toString()+"px";
	return;
}
function enleve_aide(){
	$("aide_").style.visibility="hidden";
	return;
}


/////bulle d'aide fixe
function aide_fixe(o){
	$("les_remarques").firstChild.nodeValue = pour_bulle[o];
	$("les_remarques").style.visibility = "visible";
	return;
}
function non_aide_fixe(o){
	$("les_remarques").style.visibility = "hidden";
	return;
}

////variables

var nom_ = new Array(200);//nom des légendes
var ou_ = new Array(200);//lieu image
var action_ = new Array(200);//action clic
var over_ = new Array(200);//action over
var out_ = new Array(200);//action out
//var inv_= new Array(100);//inverse de id
var le_doc_inverse = new Array(200);//no rang correspondant à la légende
var le_doc = new Array(200);//no correspondant au rang de la légende
var id_ = new Array(200);//identifiant

var init_x_image=640;//position image
//var pad_=false;//pour petits écrans

////bulles
var bulle_clic="";
var ici_=1;//no légende en over
function bulle_(){
	o=ici_;
	i=nom_[o]+". ";
	j=pour_bulle[12];
	aide_fixe(12);

	if (over_[o]=="") {mets_aide(i,j);return;}
	i+=$("d_"+over_[o]).firstChild.nodeValue;
	mets_aide(i,j);
	return;
}

function nonbulle_(){
	non_aide_fixe();
	enleve_aide();
	return;
}

function bulle2_(o){
	i=$("g_"+o).firstChild.nodeValue;
	j=pour_bulle[11];
	mets_aide(i,j);
	return;
}

///over
function le_over(o){
return;
}

/////historique dans la page

var nombre_legendes=0;//en tout. Légendes + autres
var nb_legendes=0;

var mem_histo=[0];

function histo_(){
	if (mem_histo.length<=2) {return;}
	mem_histo.pop();
	ici_=mem_histo[mem_histo.length-1];
	$("id_"+ici_).selected="selected";
	mem_histo.pop();
	clic_();
	return;
}
function plus_(){
	var j=(1+nombre_legendes+eval(ici_))%nombre_legendes;
	if (id_[j]=="hr") {
		j=(j+1)%nombre_legendes;
	}
	$("id_"+j).selected="selected";
	ici_=j;
	clic_();
	return;
}

///clic


var ici_clic=0;//pour modifier doc
var ici_ou=0;//pour modifier photo
var return_pas=false;//retour imposé par local

function clic_(){

	dra_drag=false;
	var q=document.forms.form_1.select_1.value;
	if (q=="hr") {return;}
	ici_=q;

	ici_clic=action_[ici_];
	if (window.clic_local) {
		clic_local();
	}

	if (return_pas) {
		return_pas=false;
		return;
	}

	met_info();
	return;

return;
}

var info_mem=0;//pour info
var info_mem2=0;//pour index inutile?

function met_info(){

	window.scrollTo(0,0);

	if (info_mem==ici_clic) {return;}

	mem_histo.push(ici_);
	pour_visibility("infos_"+info_mem,"hidden");
	info_mem=action_[ici_];

	if (pour_display("infos_"+info_mem,"quoi_")!="block"){
		pour_display("infos_"+info_mem,"block");
	}
	pour_visibility("infos_"+info_mem,"visible");
	charge_les_images();
return;
}

///////charge les images
function affiche_image(o){//de droite
	pour_attribute("im","src",attente_.src);

	if (o.indexOf("/")==-1){
		o="photos/"+o;
	}
	pour_attribute("im","src",o);

	if (!nav) {
		pour_deplacey("image_",document.documentElement.scrollTop);
	}
	else {
		pour_deplacey("image_",window.pageYOffset+"px");
	}
	pour_deplacex("image_",init_x_image.toString()+"px")
return;
}

function charge_image(o){//image de droite
	pour_attribute("im","src",attente_.src);

	pour_attribute("im","src",o);
return;
}
function charge_les_images(){//images d'info
	affiche_image(ou_[ici_]);

	for (var i=0; i<10; i++){
		var j="i"+action_[ici_]+"_"+i;
		if (window.document.getElementById(j)) {
			pour_attribute(j,"src","photos/"+pour_attribute(j,"alt","quoi_"));
		}
	}

return;
}

////recherche par identifiant
function id_quoi(o){
	for (var i=0; i<nombre_legendes; i++) {
		if (id_[i]==o) {return i;break}
	}
	return -1
}

///charge légendes dans index, info_0 et commandes

function charge_legendes(){

	nombre_legendes=coord_.length;
	document.write("<div id='index_' class='index2_'><div id='bandeau_' class='href_' onClick='charge_index();' onMouseOver='aide_fixe(1);' onMouseOut='non_aide_fixe();'><img src='../s3_ae.gif' alt='Autoedition CIMA'>Autoédition CIMA</div><div id='gene_0'>LM</div><hr><form name='form_1'><select name='select_1' size="+nombre_legendes+" onChange='clic_();'>");

	//j=-1;
	for (var i=0; i<nombre_legendes; i++) {

		bbb=coord_[i].split("<");
		if (bbb[1]=="hr"){
			id_[i]="hr";
			document.write("<option value='hr'>--</option>");continue;
		}
		//k=eval(bbb[0]);
		id_[i]=bbb[0];
		nom_[i]=bbb[1];
		ou_[i]=bbb[2];
		action_[i]=bbb[4];
		over_[i]=bbb[3];
		out_[i]=bbb[5];
		//j++;
		document.write("<option value="+i+" id='id_"+i+"'>"+bbb[1]+"</option>");
		//le_doc_inverse[k]=j;
		//le_doc[j]=k;
	}
	delete coord_;

	document.write("</select></form><hr><div id='gene_1'>LM2</div></div>");

	document.write("<div id='image_'><img id='im' name='im' onMouseDown='prend_(\"image_\");' onMouseOver='aide_fixe(0);' onMouseOut='non_aide_fixe();' onClick='prend_pad(\"image_\");' src='../s3_ae.gif' alt=''>");

	if (window.nombre_images) {//local
		for (i=0; i<nombre_images; i++) {
			document.write("<img id='im_"+i+"' name='im_"+i+"' class='zero_' src='../s3_ae.gif'  onMouseDown='prend_(this.id);' onMouseOver='le_over(this.id);' onClick='prend_pad(this.id);' alt=''>");
		}
	}

	if (window.nombre_textes) {//local
		for (i=0; i<nombre_textes; i++) {
			document.write("<div id='it_"+i+"' class='zero_' onMouseDown='prend_(this.id);'  onClick='prend_pad(this.id);'>.</div>");
		}
	}

	if (window.loupe_) {//local
		document.write("<div id='la_loupe' class='zero_' style='clip:rect(0px 50px 50px 0px)' onMouseDown='prend_(this.id);' onClick='prend_(this.id);'><img id='img_la_loupe' name='img_la_loupe' class='zero_' src='../s3_ae.gif'></div>");
	}

	document.write("</div><div id='aide_'>a<br><span id='aide_2'>b</span></div>");


	document.write("<div id='infos_0' class='cadre_infos'>");
		menu_();
	document.write("</div>");


document.write("<div id='commandes_' class='commandes2_'><img src='../s4_maison.gif' onClick='charge_plan();return false;' onMouseOver='aide_fixe(3);' onMouseOut='non_aide_fixe();' alt=''><img src='../s4_espace.gif' alt=''><img id='histo_moins' src='../s4_histomoins.gif' onClick='histo_();' onMouseOver='aide_fixe(15);' onMouseOut='non_aide_fixe();' alt=''><img src='../s4_espace.gif' alt=''><img id='histo_plus' src='../s4_histoplus.gif' onClick='plus_();' onMouseOver='aide_fixe(16);' onMouseOut='non_aide_fixe();' alt=''><div id='les_remarques'>....</div></div>");


	return;
}

////fin charge légendes



function tra_charge(o){
	aa=o+"?"+tra_deri;
	document.location.href=aa;
	return;
}

function depart(){

	if (langue_ici!="fr") {
		var DSLScript  = document.createElement("script");
		DSLScript.src  = "../s3_diaporama"+langue_ici+".js";
		DSLScript.type = "text/javascript";
		document.body.appendChild(DSLScript);
	}

	if (window.depart_local) {depart_local();}//local

	if (pad_) {
		init_x_image=380;
	}

	//légendes noms, n°

	var aaa=pour_first("data_0","quoi_").split(";");
	for (i=0; i<aaa.length; i=i+2) {
		var j=id_quoi("g_"+parseInt(aaa[i]));
		if (j!=-1) {
			nom_[j]=aaa[i+1];
			pour_first("id_"+j,aaa[i+1]);
		}
	}

	//divers
	aaa=$("data_1").firstChild.nodeValue.split(";");
	for (var i=0; i<=aaa.length-1; i++) {
	$("gene_"+i).firstChild.nodeValue=aaa[i];
	}

	//tra_deri
	tra_deri_action(id_tra_deri);

	info_mem=0;
	$("id_"+info_mem).selected="selected";
	clic_();

	return;
}
