// script_ensavoir.js: les diverses fonctions d'ouverture de fenêtres annexes En savoir +
//------------------------------------

//------------------------------------
// ouverture de la page Photos
/**function OpenPhotos(theURL) { 
	w=window.open(theURL,"Photos","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=400,height=430");
	MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
	VERS=parseInt(navigator.appVersion);
	if ((!MSIE) || (VERS >=5))
		w.focus();
}**/
//------------------------------------
// ouverture de la page Appel gratuit eStara
function OpenAppelgratuit(theURL) { 
	w=window.open(theURL,"Appel_gratuit","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=494,height=515");
	MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
	VERS=parseInt(navigator.appVersion);
	if ((!MSIE) || (VERS >=5))
		w.focus();
}
//------------------------------------
// ouverture de la page Info Consommateur
function OpenInfoconso(theURL) { 
	w=window.open(theURL,"Photos","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=300,height=260");//laisser à cette hauteur pour autorisation admin 
	MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
	VERS=parseInt(navigator.appVersion);
	if ((!MSIE) || (VERS >=5))
		w.focus();
}
//------------------------------------
// fermeture de la page Photos
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//------------------------------------
// ouverture de la page stats eStat
function OpeneStat() {
  var estatURL = "http://pagesjaunes.estat.com/";
  w=window.open( ( estatURL ), "eStat", "" );
}
//------------------------------------
// ouverture de la page stats eStara
function OpeneStara() {
  var estaraURL = "#";
  w=window.open( ( estaraURL ), "eStara", "" );
}
//------------------------------------
// ouverture de la page Info annonceur generique
function OpenInfoannonceur(url) {
	w=window.open(url,"Info","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=870,height=470");
	MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
	VERS=parseInt(navigator.appVersion);
	if ((!MSIE) || (VERS >=5))
		w.focus();
}
//------------------------------------
// ouverture de la page Info annonceur avocats
function OpenInfoavocat(url) {
	/*var estaraURL = "../avocat/info_annonceur.htm";*/
	w=window.open(url,"Info","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=870,height=470");
	MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
	VERS=parseInt(navigator.appVersion);
	if ((!MSIE) || (VERS >=5))
		w.focus();
}
//------------------------------------
// ouverture de la page Info editeur
function OpenInfoediteur() {
	var infoediteurURL = "http://www.pagesjaunes.fr/plusdeservices/infosite/mentionLegale.do";
	w=window.open( ( infoediteurURL ), "Info", "" );
}
//------------------------------------
// ouverture de la page Info editeur
function OpenInfoediteur() {
	var infoediteurURL = "static/html/info_editeur.html";
	w=window.open( ( infoediteurURL ), "Info", "" );
}
//------------------------------------
// Enregistrement dans favoris
function addFav() 
{ 
	if (document.all) 
	{ 
		window.external.AddFavorite(location.href, document.title); 
	} 
	else 
	{ 
		alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.') 
	} 
}
//------------------------------------
// Imprimer
function printWindow() {
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) 
		window.print()
}
//------------------------------------
// Itineraire
function pj_switch_menu (le_titre1, le_titre2) {
	document.getElementById(le_titre1);
	document.getElementById(le_titre2);
	var le_form1= document.getElementById("form_"+le_titre1);
	var le_form2= document.getElementById("form_"+le_titre2);
	le_form1.style.display='block';
	le_form2.style.display='none';
}
//------------------------------------
<!--
function MM_findObj(n, d) { //v4.0
	var p,i,x;  
	if(!d) 
		d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) 
		x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  	for (i=0; i<(args.length-2); i+=3) 
	{
		test=args[i+2]; 
		val=MM_findObj(args[i]);
    	if (val) 
		{
			nm=val.name; 
			if ((val=val.value)!="") 
			{
      			if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1))
						errors+='- '+nm+' doit contenir une adresse email.\n';
      			} else 
					if (test!='R') 
					{
	        			if (isNaN(val)) 
							errors+='- '+nm+' doit contenir un chiffre.\n';
	        			if (test.indexOf('inRange') != -1) 
						{ 
							p=test.indexOf(':');
	          				min=test.substring(8,p); 
							max=test.substring(p+1);
							if (val<min || max<val) 
								errors+='- '+nm+' doit contenir un chiffre entre '+min+' et '+max+'.\n';
						}
					} 
			} else 
				if (test.charAt(0) == 'R') 
					errors += '- '+nm+' est demand\xE9.\n'; 
		}
	}
	if (errors) 
		alert('l\'erreur suivante s\'est produite:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

//------------------------------------
// ouverture page CG eStat generique
function OpenCGEstatGen() {
	var conditiongenURL = "../html/estara_gen_conditions_generales.html";
	w=window.open( ( conditiongenURL ), "eStara", "scrollbars=yes,resizable=yes,width=700" );
}
//------------------------------------
// ouverture page Aide FAQ eStat generique
function OpenAideEstatGen() {
	var aidefaqURL = "../html/estara_gen_modemploi.html";
	w=window.open( ( aidefaqURL ), "eStara2", "scrollbars=yes,resizable=yes,width=700" );
}
//-------------------------------------
// redimentionnement de la police selon systeme
function scaleFont(){
	if (navigator.appVersion.indexOf("Win") != -1) { 
		document.body.style.fontSize='66%';
	} else {
		document.body.style.fontSize='70%';
	}
}
function initShowHide(){
	var obj = document.getElementsByTagName("span");
	for(i=1;i<obj.length;i++)
	{
		if(document.getElementById('showhide'+i)){      
		obj['showhide'+i].style.visibility = 'hidden';
		}
	}

}

function show(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'inline';
	}
	if (document.getElementById(id+'_bloc')) {
		document.getElementById(id+'_bloc').style.display = 'block';
	}

}

//-------------------------------------
// showHide horaires
function ShowHide(id) {
    var obj = document.getElementsByTagName("span");
    if (obj[id].style.visibility != 'visible')
	{
		obj[id].style.visibility = 'visible';
		obj[id].style.left = '0px';
		obj[id].style.zIndex = '100';
    } else {
    	obj[id].style.visibility = 'hidden';
    }
}


//-------------------------------------
function ShowContact(ref){
	var obj = document.getElementsByTagName("span");
	var visi;
	for (Val in contact[ref]){
		if (contact[ref][Val][0] <= curr_date)
		{
			visi='block';
			if (contact[ref][Val][1] < curr_date)
				visi='none';
		}
	}
	obj[ref].style.display=visi;
}

// main ________________________________
var the_date = new Date();
var the_month = the_date.getMonth() + 1;
if(the_month < 10)
	the_month = "0" + the_month;
var the_day = the_date.getDate();
if(the_day < 10)
	the_day = "0" + the_day;
var the_minutes = the_date.getMinutes();
if(the_minutes < 10)
	the_minutes = "0" + the_minutes;
var the_hours = the_date.getHours();
if(the_hours < 10)
	the_hours = "0" + the_hours;
var the_seconds = the_date.getSeconds();
if(the_seconds < 10)
	the_seconds = "0" + the_seconds;
var current_date = the_date.getFullYear() + "-" + the_month + "-" + the_day + "T" + the_hours + ":" + the_minutes + ":" + the_seconds;
var curr_date = the_date.getFullYear() + "/" + the_month + "/" + the_day;
var is_news_valid = 1;
var contact= new Array();




//-------------------------------------
// gestion hauteur IFRAME catalogue
var iframeids=["frCat"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() 
{
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById)
			resizeIframe(iframeids[i])
		//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block"
		}
	}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid)
	if (currentfr){
		currentfr.style.display="block"
		currentfr.width = '100%';
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else 
			if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
				currentfr.height = currentfr.Document.body.scrollHeight;
				
		if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false)
		else 
			if (currentfr.attachEvent){
				currentfr.detachEvent("onload", readjustIframe) // Bug fix line
				currentfr.attachEvent("onload", readjustIframe)
			}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
		resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
	if (document.getElementById)
		document.getElementById(iframeid).src=url
}

if (window.addEventListener) 
	window.addEventListener("load", initShowHide, false)
else if (window.attachEvent)
		window.attachEvent("onload", initShowHide)
	else
		window.onload=initShowHide;

if (window.addEventListener)
	window.addEventListener("load", resizeCaller, false)
else 
	if (window.attachEvent)
		window.attachEvent("onload", resizeCaller)
	else
		window.onload=resizeCaller

var debug=0;

//Ajouts de véronique - pour gestion des vignettes zoomées 
window.addEvent('domready',function(){
	var vignette = $('vignette');
//============= HERVE : attention ca plante, y compris le Ajax, si aucune image dans l esplus ===============
/*
	if ( vignette ) { var classe_vignette = vignette.getFirst();
	var vignettes = classe_vignette.getChildren();
	vignettes.each(function(vigne){
		var span = $(vigne).getLast();
		$(vigne).addEvent('mouseover',function(){
			//Patch pour IE6, la vignette passe sous le formulaire plan lors du rollover -_-
			if (window.ie && $('form_mail')){
				$('patch_cache1').setStyle('visibility','hidden');
				$('patch_cache2').setStyle('visibility','hidden');
			}
			t = this.getLast().getCoordinates();
			
			u = document.createElement('iframe');
			u.setStyles(
			{'width' : t['width'], 'height': t['height'], 'top': t['top'], 'left' : t['left']}
			);
			u.setStyle('position','absolute');
			u.setStyle('border','none');
			u.setStyle('z-index','2000');
			u.id = 'img_frame';
			u.frameborder='0';
			u.allowtransparency = false;
			u.inject(document.body);
		});
		$(vigne).addEvent('mouseout',function(){
			if (window.ie && $('form_mail')){
				$('patch_cache1').setStyle('visibility','visible');
				$('patch_cache2').setStyle('visibility','visible');
			}
			$('img_frame').remove();
		});
	});
}*/
//=========== fin commentaire HERVE			
	//-------------------------------------
	//Année en cours dans footer
	if ($('annee_actuelle')){ //Si le span avec identifiant "annee_actuelle" existe
		//le contenu de ce span est l'année en cours
		$('annee_actuelle').setText(the_date.getFullYear());
	}
});

//-------------------------------------
// showHide pour les MOG
function MogShowHide(id) {
    if ($(id).getStyle('display') != 'block'){
		// initialise l'effet
		var fx = $(id).effects({duration: 300, transition: Fx.Transitions.Quad.easeIn});
		$(id).setStyle('display', 'block');
		$(id).setStyle('opacity', 0);
		// récupère les balises p dans l'élément passé en paramètre
		var p		= $$('#'+id+' li');
		var height	= 0;
		// calcul la hauteur de toutes les balises p
		p.each(function(el,index){
			height	+=	el.getStyle('height').toInt() +
						el.getStyle('paddingTop').toInt() +
						el.getStyle('paddingBottom').toInt() +
						el.getStyle('marginTop').toInt() +
						el.getStyle('marginBottom').toInt();
		});
		// lance l'effet
		fx.start({
			'height': [$(id).getStyle('height').toInt(),height],
			'opacity': [$(id).getStyle('opacity').toInt(),1]
		// appel les statistiques
		}).chain(function(){
			// récupère la langue des paramètres d'URL
			var lang_form	= "FR";
			var t = location.search.substring(1).split('&');
			var f = [];
			for (var i=0; i<t.length; i++){
				var x = t[ i ].split('=');
				if(x[0]=="lang")
					lang_form = x[1].toUpperCase();
			}
			if(_PJS) _estatl(code_estat2,code_estat1,lang_form+'_INFO_CONSOMMATEUR',activite);
			if(iframe)
				iframe.location.href="http://pro.pagesjaunes.fr/uael/static/html/iframe.html?tag="+lang_form+'_INFO_CONSOMMATEUR'+"&amp;tagFinal="+activite;
		});
    } else {
		// initialise l'effet
		var fx = $(id).effects({duration: 100, transition: Fx.Transitions.linear});
		// lance l'effet
		fx.start({
			'height': [$(id).getStyle('height').toInt(),0],
			'opacity': [$(id).getStyle('opacity').toInt(),0]
		// rend l'élément "invisible" après que la hauteur soit à zéro (permet de faire le switch)
		}).chain(function() {
			$(id).setStyle('display', 'none');
		});
    }
}


/**************************************************************************************************************/
/******************************************************************************************LA FENETRE DE ZOOM */
/**************************************************************************************************************/
function deleteVideo(){
	// vire tous les bloc vidéo
	if($('bloc_video'))
		$('bloc_video').setStyle('visibility','hidden');
	// Safari et la vue à 360
	else if($('bloc_360')){
		var agt	= navigator.userAgent.toLowerCase();
		if(agt.indexOf("safari") != -1){
			$('bloc_360').setStyle('display','none');
			$('bloc_360').setStyle('height','0');
		}
	}else if($('show_flash_bloc')){
		$('show_flash_bloc').setStyle('display','none');
		$('show_flash_bloc').setStyle('height','0');
	}
}
function showVideo(){
	if($('bloc_video') && $('bloc_video').getStyle('visibility')!='visible')
		$('bloc_video').setStyle('visibility','visible');
	// Safari et la vue à 360
	else if($('bloc_360') && $('bloc_360').getStyle('display')=='none'){
		var agt	= navigator.userAgent.toLowerCase();
		if(agt.indexOf("safari") != -1){
			$('bloc_360').setStyle('display','inline');
			$('bloc_360').setStyle('height','360px');
		}
	}else if($('show_flash_bloc')){
		$('show_flash_bloc').setStyle('display','inline');
		$('show_flash_bloc').setStyle('height','250px');
	}
}
// fermer la fenêtre de zoom
function closeZoom(){
	var fx = $('zoom').effects({duration: 150, transition: Fx.Transitions.linear});
	fx.start({
		'opacity': [$('zoom').getStyle('opacity'),0]
	}).chain(function() {
		// affiche la vidéo gênante
		showVideo();
		// enlève le zoom
		$('zoom').setStyle('display','none');
	});
}
// ouvrir la fenêtre de zoom
function openZoom(x){
	// efface la vidéo gênante si nécessaire
	deleteVideo();
	// resize sur la largeur et la hauteur :: pour IE utiliser le sélecteur $E('body') au lieu de document.body
	$('zoom').setStyle('height', $E('body').getStyle('height').toInt()+$E('body').getStyle('marginTop').toInt()+$E('body').getStyle('marginBottom').toInt()+'px');
	$('zoom').setStyle('width', $E('body').getStyle('width').toInt());
	// repositionne en hauteur
	var top		= 94;
	/*if($('module'))
		top	+= $('module').getStyle('height').toInt();
	if($$('#main h2') && $$('#main h2').length>0)
		top	+= 38;*/
	$('zoomContent').setStyle('top',top+'px');
	new Asset.images(getBig(x), {
		onComplete:function(){
			if(isZoomOpen()){
				var fxZoomImage1 = $('zoomImage').effects({duration: 150, transition: Fx.Transitions.linear});
				fxZoomImage1.start({
					'opacity': [$('zoomImage').getStyle('opacity'),0]
				}).chain(function(){
					// change l'image
					$('zoomImage').src		= getBig(x);
					$('zoomImage').height	= imagesBigH[x];
					$('zoomImage').width	= imagesBigW[x];
					$('zoomImage').alt		= imagesAlt[x];
					$('zoomImage').title	= imagesAlt[x];
					var top					= $('zoomContent').getStyle('height').toInt()-$('liserai').getStyle('height').toInt();
					if($('miniNav').getStyle('display')!='none')
						$('liserai').setStyle('top',Math.round((top-$('miniNav').getStyle('height').toInt()-10)/2)+'px');
					else
						$('liserai').setStyle('top',Math.round(top/2)+'px');
					$('liserai').setStyle('left',($('zoomContent').getStyle('width').toInt()-$('liserai').getStyle('width').toInt())/2);
					var fxZoomImage2 = $('zoomImage').effects({duration: 250, transition: Fx.Transitions.linear});
					fxZoomImage2.start({
						'opacity': [$('zoomImage').getStyle('opacity'),1]
					}).chain(function(){
						changeBordure(x);
					});
				});
			}else{
				$$('#miniNav .galeryContent .images').setStyle('paddingTop',borderWidth_n+'px');
				$$('#miniNav .galeryContent .images').setStyle('paddingBottom',borderWidth_n+'px');
				// cale l'image à droite
				var k			= $$('.galery').length-1;
				while(k>=0){
					if($$('.galery')[k].getAttribute('id')=='miniNav'){
						$$('#miniNav .galeryContent .images').setStyle('left',seekLeftImage(i, k));
						break;
					}else
						k--;
				}
				var left	= seekLeftImage(x,k);
				$$('.images')[k].setStyle('left',left);
				// affiche/cache les flèches
				showHide(x, left, k);

				$('zoomImage').src		= getBig(x);
				$('zoomImage').height	= imagesBigH[x];
				$('zoomImage').width	= imagesBigW[x];
				$('zoomImage').alt		= imagesAlt[x];
				$('zoomImage').title	= imagesAlt[x];
				$('zoom').setStyle('display','block');
				$('zoom').setStyle('opacity',0);
				$('zoomImage').setStyle('opacity',1);
				var top					= $('zoomContent').getStyle('height').toInt()-$('liserai').getStyle('height').toInt();
				if($('miniNav').getStyle('display')!='none')
					$('liserai').setStyle('top',Math.round((top-$('miniNav').getStyle('height').toInt()-10)/2)+'px');
				else
					$('liserai').setStyle('top',Math.round(top/2)+'px');
				$('liserai').setStyle('left',($('zoomContent').getStyle('width').toInt()-$('liserai').getStyle('width').toInt())/2);
				var fx = $('zoom').effects({duration: 200, transition: Fx.Transitions.linear});
				fx.start({
					'opacity': [$('zoom').getStyle('opacity'),1]
				}).chain(function(){
					changeBordure(x);
				});
			}
		}
	});
}
// change la taille de la bordure des vignettes dans la fenêtre de zoom
function changeBordure(i){
	for(j=0;j<imagesTmb.length;j++){
		$('galery_zoom_'+j).setStyle('borderWidth',borderWidth_n+'px');
		$('galery_zoom_'+j).setStyle('marginRight',marginRight+'px');
		$('galery_zoom_'+j).setStyle('marginBottom','0');
		$('galery_zoom_'+j).setStyle('marginLeft','0');
		$('galery_zoom_'+j).setStyle('marginTop','0');
	}
	$('galery_zoom_'+i).setStyle('borderWidth',borderWidth_s+'px');
	$('galery_zoom_'+i).setStyle('marginRight',(marginRight-borderWidth_s/2)+'px');
	$('galery_zoom_'+i).setStyle('marginBottom',-(borderWidth_s/2)+'px');
	$('galery_zoom_'+i).setStyle('marginLeft',-(borderWidth_s/2)+'px');
	$('galery_zoom_'+i).setStyle('marginTop',-(borderWidth_s/2)+'px');

	// repositionne par rapport à la bordure
	/*var k			= $$('.galery').length-1;
	while(k>=0){
		if($$('.galery')[k].getAttribute('id')=='miniNav'){
			$$('#miniNav .galeryContent .images').setStyle('left',seekLeftImage(i, k));
			break;
		}else
			k--;
	}*/
}
// vérifi si la fenêtre de zoom est ouverte
function isZoomOpen(){
	if($('zoom').getStyle('display')=='block')
		return true;
	return false;				
}
// récupère l'image de la vignette à partir de son nom (pour le zoom)
function getBig(x){
	return imagesBig[x];
}
// aller directement à une image dans la galerie
function directGalery(x){
	numImgActu = x;
	for(i=$$('.galery').length-1;i>=0;i--){
		if($$('.galery')[i].getStyle('display')!='none')
			moveGalery(x, i);
	}
}
var fxGalery	= new Array();
function moveGalery(num, i){
	// récupère la position pour le déplacement de la galerie
	var	left		= seekLeftImage(num, i);
	// transition
	var diff		= Math.abs(Math.abs(left)-Math.abs($$('.images')[i].getStyle('left').toInt()));
	var time		= Math.round(diff)*7;
	var transition	= Fx.Transitions.Back.easeOut;
	// si le temps est court, on fait une transition linéaire
	if(time<300)
		transition	= Fx.Transitions.linear;
	// s'il y a déjà un effet on l'arrête
	if(fxGalery[i])
		fxGalery[i].stop();
	// on lance l'effet
	fxGalery[i]		= $$('.images')[i].effects({duration: time, transition: transition});
	fxGalery[i].start({
		'left': [$$('.images')[i].getStyle('left'),left+'px']
	}).chain(function(){
		// change la couleur de bordure pour le zoom
		if($$('.galery')[i].getAttribute('id')=='miniNav'){
			if(isZoomOpen()){
				if(num==numImgActu)
					changeBordure(numImgActu);
			}
		}
	});
	// affiche / cache les flèches
	showHide(num, left, i);
}

/*******************************************************************LES ACTIONS SUR LES FLECHES DE LA GALERIE */
// aller à l'image de droite dans la galerie
function rightGalery(){
	for(i=$$('.galery').length-1;i>=0;i--){
		if( (isZoomOpen() && $$('.galery')[i].getAttribute("id")=="miniNav") || (!isZoomOpen() && $$('.galery')[i].getAttribute("id")=="vignette")){
			if($$('.galery')[i].getStyle('display')!='none'){
				// recherche de la position courante et incrémentation
				var imgActu	= seekCurrentImage(i);
				// on est dans le header : incrémentation de plusieurs images
				var numImg		= 4;
				if(imgActu+numImg<imagesTmb.length-1){
					var pos1		= seekLeftImage(imgActu+numImg, i);
					var pos2		= seekLeftImage(imgActu, i);

					while( (pos2-pos1)<$$('.galeryContent')[i].getStyle('width').toInt() && (imgActu+numImg+1)<imagesTmb.length){
						numImg		++;
						pos1		= seekLeftImage(imgActu+numImg, i);
					}
					imgActu			+= numImg-1;
				}else
					imgActu	= imagesTmb.length-1;
				// vérifi la limite à gauche
				if(imgActu>(imagesTmb.length-1))
					imgActu	= imagesTmb.length-1;

				// mise à jour de la galerie
				moveGalery(imgActu, i);
			}
		}
	}
}
// aller à l'image de gauche dans les galeries
function leftGalery(){
	for(i=$$('.galery').length-1;i>=0;i--){
		if( (isZoomOpen() && $$('.galery')[i].getAttribute("id")=="miniNav") || (!isZoomOpen() && $$('.galery')[i].getAttribute("id")=="vignette")){
			if($$('.galery')[i].getStyle('display')!='none'){
				// recherche de la position courante et incrémentation
				var imgActu	= seekCurrentImage(i);
				// on est dans le header : décrémentation de plusieurs images
				var numImg		= -4;
				if(imgActu+numImg>0){
					var pos1		= seekLeftImage(imgActu, i);
					var pos2		= seekLeftImage(imgActu+numImg, i);

					while( (pos1-pos2)<$$('.galeryContent')[i].getStyle('width').toInt() && (imgActu+numImg-1)>0){
						numImg		--;
						pos2		= seekLeftImage(imgActu+numImg, i);
					}
					imgActu			+= numImg;
				}else
					imgActu	= 0;
				// vérifi la limite à droite
				if(imgActu<0)
					imgActu	= 0;

				// mise à jour de la galerie
				moveGalery(imgActu, i);
			}
		}
	}
}
/********************************************************************************AFFICHER/MASQUER LES FLECHES */
// aficher ou masquer les flèches
function showRight(i){
	if($$('.galeryArrowRight')[i].getStyle('visibility')!='visible')
		$$('.galeryArrowRight')[i].setStyle('visibility','visible');
}
function hideRight(i){
	if($$('.galeryArrowRight')[i].getStyle('visibility')!='hidden')
		$$('.galeryArrowRight')[i].setStyle('visibility','hidden');
}
function showLeft(i){
	if($$('.galeryArrowLeft')[i].getStyle('visibility')!='visible')
		$$('.galeryArrowLeft')[i].setStyle('visibility','visible');
}
function hideLeft(i){
	if($$('.galeryArrowLeft')[i].getStyle('visibility')!='hidden')
		$$('.galeryArrowLeft')[i].setStyle('visibility','hidden');
}
function showHide(num, left, i){
	if(num<=0)
		hideLeft(i);
	else
		showLeft(i);
	if(num>=imagesTmb.length-1 || Math.abs(left)>=Math.abs(totalWidth-$$('.galeryContent')[i].getStyle('width').toInt()))
		hideRight(i);
	else
		showRight(i);
}

/***************************************************************************PERMET DE RECHERCHER UNE POSITION */
// cherche la position en left pour aller à une image donnée
function seekLeftImage(x, i){
	var left	= 0;
	if(totalWidth>$$('.galery')[i].getStyle('width').toInt()){
		if(x>imagesTmb.length)
			x	= imagesTmb.length;
		// recherche de la position
		for(var j=0;j<x;j++){
			var ref	= $('galery_'+j);
			if($$('.galery')[i].getProperty('id')=='miniNav')
				ref	= $('galery_zoom_'+j);

			left	+= ref.getStyle('borderLeftWidth').toInt()+ref.getStyle('borderRightWidth').toInt()+imagesTmbW[j].toInt()+marginRight;
		}
		// limite à droite
		if(left>totalWidth-$$('.galeryContent')[i].getStyle('width').toInt())
			left	= totalWidth-$$('.galeryContent')[i].getStyle('width').toInt();
		// limite à gauche
		if(left<0)
			left	= 0;
	}
	return -left;
}
// recherche l'image actuelle
function seekCurrentImage(i){
	if($$('.galery').length>i && $$('.galery')[i].getStyle('display')!='none'){
		var left	= Math.abs($$('.images')[i].getStyle('left').toInt());
		var compte	= 0;
		var j		= 0;
		while(compte<left && j<imagesTmb.length-1){
			var ref	= $('galery_'+j);
			if($$('.galery')[i].getProperty('id')=='miniNav')
				ref	= $('galery_zoom_'+j);

			compte	+= ref.getStyle('borderLeftWidth').toInt()+ref.getStyle('borderRightWidth').toInt()+imagesTmbW[j].toInt()+marginRight;
			j++;
		}
		if(j>imagesTmb.length-1)
			j = imagesTmb.length-1;
		return j;
	}
	return 0;
}
window.addEvent('domready', function(){
	if(imagesTmb.length>0){
		new Asset.images(imagesTmb, {
			onProgress: function(i) {
				if($('progress') && $('progress').getStyle('display')=='block'){
					totalWidth			+= imagesTmbW[i].toInt()+marginRight+borderWidth_n*2;
					var percent			= ((i + 1) *$('progress').getStyle('width').toInt()) / imagesTmb.length;
					$('bar').setStyle('width', percent).setHTML(Math.round(percent/$('progress').getStyle('width').toInt()*100)+" %");
				}
			},
			onComplete:function() {
				if($('progress'))
					$('progress').setStyle('display', 'none');
				if($$('.images'))
					$$('.images').setStyle('width',totalWidth+'px');
				if($$('#miniNav .galeryContent .images'))
					$$('#miniNav .galeryContent .images').setStyle('width',(totalWidth+borderWidth_s*2)+'px');
				// cache les flèches de gauche
				for(i=0;i<$$('.galeryArrowLeft').length;i++)
					hideLeft(i);
				imagesTmb.each(function(image, i) {
					// insertion dans le bandeau de vignettes
					new Element(
						'img',
						{
							'id'		: "galery_"+i,
							'src'		: imagesTmb[i],
							'height'	: imagesTmbH[i],
							'width'		: imagesTmbW[i],
							'title'		: imagesAlt[i],
							'alt'		: imagesAlt[i],
							'styles'	: {
								'marginRight'	: marginRight+'px',
								'border'		: borderWidth_n+'px solid #b81e8e',
								'cursor'		: 'pointer'
							},
							'events': {
								'click': function(){
									// accès direct à une image de la galerie
									//directGalery(i);
									// ouverture de la fenêtre de zoom
									openZoom(i);
								}
							}
						}
					).inject($$('.images')[0],'bottom');
					// insertion dans le bandeau de zoom
					new Element(
						'img',
						{
							'id'		: "galery_zoom_"+i,
							'src'		: imagesTmb[i],
							'height'	: imagesTmbH[i],
							'width'		: imagesTmbW[i],
							'title'		: imagesAlt[i],
							'alt'		: imagesAlt[i],
							'styles'	: {
								'marginRight'	: marginRight+'px',
								'border'		: borderWidth_n+'px solid #b81e8e',
								'cursor'		: 'pointer'
							},
							'events': {
								'click': function(){
									// accès direct à une image de la galerie
									//directGalery(i);
									// ouverture de la fenêtre de zoom
									openZoom(i);
								}
							}
						}
					).inject($$('.images')[1],'bottom');
				});
				// positionnements initiaux
				for(i=$$('.galery').length-1;i>=0;i--){
					// si la largeur totale est supérieur à la largeur alouée à la galerie, on affiche la navigation par flèches !
					if(totalWidth>$$('.galery')[i].getStyle('width').toInt()){
						$$('.galeryArrowLeft')[i].setStyle('display','block');
						$$('.galeryArrowRight')[i].setStyle('display','block');
						$$('.galeryContent')[i].setStyle("width",$$('.galery')[i].getStyle('width').toInt()-$$('.galeryArrowLeft')[i].getStyle('width').toInt()-$$('.galeryArrowRight')[i].getStyle('width').toInt());
					// sinon, traitement des cas particuliers
					}else{
						$$('.galeryContent')[i].setStyle("width",$$('.galery')[i].getStyle('width').toInt());
						// si pas d'images, on affiche rien
						if(imagesTmb.length==0){
							$$('.galery')[i].setStyle('display','none');
						}else{
							// cas particulier pour la miniNav dans le paneau de zoom
							if($$('.galery')[i].getProperty('id')=='miniNav'){
								// si une image, on affiche pas
								if(imagesTmb.length==1){
									$$('.galery')[i].setStyle('left','-1000px');
									$$('.galery')[i].setStyle('display','none');
								}
								// on centre
								else
									$$('.galeryContent')[i].setStyle("left",Math.round(($$('.galery')[i].getStyle('width').toInt()-totalWidth)/2)+"px");
							}else
								$$('.galeryContent')[i].setStyle("left",($$('.galery')[i].getStyle('width').toInt()-totalWidth)+"px");
						}
					}
					// respécifie la hauteur du cadre en prenant en compte la largeur des images
					$$('.galery')[i].setStyle("height",$$('.galery')[i].getStyle('height').toInt()+borderWidth_n*2);
				}
			}
		});
	}
}); 