//-------------------------------------------------------------
//  Nom Document : mousezoom
//  Auteur       : kazma
//  Objet        : zoom a la sourie   http://www.javascriptfr.com/
//  Création     : 12.10.2008
//-------------------------------------------------------------
//  Mise à Jour  : 19.10.2008
//  Objet        : neant
//-------------------------------------------------------------
//-(*)------------------
var sscrotimer;
var couleur_de_fond="black";
var factalle
var opab=10;
var tour=1;
var _stop=0;
var dde=document.documentElement;
var imag = new Image();
var cc;
var lg_max=0;
var ht_max=0;
var ht_screen;
var fileLoadingImage = "lightbox/images/loading.gif";
var fileBottomNavCloseImage = "lightbox/images/close.gif";
var arrayPageSize;
var sans_fond;
var sans_fondu;
var sans_zoom;
var lg_border;
var cl_border;
var les_tailles;
var aff_encours;
var pos_taille='d';

if (dde.clientHeight != 0) dde_s = dde; else dde_s = document.body;
ht_screen = dde_s.clientHeight;

function Aff_Agrandir(LaLoupe, _Visible){
	if (!aff_encours) {
    	obj=document.getElementById(LaLoupe);
    	if (_Visible) {
        	obj.style.visibility="visible";
    	} else {
        	obj.style.visibility="hidden";
    	}
	}
}

function precharge(ii, larg, haut,ss_fond,ss_fondu,lg_bord,cl_bord,tailles,sanszoom) {
	aff_encours=true;
	if (!larg) larg=9999;
	if (!haut) haut=9999;
	if (!lg_bord) lg_bord=0;
	if (!ss_fond) ss_fond=false;
	if (!ss_fondu) ss_fondu=false;
	if (!tailles) les_tailles=''; else les_tailles=tailles;
	if (!sanszoom) sanszoom=false;
	hideSelectBoxes("select");
	hideSelectBoxes("embed");
	hideSelectBoxes("object");
	lg_max=larg;
	ht_max=haut;
	sans_fond=ss_fond;
	sans_fondu=ss_fondu;
	sans_zoom=sanszoom;
	lg_border=lg_bord;
	if (!cl_bord) cl_border='#bbbbbb'; else cl_border=cl_bord;
	_stop=0;
	tour=1;
	imag.src = ii;
	cc=ii;

	resize();
}

function quit2() {
	aff_encours=false;
	document.onkeydown = "";
	document.getElementById('divco').parentNode.removeChild(document.getElementById('divco'));
	document.getElementById('divim').parentNode.removeChild(document.getElementById('divim'));
	tail=document.getElementById('divt');	if (tail) tail.parentNode.removeChild(tail);
	ydic=document.getElementById('divimc');	if (ydic) ydic.parentNode.removeChild(ydic);
	showSelectBoxes("select");
	showSelectBoxes("embed");
	showSelectBoxes("object");
	tour=1;
	opab=10;
	_stop=1;
	window.clearTimeout(sscrotimer)
}

function sscro() {
	document.getElementById('divco').style.height =(ht_screen+(Math.max(dde.lastChild.scrollTop,dde.scrollTop)))+"px";
	sscrotimer=setTimeout("sscro()",20);
}

function tarto(s) {
	if(navigator.appName.substring(0,3)=="Net") {
		setY=s.clientY+dde.scrollTop;
	} else {
		setY=event.y+dde.scrollTop;
		return false;
	}
}

function disableselect(e) {
	return false;
}

function enableselecte(e){
	return true;
}

function mousezoom() {
	if (sans_zoom) quit2();
	if(tour==2) {
		document.onmousedown=enableselecte;
		return false;
	}
	if(tour==3) {
		py=setY;
		tour=1;
		adi=document.getElementById('divim');
		oper=(adi.offsetWidth-(2*lg_border))/(adi.offsetHeight-(2*lg_border));
	}
	if(adi.offsetWidth<=(30)) {
		adi.style.height='50px';
		adi.style.width=(factalle*50)+'px';
	}

	a_gauche=((dde_s.clientWidth-(adi.offsetWidth-(2*lg_border)))/2);
	lg_img=oper*((adi.offsetHeight-(2*lg_border))-(setY-py)*2);
	_top=((ht_screen-(adi.offsetHeight-(2*lg_border)))/2)+(Math.max(dde.lastChild.scrollTop,dde.scrollTop));
	adi.style.width=lg_img+'px';
	adi.style.height=((adi.offsetHeight-(2*lg_border))-(setY-py)*2)+'px';
	adi.style.left=a_gauche+'px';
	adi.style.top=_top+"px";

	adic=document.getElementById('divimc');
	adic.style.left=(a_gauche+lg_img-25+lg_border)+"px";
	adic.style.top=(_top+lg_border)+"px";

	adit=document.getElementById('divt');
	if (adit) {
		switch(pos_taille) {
			case 'h':
			adit.style.width=(lg_img+2*lg_border)+'px';
			adit.style.left=a_gauche+'px';
			adit.style.top=(_top-adit.offsetHeight-1)+"px";
			break;

			case 'b':
			adit.style.width=(lg_img+2*lg_border)+'px';
			adit.style.left=a_gauche+'px';
			adit.style.top=(_top+adi.offsetHeight+1)+"px";
			break;

			default:
			adit.style.left=(a_gauche+lg_img+2*lg_border+2)+"px";
			adit.style.top=_top+"px";
			break;
		}
	}

	dde.onmousedown=disableselect;
	py=setY;
	setTimeout("mousezoom()",15);
}
function resize() {
	if (_stop==1) {
		tour=2;
		return false;
	}
	if(tour==1) {
		dde.lastChild.appendChild(document.createElement('div')).setAttribute("id",'divco');
		ddco=document.getElementById('divco');

		ddco.style.position='absolute';
		ddco.style.top=0+"px";
		ddco.style.left=0+"px";
		ddco.style.width = 100+"%";
		ddco.style.zIndex = '90';

		ddco.style.backgroundColor=couleur_de_fond;

		if(document.all && !window.opera) {
			if (sans_fond==false) {
				ddco.style.filter = 'alpha(opacity=60)';
			} else {
				ddco.style.filter = 'alpha(opacity=0)';
			}
		} else {
			if (sans_fond==false) {
				ddco.style.opacity = 0.6;
			} else {
				ddco.style.opacity = 0.0;
			}
		}

		dde.lastChild.appendChild(document.createElement('img')).setAttribute("id",'divim');
		ydi=document.getElementById('divim');
		sscro();
		ydi.src=cc;
		ydi.style.zIndex = '99';

		ydi.style.border=lg_border+"px solid "+cl_border;
		ydi.style.position='absolute';
		if (!sans_zoom) ydi.style.cursor='s-resize';
		if (sans_fondu==false) {
			ydi.style.height=100+"px";
		} else {
			ydi.style.height=(6+ht_max)+"px";
		}

		factalle=lg_max/ht_max;
		tour=0;
	}
	ht_reel=(ydi.offsetHeight-(2*lg_border));
	_top=(ht_screen-ht_reel)/2+(Math.max(dde.lastChild.scrollTop,dde.scrollTop));
	lg_img=factalle*(ht_reel+20);
	if (ht_reel>20) ydi.style.height=(ht_reel+20)+"px";
	if (lg_img>0) ydi.style.width=lg_img+"px";
	a_gauche=(dde_s.clientWidth-(ydi.offsetWidth-(2*lg_border)))/2;
	ydi.style.left=a_gauche+"px";
	if (lg_max !=0 || ht_max != 0) {
		if ((((ydi.offsetHeight-(2*lg_border))>=lg_max) || ((ydi.offsetWidth-(2*lg_border))>=ht_max))) opab=100;
		else opab = (ydi.offsetHeight-(2*lg_border))*100 / ht_max;
	}
	opab = Math.min(opab, 100);
	if(document.all && !window.opera) {
		ydi.style.filter = 'alpha(opacity=' + opab + ')';
	} else {
		ydi.style.opacity = opab/100;
	}
	ydi.style.top=_top+"px";
	if((((ydi.offsetHeight-(2*lg_border))>=ht_max)||((ydi.offsetWidth-(2*lg_border))>=lg_max))) {
		if (les_tailles!='') {
			dde.lastChild.appendChild(document.createElement('div')).setAttribute("id",'divt');
			ydt=document.getElementById('divt');
			ydt.style.background='#ffffff';
			ydt.style.padding='10px';
			ydt.innerHTML='<center><p><font color="#333366"><span style="font-size:12px; font-weight:bold font-family: Arial, Helvetica, sans-serif;">'+les_tailles+'</span></font></p></center>';
			ydt.style.zIndex = '99';
			ydt.style.border=lg_border+"px solid "+cl_border;
			ydt.style.position='absolute';

			switch(pos_taille) {
				case 'h':
				ydt.style.width=(lg_img+2*lg_border)+'px';
				ydt.style.left=a_gauche+'px';
				ydt.style.top=(_top-ydt.offsetHeight-1)+"px";
				break;

				case 'b':
				ydt.style.width=(lg_img+2*lg_border)+'px';
				ydt.style.left=a_gauche+'px';
				ydt.style.top=(_top+ydi.offsetHeight+1)+"px";
				break;

				default:
				ydt.style.left=(a_gauche+lg_img+2*lg_border+2)+"px";
				ydt.style.top=_top+"px";
				break;
			}
		}
		if (!sans_zoom) {
			dde.lastChild.appendChild(document.createElement('img')).setAttribute("id",'divimc');
			ydic=document.getElementById('divimc');
			ydic.style.position='absolute';
			ydic.style.zIndex = '100';
			ydic.style.border='0px';
			ydic.setAttribute('src', fileBottomNavCloseImage);
			ydic.setAttribute('alt', "Touche Esc");
			ydic.onclick = function() { quit2(); return false; }
			ydic.style.cursor='pointer';
			ydic.style.left=(a_gauche+lg_img-25+lg_border)+"px";
			ydic.style.top=(_top+lg_border)+"px";
		}
		tour=2;
		if(navigator.appName.substring(0,5)=="Micro") {
			ddco.attachEvent("onclick",quit2);
			ydi.attachEvent('onmousedown', function() {tour=3;mousezoom()});
			ydi.attachEvent("onmousemove",tarto);
			ydi.attachEvent('onmouseup', function(){tour=2;});
		} else {
			ddco.setAttribute("onclick","quit2()");
			ydi.setAttribute("onmousedown","tour=3;mousezoom()");
			ydi.setAttribute("onmousemove","tarto(event)");
			ydi.setAttribute("onmouseup","tour=2");
		}
		document.onkeydown = function(e){
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			key = String.fromCharCode(keycode).toLowerCase();
			if((keycode==27) || (key == 'x') || (key == 'q') || (key == 's')) {
				quit2();
				return;
			}
		};

		return false;
	}
	setTimeout("resize()",15);
}

function showSelectBoxes(type){
	selects = document.getElementsByTagName(type);
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(type){
	selects = document.getElementsByTagName(type);
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
function display_3d() {
	_stop--;
	swf3d=document.getElementById('a3d');
	if (_stop<0)	{
		fait=swf3d.PercentLoaded();
		if (fait>90) _stop=0;
	}
	if (!_stop) {
		swf3d.style.display='block';
	} else {
		setTimeout("display_3d()",100);
	}
}
function charge_3d(ii, larg, haut,ss_fond,lg_bord,cl_bord) {
	imag.src = fileLoadingImage;
	aff_encours=true;
	if (!larg) larg=9999;
	if (!haut) haut=9999;
	if (!lg_bord) lg_bord=0;
	if (!ss_fond) ss_fond=false;

	hideSelectBoxes("select");
	hideSelectBoxes("embed");
	hideSelectBoxes("object");

	lg_max=larg;
	ht_max=haut;
	sans_fond=ss_fond;
	sans_fondu=true;
	sans_zoom=true;
	lg_border=lg_bord;
	if (!cl_bord) cl_border='#bbbbbb'; else cl_border=cl_bord;
	_stop=0;
	tour=1;
	cc=ii;
	swf_3d();
}
function quit_3d() {
	aff_encours=false;
	document.onkeydown = "";
	document.getElementById('divco').parentNode.removeChild(document.getElementById('divco'));
	ydic=document.getElementById('divimc');	if (ydic) ydic.parentNode.removeChild(ydic);
	swf3d=document.getElementById('div3d');  if (swf3d) swf3d.parentNode.removeChild(swf3d);

	showSelectBoxes("select");
	showSelectBoxes("embed");
	showSelectBoxes("object");
	tour=1;
	opab=10;
	_stop=1;
	window.clearTimeout(sscrotimer)
}
function swf_3d() {
	if (_stop==1) {
		tour=2;
		return false;
	}
	if(tour==1) {
		dde.lastChild.appendChild(document.createElement('div')).setAttribute("id",'divco');
		ddco=document.getElementById('divco');

		ddco.style.position='absolute';
		ddco.style.top=0+"px";
		ddco.style.left=0+"px";
		ddco.style.width = 100+"%";
		ddco.style.zIndex = '90';

		ddco.style.backgroundColor=couleur_de_fond;

		if(document.all && !window.opera) {
			if (sans_fond==false) {
				ddco.style.filter = 'alpha(opacity=60)';
			} else {
				ddco.style.filter = 'alpha(opacity=0)';
			}
		} else {
			if (sans_fond==false) {
				ddco.style.opacity = 0.6;
			} else {
				ddco.style.opacity = 0.0;
			}
		}
		sscro();

		factalle=lg_max/ht_max;
		tour=0;
	}
	dde.lastChild.appendChild(document.createElement('div')).setAttribute("id",'div3d');
	ydt=document.getElementById('div3d');
	ydt.style.background='#ffffff';
	ydt.style.padding='10px';
	tmp1='<table width="500" border="0" cellspacing="5" cellpadding="2"><tr><td width="100%" align="center" class="smallText" valign="top">Cliquez et passez la souris sur l\'image pour faire tourner l\'article</td></tr><tr>';
	tmp2='<td style="background-image:url(\''+fileLoadingImage+'\'); background-repeat:no-repeat; background-position:center center;" height='+ht_max+'>';
	tmp3a='<object id="a3d" style="display:none" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width='+lg_max+' height='+ht_max+' id="button" align="middle"><param name="allowScriptAccess" value="sameDomain" />';
	tmp3b='<param name="movie" value="'+cc+'" /><param name="quality" value="high" /><param name="wmode" value="window" /><param name="bgcolor" value="#ffffff" />';
	tmp3c='<embed src="'+cc+'" quality="high" bgcolor="#ffffff" width='+lg_max+' height='+ht_max+' name="button" align="middle" wmode="window" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	tmp4='</td></tr></table>';
	ydt.innerHTML=tmp1+tmp2+tmp3a+tmp3b+tmp3c+tmp4;
	ydt.style.zIndex = '99';
	ydt.style.border=lg_border+"px solid "+cl_border;
	ydt.style.position='absolute';

	ht_reel=(ydt.offsetHeight-(2*lg_border));
	_top=(ht_screen-ht_reel)/2+(Math.max(dde.lastChild.scrollTop,dde.scrollTop));
	a_gauche=(dde_s.clientWidth-(ydt.offsetWidth-(2*lg_border)))/2;
	ydt.style.left=a_gauche+"px";
	ydt.style.top=_top+"px";
	tour=2;
	if(navigator.appName.substring(0,5)=="Micro") {
		ddco.attachEvent("onclick",quit_3d);
	} else {
		ddco.setAttribute("onclick","quit_3d()");
	}
	dde.lastChild.appendChild(document.createElement('img')).setAttribute("id",'divimc');
	ydic=document.getElementById('divimc');
	ydic.style.position='absolute';
	ydic.style.zIndex = '100';
	ydic.style.border='0px';
	ydic.setAttribute('src', fileBottomNavCloseImage);
	ydic.setAttribute('alt', "Touche Esc");
	ydic.onclick = function() { quit_3d(); return false; }
	ydic.style.cursor='pointer';
	ydic.style.left=(a_gauche+ydt.offsetWidth-28)+"px";
	ydic.style.top=(_top+lg_border)+"px";
	document.onkeydown = function(e){
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		key = String.fromCharCode(keycode).toLowerCase();
		if((keycode==27) || (key == 'x') || (key == 'q') || (key == 's')) {
			quit_3d();
			return;
		}
	};

	if (navigator.appName.indexOf("Microsoft") != -1) _stop=-1; else _stop=5;
	display_3d();

	return false;
}

