//



var xw = screen.width/2;
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;

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) {drag_w=xw;}
	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";
	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";
	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_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;
}
/*
function pre_aide(o){
	mets_aide(document.getElementById("e_"+o).firstChild.nodeValue);
	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;
}
/*
cible,100,-65,60;
lampe,100,-65,410, x0,5
camera,0,100,285,410;1,234,258,410;2,347.5,182.5,410;3,423,69,410;4,450,-65,410;5,423,-199,410;6,347.5,-312.5,410;7,234,-388,410;8,100,-415,410;9,-34,-388,410;10,-147.5,-312.5,410;11,-223,-199,410;12,-250,-65,410;13,-223,69,410;14,-147.5,182.5,410;15,-34,258,410
*/

////variables
var coefx=1.7;
var coefy=1.7;
var coefz=1.7;
var zoom=1;
var image_memo=8;
var angle_memo=8;

////légendes coords, affichage, non affichage

var aaa=""
aaa="0,- Casemate,-80,20,112;1,- Entrée casemate,-20,20,115;2,- Barrière antichars,0,0,-100;3,- Local barrière,40,30,-80;4,- Entrée local barrière,110,20,0;5,- Caserne extérieure,70,40,50;6,- Cuisine extérieure,120,60,120;7,- Tranchée,-20,10,95;8,- Douanes,10,50,30;9,- Police,40,50,-35;10,- Gendarmerie,-19,30,-135;11,- Souvenirs,-70,15,-70;12,- Wc,-155,30,115;13,- Pont,80,0,-200;14,- Plaque,-25,0,-83;15,- Triangle,80,60,-145".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-1; i++) {
	bbb=aaa[i].split(","); xo[bbb[0]]=eval(bbb[2])*coefx; yo[bbb[0]]=eval(bbb[3])*coefy; zo[bbb[0]]=eval(bbb[4])*coefz;
	}

var non_legende = new Array(nombre_legendes);
var oui_legende = new Array(nombre_legendes);

for (i=0; i<=nombre_legendes; i++) {non_legende[i]="";oui_legende[i]="";}

non_legende[15]="_0_1_7_6_";
non_legende[13]="_0_1_";
non_legende[4]="_8_";
non_legende[0]="_1_2_";
non_legende[12]="_3_";


var y=350*coefz;//350*coefz;
var d=Math.sqrt(2*y*y);
var e=1;
var f=1;

////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=yw-posit_y-256*zoom;
	xp=xw-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=(40+angle*10).toString()+"px";
	angle=0.392695*angle;
	x=y*Math.sin(angle);
	z=y*Math.cos(angle);
	aaa="photos/lo_ext_"+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-1; i++) {
	denom=-x*xo[i]+y*yo[i]+z*zo[i]-d*y*Math.SQRT2;
	xim= (256+((Math.SQRT2)*d*(z*xo[i]+x*zo[i])/denom)*e)*zoom-10;
	yim= (256+(d*(x*xo[i]+y*yo[i]-z*zo[i])/denom)*f)*zoom-10;

	document.getElementById("b"+i).style.color="#33CC00";

	if (non_legende[i]!="") {if (non_legende[i].indexOf("_"+ima.toString()+"_")!=-1) {xim=-20;yim=0;document.getElementById("b"+i).color="#FF0000";}}
	if (oui_legende[i]!="") {if (oui_legende[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,p){
	bulle_clic=p;
	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";

bb=document.getElementById("d_"+o).firstChild.nodeValue;

cc=(document.getElementById("infos_"+p).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
function clic_(){
	o=bulle_clic;
	met_info(o);
	//if (o==18) {tra_charge("bichel16-002_fr.htm");}
	//if (o==15) {tra_charge("bichel14-002_fr.htm");}
	return;
}
var info_mem=0;
var info_mem_y="0px";
function met_info(o){
	if (o==-1) {info_mem_y=document.getElementById("infos_").style.top;
		document.getElementById("infos_").style.top="-3000px";
		return;
		}
	if (o!=50) {if (document.getElementById("infos_"+o).firstChild.nodeValue=="0") {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=info_mem_y;
	return;
}


function legendes_(){
	p=(document.getElementById("legendes").style.visibility=="visible") ? "hidden" : "visible"
	document.getElementById("legendes").style.visibility=p;
	return
}

////saut image
function saut_(){
	i=document.getElementById("le_zoom").style.top;
	i=yw-(posy-parseInt(i))*zoom*4;
	document.getElementById("image_").style.top=i.toString()+"px";
	i=document.getElementById("le_zoom").style.left;
	i=xw-(posx-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>=2 && o==1) || (zoom<=0.85 && o==-1)) {return;}
	i=(yw-parseInt(document.getElementById("image_").style.top))/zoom;
	p=(xw-parseInt(document.getElementById("image_").style.left))/zoom;

	zoom=Math.ceil((zoom+0.25*o)*100)/100;

	i=i*zoom;
	p=p*zoom;
	document.getElementById("image_").style.top=(yw-i).toString()+"px";
	document.getElementById("image_").style.left=(xw-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=(xw-256*zoom).toString()+"px";
	document.getElementById("image_").style.top=(yw-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 tra_charge(o){
	aa=o+"?"+tra_deri;
	if (tra_deri_dra && id_tra_deri=="_lo_") {aa+="_lo_,"+zoom+","+image_memo+","+angle_memo+","+parseInt(document.getElementById("image_").style.top)+","+parseInt(document.getElementById("image_").style.left)+","+parseInt(document.getElementById("infos_").style.left)+","+parseInt(document.getElementById("infos_").style.width)+","+parseInt(document.getElementById("index_").style.left)+","+parseInt(document.getElementById("commandes_").style.top)+","+parseInt(document.getElementById("commandes_").style.left)+";";}
	document.location.href=aa;
	return;
}


function depart(){

	document.getElementById("image_").style.left=(xw-256*zoom).toString()+"px";
	document.getElementById("image_").style.top=(yw-256*zoom).toString()+"px";


	//légendes noms, n°
	aaa=document.getElementById("data_0").firstChild.nodeValue.split(";");
	for (i=0; i<=aaa.length-1; i++) {
	bbb=aaa[i].split(","); aa=eval(bbb[0]);
	document.getElementById("f_"+aa).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];
	}


	if (tra_deri_pour_ici!="") {
		bb=tra_deri_pour_ici.split(",");
		if (bb.length==11) {
		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("infos_").style.left=bb[6]+"px";
		document.getElementById("infos_").style.width=bb[7]+"px";
		document.getElementById("index_").style.left=bb[8]+"px";
		document.getElementById("commandes_").style.top=bb[9]+"px";
		document.getElementById("commandes_").style.left=bb[10]+"px";
		}}


	zoom_2();
	return;
}
