//



var xw = screen.width/2;
var xw_max=xw/2*3;
var yw = screen.height/2;

var nav=(document.all) ? false : true;
var posx=0;
var posy=0;
var dra_drag=true;//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;

if (nav) {document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove=position_souris;


var que_deplacer="commandes_";


function position_souris(e){
	posx=(nav)?e.pageX:window.event.x;
	posy=(nav)?e.pageY:window.event.y
	if (dra_drag) {return;}
	setTimeout("deplacer_()",50);
}

var s=0;
var u=0;
var v=0;
var r2=0
var posit_x=0;
var posit_y=0;

function deplacer_(){
	if (dra2_drag) {
	drag_w+=posx-drag_dw;drag_dw=posx;
	if (drag_w<200) {drag_w=200;}
	if (drag_w>xw_max) {drag_w=xw_max;}
	document.getElementById(que_deplacer).style.width=drag_w.toString()+"px";
	return;
	}

	document.getElementById(que_deplacer).style.left=(posx-drag_dx).toString()+"px";
	document.getElementById(que_deplacer).style.top=(posy-drag_dy).toString()+"px";
	return;
}
function prend_(o){
	que_deplacer=o;
	dra_drag=false;
	document.getElementById("sur_tout").style.left="0px";
	if (que_deplacer=="image_") {document.getElementById("reference_").style.visibility="visible";}
	i=document.getElementById(o).style.top;
	drag_dy=posy-parseInt(i);
	i=document.getElementById(o).style.left;
	drag_dx=posx-parseInt(i);
	drag_w=parseInt(document.getElementById(o).style.width);
	drag_dw=posx;
	return;
}
function lache_(){
	dra_drag=true;
	dra2_drag=false;
	document.getElementById("sur_tout").style.left="-5000px";
	if (que_deplacer=="reference_") {
		ref_x=parseInt(document.getElementById("reference_").style.left)+100;
		ref_y=parseInt(document.getElementById("reference_").style.top)+100;
		}
	if (que_deplacer=="image_") {document.getElementById("reference_").style.visibility="hidden";}
	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=document.getElementById("g_"+o).firstChild.nodeValue;
	mets_aide(p,"");
	return;
}
function mets_aide(o,r){
	hauteur_aide=(o+r).length/1.4+20;

	p=(largeur_doc>posx)? posx+20 : posx-180;
	q=(hauteur_doc-posy>hauteur_aide)? posy-10 : posy-hauteur_aide+(hauteur_doc-posy)/2; //hauteur_doc-hauteur_aide;

	document.getElementById("aide_").firstChild.nodeValue=o;//innerHTML=o;

	document.getElementById("aide_2").firstChild.nodeValue=r;
	document.getElementById("aide_").style.top=q.toString()+"px";
	document.getElementById("aide_").style.left=p.toString()+"px";
	return;
}
function enleve_aide(){
	document.getElementById("aide_").style.top="-1000px";
	document.getElementById("aide_").style.left="-1000px";
	return;
}

///bulle d'aide fixe
function aide_fixe(o){
	document.getElementById("les_remarques").firstChild.nodeValue = document.getElementById("e_"+o).firstChild.nodeValue;
	return;
}
function non_aide_fixe(o){
	document.getElementById("les_remarques").firstChild.nodeValue="";
	return;
}

var le_doc = new Array(100);
var le_doc_inverse = new Array(100);


////légendes coords, affichage, non affichage

aaa=coord_.split(";");
var nombre_legendes=aaa.length;

var xo = new Array(nombre_legendes);//
var yo = new Array(nombre_legendes);//vertical
var zo = new Array(nombre_legendes);//


	for (i=0; i<nombre_legendes; i++) {
	bbb=aaa[i].split(",");
	le_doc[i]=eval(bbb[0]);
	le_doc_inverse[bbb[0]]=i;

	xo[i]=eval(bbb[2])*coefx; yo[i]=eval(bbb[3])*coefy; zo[i]=eval(bbb[4])*coefz;
	}

var y=600*coefz;//350*coefz;
var d=Math.sqrt(2*y*y);
var e=1;
var f=1.2;

////stockage et traitement images
var pho = new Array(2);
for (i=0; i<=1; i++)
	{pho[i] = new Array(33);
		for (j=0; j<=32; j++) {pho[i][j] = new Image;}
	}
///rotation
var aaa= "";
//var rot_fixe=false;

function essai0(angle,ima){
	posit_y=parseInt(document.getElementById("image_").style.top);
	posit_x=parseInt(document.getElementById("image_").style.left);

	yp=ref_y-posit_y-256*zoom;
	xp=ref_x-posit_x-256*zoom;
	s=Math.sqrt(yp*yp+xp*xp);

if (((xp!=0) || (yp!=0))) {// && rot_fixe) {
	r=Math.atan(yp/xp);
	if(xp<=0) {r+=3.14159265359}

	r+=(angle-angle_memo)*0.39269908;

	document.getElementById("image_").style.top=(posit_y+yp-Math.floor(s*(Math.sin(r)))).toString()+"px";
	document.getElementById("image_").style.left=(posit_x+xp-Math.floor(s*(Math.cos(r)))).toString()+"px";
	}	

	image_memo=ima;
	angle_memo=angle;
	document.getElementById("curseur_").style.left=(38+angle*10).toString()+"px";
	angle=0.392695*angle;
	x=y*Math.sin(angle);
	z=y*Math.cos(angle);
	aaa="photos/"+l_photo+ima+".jpg";

	if (pho[0][ima].src.indexOf(aaa.src)!=-1) {document.im.src=pho[0][ima].src;}
	else {document.im.src=aaa; pho[0][ima].src=aaa;}

	document.zoom_im.src=pho[0][ima].src;

	for (i=0; i<nombre_legendes; i++) {
	denom=-x*xo[i]+y*yo[i]+z*zo[i]-d*y*Math.SQRT2;
	xim= (250+((Math.SQRT2)*d*(z*xo[i]+x*zo[i])/denom)*e)*zoom;
	yim= (260+(d*(x*xo[i]+y*yo[i]-z*zo[i])/denom)*f)*zoom;

	document.getElementById("b"+i).style.color="#33CC00";

	if (non_legende[le_doc[i]]!="") {if (non_legende[le_doc[i]].indexOf("_"+ima.toString()+"_")!=-1) {xim=-20;yim=0;document.getElementById("b"+i).color="#FF0000";}}
	if (oui_legende[le_doc[i]]!="") {if (oui_legende[le_doc[i]].indexOf("_"+ima.toString()+"_")==-1) {xim=-20;yim=0;document.getElementById("b"+i).color="#FF0000";}}

	if (xim<0 || xim>512*zoom || yim<0 || yim>512*zoom) {xim=-20;yim=0;document.getElementById("b"+i).style.color="#FF0000";}

	document.getElementById("a"+i).style.top=yim.toString()+"px";
	document.getElementById("a"+i).style.left=xim.toString()+"px";
	}
	return;
}
function rot_auto(o){
	i=(angle_memo+o+16)%16;
	essai0(i,(16-i)%16);
	return;
}
////bulles

function bulle_(o){
	aa="a"+o;
document.getElementById("le_zoom_cible").style.top=(parseInt(document.getElementById(aa).style.top)/zoom/4-8)+"px";
document.getElementById("le_zoom_cible").style.left=(parseInt(document.getElementById(aa).style.left)/zoom/4-8)+"px";
	o=le_doc[o];
	bb=document.getElementById("d_"+o).firstChild.nodeValue;
	if (bb=="0") {return;}
	cc=(document.getElementById("infos_"+o).firstChild.nodeValue=="0")?"11":"12";
	dd=document.getElementById("e_"+cc).firstChild.nodeValue;

	aide_fixe(cc);
	mets_aide(bb,dd);//innerHTML;
	document.getElementById(aa).style.backgroundColor="rgb(255,0,0)";
	return;
}
function nonbulle_(o){
	non_aide_fixe();
	enleve_aide();
document.getElementById("le_zoom_cible").style.top="0px";
document.getElementById("le_zoom_cible").style.left="0px";
	document.getElementById("a"+o).style.backgroundColor="rgb(255,255,255)";
	return;
}

///info
var info_mis=-1;
function clic_(o){
	if (document.getElementById("infos_"+le_doc[o]).firstChild.nodeValue=="0") {return;}
	if (document.getElementById("infos_"+le_doc[o]).firstChild.nodeValue=="1") {eval(document.getElementById("action_"+o).firstChild.nodeValue);return;}
	if (info_mis==o) {info_mis=-1;met_info(-1);return;}
	info_mis=o;
	met_info(le_doc[o]);
	return;
}
var info_mem=0;
function met_info(o){
	if (o==-1) {info_mis=-1;document.getElementById("infos_").style.top="-3000px";return;}

//	if (document.getElementById("infos_"+o).firstChild.nodeValue=="0") {return;}
//	if(document.getElementById("infos_"+o).firstChild.nodeValue=="1")
//{eval(document.getElementById("action_"+o).firstChild.nodeValue);return;}


	document.getElementById("infos_"+info_mem).style.top="-3000px";
	info_mem=o.toString();
	document.getElementById("infos_"+info_mem).style.top="0px";

	if (document.getElementById("infos_").style.top!="-3000px") {return;}
	document.getElementById("infos_").style.top="0px";
	return;
}

function legendes_(){
	p=(document.getElementById("legendes").style.visibility=="visible") ? "hidden" : "visible"
	document.getElementById("legendes").style.visibility=p;
	return;
}

function voir_reference(){
	p=(document.getElementById("reference_").style.visibility=="visible") ? "hidden" : "visible"
	document.getElementById("reference_").style.visibility=p;
	return;
}

////saut image
function saut_(){
	i=document.getElementById("index_").style.top;
	i=ref_y-(posy-4-parseInt(i))*zoom*4;
	document.getElementById("image_").style.top=i.toString()+"px";
	i=document.getElementById("index_").style.left;
	i=ref_x-(posx-4-parseInt(i))*zoom*4;
	document.getElementById("image_").style.left=i.toString()+"px";
	//rot_fixe=true; document.getElementById("le_c_du_zoom").style.visibility="visible";
	return;
}
////zoom image
function zoom_(o){
	if ((zoom>=4 && o==1) || (zoom<=0.5 && o==-1)) {return;}
	i=(ref_y-parseInt(document.getElementById("image_").style.top))/zoom;
	p=(ref_x-parseInt(document.getElementById("image_").style.left))/zoom;

	zoom=Math.ceil((zoom+0.5*o)*100)/100;

	i=i*zoom;
	p=p*zoom;
	document.getElementById("image_").style.top=(ref_y-i).toString()+"px";
	document.getElementById("image_").style.left=(ref_x-p).toString()+"px";
	zoom_2();
	return;
}
function zoom_2(){
	p=(512*zoom).toString()+"px";
	document.getElementById("im").style.width=p;
	document.getElementById("sur_im").style.width=p;
	document.getElementById("image_").style.width=p;
	document.getElementById("im").style.height=p;
	document.getElementById("sur_im").style.height=p;
	document.getElementById("image_").style.height=p;
	essai0(angle_memo,image_memo);
	return;
}
/////////
function re_centrer(){
	//rot_fixe=false;
	document.getElementById("le_c_du_zoom").style.visibility="hidden";
	return;
	document.getElementById("image_").style.left=(ref_x-256*zoom).toString()+"px";
	document.getElementById("image_").style.top=(ref_y-256*zoom).toString()+"px";
	return;
}



function pointe_(xx,yy,zz,tt){
	mets_aide(document.getElementById("e_"+tt).firstChild.nodeValue,"");
	angle=0.392695*angle_memo;
	x=y*Math.sin(angle);
	z=y*Math.cos(angle);
	xx=xx*coefx
	yy=yy*coefy
	zz=zz*coefz
	denom=-x*xx+y*yy+z*zz-d*y*Math.SQRT2;
	xim=(250+((Math.SQRT2)*d*(z*xx+x*zz)/denom)*e)*zoom;
	yim=(260+(d*(x*xx+y*yy-z*zz)/denom)*f)*zoom;
	document.getElementById("pointeur_").style.top=yim.toString()+"px";
	document.getElementById("pointeur_").style.left=xim.toString()+"px";
	document.getElementById("le_zoom_cible").style.top=(yim/zoom/4-8).toString()+"px";
	document.getElementById("le_zoom_cible").style.left=(xim/zoom/4-8).toString()+"px";
	return;
}
function pointe_fin(){
	enleve_aide();
	document.getElementById("pointeur_").style.top="0px";
	document.getElementById("pointeur_").style.left="-20px";
	document.getElementById("le_zoom_cible").style.top="0px";
	document.getElementById("le_zoom_cible").style.left="0px";
	return;
}

function charge_legendes_reperes(o){
	for (i=0; i<=o; i++) {document.write("<div id='a"+i+"' class='legendes_' onClick='clic_("+i+");' onMouseOver='bulle_("+i+");' onMouseOut='nonbulle_("+i+");'>"+i+"</div>");
	}
	return;
}
function charge_legendes(){
	p=arguments.length;
	r=1;
	q=arguments[1];
	for (i=0; i<=arguments[0]; i++) {
		document.write("<span id='b"+i+"'>"+i+"</span>- <a id='f_"+i+"' href='fr15-002_fr.htm' onClick='clic_("+i+");return false;' onMouseOver='bulle_("+i+");' onMouseOut='nonbulle_("+i+");'>a</a>");
	if (i==q) {document.write("<hr>");r++;q=arguments[r];}
		else {document.write("<br>");}
	}
	return;
}

function tra_charge(o){
	aa=o+"?"+tra_deri;
aa+=id_tra_deri+","+zoom+","+image_memo+","+angle_memo+","+parseInt(document.getElementById("image_").style.top)+","+parseInt(document.getElementById("image_").style.left)+","+parseInt(document.getElementById("index_").style.left)+","+parseInt(document.getElementById("infos_").style.left)+","+parseInt(document.getElementById("infos_").style.width)+","+parseInt(document.getElementById("commandes_").style.top)+","+parseInt(document.getElementById("commandes_").style.left)+","+parseInt(document.getElementById("reference_").style.top)+","+parseInt(document.getElementById("reference_").style.left);


	document.location.href=aa;
	return false;
}

function depart(){

	aaa=l_photo;
	//pho.src=l_photo;
	//document.zoom_im.src=pho.src;
	//document.im.src=pho.src;

	document.getElementById("image_").style.left=(ref_x-256*zoom).toString()+"px";
	document.getElementById("image_").style.top=(ref_y-256*zoom).toString()+"px";

	document.getElementById("reference_").style.left=(ref_x-100).toString()+"px";
	document.getElementById("reference_").style.top=(ref_y-100).toString()+"px";

	//légendes noms,
	aaa=document.getElementById("data_0").firstChild.nodeValue.split(";");
	nombre_legendes=aaa.length;
	for (i=0; i<nombre_legendes; i++) {
	bbb=aaa[i].split(",");

	document.getElementById("f_"+le_doc_inverse[eval(bbb[0])]).firstChild.nodeValue=bbb[1];
	}


	//divers
	aaa=document.getElementById("data_1").firstChild.nodeValue.split(";");
	for (i=0; i<=aaa.length-1; i++) {
	document.getElementById("gene_"+i).firstChild.nodeValue=aaa[i];
	}


	//tra_deri
	tra_deri_action(id_tra_deri);
	if (tra_deri_pour_ici!="") {
		bb=tra_deri_pour_ici.split(",");
		if (bb.length==13) {
		zoom=eval(bb[1]);
		image_memo=eval(bb[2]);
		angle_memo=eval(bb[3]);
		document.getElementById("image_").style.top=bb[4]+"px";
		document.getElementById("image_").style.left=bb[5]+"px";
		document.getElementById("index_").style.left=bb[6]+"px";
		document.getElementById("infos_").style.left=bb[7]+"px";
		document.getElementById("infos_").style.width=bb[8]+"px";
		document.getElementById("commandes_").style.top=bb[9]+"px";
		document.getElementById("commandes_").style.left=bb[10]+"px";
		document.getElementById("reference_").style.top=bb[11]+"px";
		document.getElementById("reference_").style.left=bb[12]+"px";
		ref_y=eval(bb[11])+100;
		ref_x=eval(bb[12])+100;
		}}


	zoom_2();
	return;
}