/*
 * Thickbox V3.1 - One Box To Rule Them All.
 *
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * -----------------------------------------------------------------------------------
 * 
 * Mise en Plugin pour SPIP <www.spip.net> - PASCAL - 16/01/2009
 *
 * Traduction en langue Française des textes de liens.                   
 * Modification et ajout des balises TITLE et ALT manquantes.           
 * Ajout du bouton "Fermer".   
 * Ajout du bouton "Imprimer" avec gestion de l'impression de la page.    
 * Ajout du bouton "Activer loupe" et de sa fonction.                       
*/


	


/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/


/* Definition des variables GLOBALES du script */
var plugin_path = "plugins/thickbox3";

var tb_pathToImageLoading      = plugin_path + "/img_pack/loadingAnimation.gif";
var tb_pathToImageClose        = plugin_path + "/img_pack/close.gif";
var tb_pathToImageClose_over   = plugin_path + "/img_pack/close_over.gif";

var	site_title = document.title;     // Recupere le titre du site SPIP pour l'impression.
var loupe_status = 0;                // Status de lafonction loupe.

var browser = new Browser();
var edz_zooms = new Zooms();         // Liste des objets zoomables de la page */


//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
	imgLoader = new Image(); // preload image
	imgLoader.src = tb_pathToImageLoading;
  });


//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;			
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}


function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"'  alt='Chargement...' title='Chargement...' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
										
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#' title='Image suivante'> - Suivant &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#' title='Image precedente'>&lt; Précédent</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = " - Image " + (TB_Counter + 1) +" sur "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
						
			
			if (imageWidth > x) {	
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) {			
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) {			
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) {
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
		 
		 /* Bouton LOUPE */
		 loupe_status = 0;	
		 TB_loupe = "";
		 
		 /*	 
     TB_loupe = "<a href='#' alt='Activer loupe'  title='Activer loupe'  onclick='if( loupe_onoff() ) {this.innerHTML=\"<strong>[D&#233;sactiver loupe]</strong>\"; this.title=\"D&#233;sactiver loupe\" } else {this.innerHTML=\"<strong>[Activer loupe]</strong>\"; this.title=\"Activer loupe\"   }; return false;'  ><strong>[Activer loupe]</strong></a> &nbsp;&nbsp; ";
     */
		 
		 
		 /* Bouton IMPRIMER */
		 TB_imprimer = "<a href='#' alt='Imprimer'  title='Imprimer' onclick='imprime_image(\"TB_window\")'><strong>[Imprimer]</strong> </a> &nbsp;&nbsp; ";
		 
		 
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			
				$("#TB_window").append("<div id='TB_ImageOff'><div><img id='TB_Image' onmouseover=\"loupe_action(event, this);\" src='"+url+"' onLoad=\"edz_smallLoaded(this);\" width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+" - Cliquer ici pour fermer.' title='"+caption+" - Cliquer ici pour fermer.' /> <img  src='"+url+"' onLoad=\"edz_bigLoaded(this);\" style=\"display: none;\" /> </div> </div> <div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imprimer + TB_loupe + TB_imageCount + TB_PrevHTML + TB_NextHTML + " </div></div><div id='TB_closeWindow'><a href='#' onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('TB_closeWindowButton','','" + tb_pathToImageClose_over + "',1)\"   ><img src='" + tb_pathToImageClose + "' id='TB_closeWindowButton' alt='Fermer'  title='Fermer' /></a> </div>"); 
			
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
			}



			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			/*   $("#TB_ImageOff").click(tb_remove);    */
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}
		
		
		else{        //code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' alt='Fermer' title='Fermer'>Fermer</a> ou touche Esc</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>Fermer</a> ou touche Esc</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}  // Fin de la fonction tb_show()






//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}



/* __________________________________________________________________________ */
  
/* Fonction status de la loupe */	
function loupe_onoff() 
{
	loupe_status =((loupe_status)?(0):(1));
  return loupe_status;
}

/* Fonction action de la loupe */	
function loupe_action(event, obj) 
{
 if(loupe_status) {edz_zoomIn(event, obj);}
}





/* __________________________________________________________________________ */

/* Fonction imprime image en cours */	
function imprime_image(obj) 
{
// Définie la zone à imprimer
var zi = document.getElementById(obj).innerHTML;

// Definie header et footer.
var Headers = '<!DOCTYPE HTML PUBLIC ><HTML><HEAD><title>' + site_title + '</title><script type="text/javascript">\n <!-- \n function loupe_action(event, obj) { } \n //--> \n </script><link rel="stylesheet" href="plugins/thickbox3/thickbox.css" type="text/css" media="screen,print" /></HEAD><BODY onload="window.print();window.close()" >';
var Footers = "</body></html>";

// Ouvre une nouvelle fenetre
var f = window.open("", "Impression", "height=1, width=1,toolbar=0, menubar=0, scrollbars=0, resizable=0,status=0, location=0, left=0, top=0");

// Ajoute les Données
f.document.write ("" + Headers + zi + Footers);
f.document.close();
// Imprime et ferme la fenetre

return true;
}



/* __________________________________________________________________________ */

/** ZoomImg, V1.0
* Réalisé par Elforia Design
* http://www.elforia-design.fr
* infos@elforia-design.fr
* 15/02/2007
*
* Distribué sous licence GPL
*/

/**
* Retourne la position de la souris par rapport au bord haut gauche du navigateur et non de la page
*/
function edz_getMouseXY(evt) {
  var evt = evt?evt:window.event?window.event:null; if(!evt){ return null;}

  var pos = new Array();
  if (evt.pageX) {
    pos[0] = evt.pageX;
    pos[1] = evt.pageY;
  } else {
    pos[0] = evt.clientX + document.documentElement.scrollLeft;
    pos[1] = evt.clientY + document.documentElement.scrollTop;
  }

  return pos;
}
/**
* Le curseur a quittÃ© le zoom :
*   Soit c'est un dÃ©placement trÃ¨s rapide et le curseur est encore dans l'image, alors il faut appeler edz_zoomMove(evt)
*   Soit le curseur a quittÃ© l'image, alors il n'existe plus d'objet Zoom courant
*/
function edz_zoomOut(evt) {
  var pos = edz_getMouseXY(evt);
  if (pos==null) return;

  var zoom = edz_zooms.zoomCur();
  if (zoom.isIn(pos[0],pos[1])) edz_zoomMove(evt); // La souris est dedans
  else {
    edz_zooms.setZoomCur(null);
    zoom.getDivLoupe().style.display = 'none';
  }
}

/** 
* Souris est entrÃ©e dans un div :
*
*/

function edz_zoomIn(evt, div) { 
  var zoom = edz_zooms.getZoom(div);
  if (zoom==null) zoom = edz_zooms.addZoom(div);

  zoom._zooms.setZoomCur(zoom);

  zoom.findPos(); /* Retrouver la position du div Ã  chaque fois que l'on entre */
  var divLoupe = zoom.getDivLoupe();
  var imgLoupe = zoom.getImgLoupe();

  if (!zoom.ready()) {
    zoom._zooms.setLoupeLoading();
    imgLoupe.style.display = 'none';
  } else {
    zoom._zooms.setWidthLoupe( zoom._zooms.widthLoupeCopy() );
    zoom._zooms.setHeightLoupe( zoom._zooms.heightLoupeCopy() );
    imgLoupe.style.display = 'inline';
  }

  if (zoom.isBigLoaded()) imgLoupe.src = zoom.getBigImg().src;
  if (zoom.isSmallLoaded()) {
    imgLoupe.width = zoom.getSmallImg().width * zoom._zooms.factZoom();
    imgLoupe.height = zoom.getSmallImg().height * zoom._zooms.factZoom();
  }

  edz_zoomMove(evt);

  divLoupe.style.display = 'inline';
}

function edz_zoomMove(evt) {
  var zoom = edz_zooms.zoomCur();
  if (zoom==null) return;
  zoom.move(evt);
}
/**
* Une petite image est finie de charger. 
* CrÃ©er l'objet Zoom s'il n'existe pas et l'ajouter Ã  la liste
*/
function edz_smallLoaded(img) { 
  var div = edz_findDiv(img);
  if (div==null) return;

  var zoom = edz_zooms.getZoom(div);
  if (zoom==null) zoom = edz_zooms.addZoom(div);
  zoom.smallLoaded(img);

  if (edz_zooms.isCurZoom(zoom)) {
    zoom.getImgLoupe().width  = img.width  * zoom._zooms.factZoom();
    zoom.getImgLoupe().height = img.height * zoom._zooms.factZoom();
  }
}
/** 
* Une grande image est finie de charger 
* CrÃ©er l'objet Zoom s'il n'existe pas et l'ajouter Ã  la liste
*/
function edz_bigLoaded(img) { 
  var div = edz_findDiv(img);
  if (div==null) return;
  var zoom = edz_zooms.getZoom(div);
  if (zoom==null) zoom = edz_zooms.addZoom(div);
  zoom.bigLoaded(img);

  if (edz_zooms.isCurZoom(zoom)) {
    zoom.getDivLoupe().style.width  = zoom._zooms.widthLoupeCopy()+'px';
    zoom.getDivLoupe().style.height = zoom._zooms.heightLoupeCopy()+'px';
    zoom.getImgLoupe().src = img.src;
    zoom.getImgLoupe().style.display = 'inline';
  }
}
/**
* Retourne le premier node parent qui est un Ã©lÃ©ment div
*/
function edz_findDiv(img) {
  var node = img;
  while (node.parentNode && node.parentNode.nodeName!='DIV') { node = node.parentNode;}

  return node.parentNode;
}

/**
* Un objet Zoom
*/
function Zoom(zooms, div, divLoupe, imgLoupe) {
  this._zooms = zooms; /* L'objet Zooms */
  this._div = div; /* Le node du div */
  this._divLoupe = divLoupe; /* Le node div, conteneur de la loupe */
  this._imgLoupe = imgLoupe; /* Le node img inclu dans this._divLoupe */
  this._smallImg = null; /* Le node de la petite image */
  this._bigImg = null; /* Le node de la grande image */
  this._smallLoaded = false;
  this._bigLoaded = false;

  this._x = 0; /* Position du div par rapport au bord gauche du navigateur */
  this._y = 0; /* Position du div par rapport au bord haut du navigateur */

  this._lastMouseX = 0; /* DerniÃ¨re position de la souris. NÃ©cessaire lors de la modification du Zoom */
  this._lastMouseY = 0;

  this.getDiv = function() { return this._div; }
  this.getDivLoupe = function() { return this._divLoupe; }
  this.getImgLoupe = function() { return this._imgLoupe; }
  this.getSmallImg = function() { return this._smallImg; }
  this.getBigImg = function() { return this._bigImg; }
  this.smallLoaded = function(img) { this._smallImg = img; }
  this.isSmallLoaded = function() { if (this._smallImg!=null) return true; return false; }
  this.isBigLoaded = function() { if (this._bigImg!=null) return true; return false; }
  this.bigLoaded = function(img) { this._bigImg = img; }
  this.ready = function() { 
    if (this._smallImg!=null && this._bigImg!=null) return true;
    return false;
  }
  this.x = function() { return this._x; }
  this.y = function() { return this._y; }

  this.isIn = function(x, y) { 
    if (x<=this.x()) return false;
    if (y<=this.y()) return false;

    var smallImgWidth, smallImgHeight;
    if (this._smallImg==null) {
      smallImgWidth  = this._zooms.widthLoupe();
      smallImgHeight = this._zooms.heightLoupe();
    } else {
      smallImgWidth  = this._smallImg.width;
      smallImgHeight = this._smallImg.height;
    }

    if (x>=this.x()+smallImgWidth) return false;
    if (y>=this.y()+smallImgHeight) return false;

    return true;
  }

  this.findPos = function() {
    var obj = this._div;
    var curleft = curtop = 0;

    if (obj.offsetParent) {
      curleft = obj.offsetLeft;
      curtop = obj.offsetTop;
      while (obj = obj.offsetParent) {
        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;
      }
    }

    this._x = curleft;
    this._y = curtop;
  }

  this.move = function(evt) {

    var xx, yy;
    if (evt!=null) {
      var pos = edz_getMouseXY(evt);
      xx = pos[0];
      yy = pos[1];

      this._lastMouseX = xx;
      this._lastMouseY = yy;

    } else {
      xx = this._lastMouseX;
      yy = this._lastMouseY;
    }

    var smallImgWidth, smallImgHeight;
    if (this._smallImg==null) {
      smallImgWidth  = this._zooms.widthLoupe();
      smallImgHeight = this._zooms.heightLoupe();
    } else {
      smallImgWidth  = this._smallImg.width;
      smallImgHeight = this._smallImg.height;
    }

    var b = this._zooms.border()*2;

    if (xx-this.x()<this._zooms.widthLoupe()/2) leftDiv = this.x();
    else if (xx-this.x()>smallImgWidth-this._zooms.widthLoupe()/2-b) leftDiv = this.x() + smallImgWidth-this._zooms.widthLoupe() - b;
    else leftDiv = xx-this._zooms.widthLoupe()/2;
    leftDiv = Math.floor(leftDiv);

    if (yy-this.y()<this._zooms.heightLoupe()/2) topDiv = this.y();
    else if (yy-this.y()>smallImgHeight-this._zooms.heightLoupe()/2-b) topDiv = this.y() + smallImgHeight-this._zooms.heightLoupe()-b;
    else topDiv = yy-this._zooms.heightLoupe()/2;
    topDiv = Math.floor(topDiv);

    this._divLoupe.style.marginLeft = Math.floor(leftDiv)+'px';
    this._divLoupe.style.marginTop= Math.floor(topDiv)+'px';

    leftImg = -(xx-this.x())*this._zooms.factZoom() + this._zooms.widthLoupe()/2;
    if (leftImg>0) leftImg = 0;
    else if (-leftImg>=smallImgWidth*this._zooms.factZoom()-this._zooms.widthLoupe()-b) leftImg = -(smallImgWidth*this._zooms.factZoom()-this._zooms.widthLoupe()-b);

    topImg  = -(yy-this.y())*this._zooms.factZoom() + this._zooms.heightLoupe()/2 ;
    if (topImg>0) topImg = 0;
    else if (-topImg>=smallImgHeight*this._zooms.factZoom()-this._zooms.heightLoupe()-b) topImg = -(smallImgHeight*this._zooms.factZoom()-this._zooms.heightLoupe()-b);

    this._imgLoupe.style.marginLeft = Math.floor(leftImg)+'px';
    this._imgLoupe.style.marginTop = Math.floor(topImg)+'px';
  }
}

/**
* Liste des objets Zoom de la page
*/
function Zooms() {
  this._zooms = new Array();
  this._divLoupe = null; /* Le node div conteneur de la loupe */
  this._imgloupe = null; /* Le node img, image de la loupe */

  this._widthLoupeLoading = 130; /* Dimensions de la loupe en cours de chargement */
  this._heightLoupeLoading = 30;

  this._widthLoupe = 0; /* Dimensions rÃ©Ã©lles de la loupe (this._widthLoupeLoading ou this._curWidthLoupe) */
  this._heightLoupe = 0;

  this._copyWidthLoupe = 120; /* Sauvegarde des dimensions de la loupe, sachant qu'elle peut passer Ã  l'Ã©tat loading sans perdre ses dimensions */
  this._copyHeightLoupe = 80;

  this._minWidthLoupe = 50;
  this._maxWidthLoupe = 400;
  this._scaleDimsLoupe = 1.2;
  this._scaleFactLoupe = 1.2;

  this._factZoom = 5;

  this._border = 2; /* Nombre de pixels de bordure de l'image */
  this._borderColor = '#000';

  this._textLoading = "Zoom loading...";

  this._zoomCur = null; /* L'objet Zoom actif */

  this.getZoom = function(div) {
    for (var i=0;i<this._zooms.length;i++) if (div==this._zooms[i].getDiv()) return this._zooms[i];
    return null;
  }

  this.addZoom = function(div) {
    if (this._divLoupe==null) this.createDivLoupe();
    var zoom = new Zoom(this, div, this._divLoupe, this._imgLoupe);
    this._zooms.push(zoom);

    return zoom;
  }

  this.widthLoupe = function() { return this._widthLoupe; }
  this.heightLoupe = function() { return this._heightLoupe; }
  this.widthLoupeCopy = function() { return this._copyWidthLoupe; }
  this.heightLoupeCopy = function() { return this._copyHeightLoupe; }
  this.setLoupeLoading = function() { this.setWidthLoupe(this._widthLoupeLoading); this.setHeightLoupe(this._heightLoupeLoading); }
  this.factZoom = function() { return this._factZoom; }
  this.setWidthLoupe = function(width) { this._widthLoupe = width; if (this._divLoupe!=null) this._divLoupe.style.width = width+'px';}
  this.setHeightLoupe = function(height) { this._heightLoupe = height; if (this._divLoupe!=null) this._divLoupe.style.height = height+'px'; }
  this.border = function() { return this._border; }
  this.setZoomCur = function(zoom) { this._zoomCur = zoom; }
  this.zoomCur = function() { return this._zoomCur; }

  this.isCurZoom = function(zoom) { if (this._zoomCur==zoom) return true; return false; }

  this.createDivLoupe = function() {
    this._divLoupe = document.createElement('div');
    document.body.appendChild(this._divLoupe);

    this._divLoupe.appendChild( document.createTextNode(this._textLoading) );

    this._divLoupe.style.position = 'absolute';
    this._divLoupe.style.top = 0;
    this._divLoupe.style.display = 'none';
    this._divLoupe.style.width = this._widthLoupe + 'px';
    this._divLoupe.style.height = this._heightLoupe + 'px';
    this._divLoupe.style.overflow = 'hidden';
    this._divLoupe.style.backgroundColor = '#ffffe1';
    this._divLoupe.style.margin = '0';
    this._divLoupe.style.padding = '0';
    this._divLoupe.style.border = this._border + 'px solid ' + this._borderColor;
    this._divLoupe.onmousemove = function(e) { edz_zoomMove(e?e:event); };

    this._imgLoupe = document.createElement('img');
    this._imgLoupe.onmousemove = function(e) { edz_zoomMove(e?e:event); };
    this._imgLoupe.onmouseout = function(e) { edz_zoomOut(e?e:event); };

    this._imgLoupe.style.margin = '0';
    this._imgLoupe.style.padding = '0';
    this._imgLoupe.style.border = '0';
    this._imgLoupe.style.position = 'absolute';
    this._imgLoupe.style.top = 0;
    this._imgLoupe.style.left = 0;
    this._imgLoupe.style.display = 'none';

    this._divLoupe.appendChild(this._imgLoupe);

    if (browser.name()=='opera') document.onkeypress = edz_chgZoom;
    else if (document.all) document.onkeydown = edz_chgZoom; // IE
    else {
      document.onkeydown = edz_chgZoom;
      window.captureEvents(Event.KEYDOWN);
      window.onkeydown = edz_chgZoom;
    }
  }

  this.delZoomWidth = function() {
    if (this._zoomCur==null) return;
    var newWidth = this._widthLoupe/this._scaleDimsLoupe;
    if (newWidth<this._minWidthLoupe) return;

    this._copyWidthLoupe  = Math.floor(newWidth);
    this._copyHeightLoupe = Math.floor(this._heightLoupe/this._scaleDimsLoupe);

    this.setWidthLoupe(this._copyWidthLoupe);
    this.setHeightLoupe(this._copyHeightLoupe);
    this._zoomCur.move(null);
  }

  this.addZoomWidth = function() {
    if (this._zoomCur==null) return;
    var newWidth = this._widthLoupe*this._scaleDimsLoupe;
    if (newWidth>this._maxWidthLoupe) return;

    this._copyWidthLoupe  = Math.floor(newWidth);
    this._copyHeightLoupe = Math.floor(this._heightLoupe*this._scaleDimsLoupe);

    this.setWidthLoupe(this._copyWidthLoupe);
    this.setHeightLoupe(this._copyHeightLoupe);
    this._zoomCur.move(null);
  }

  this.delFactZoom = function() {
    if (this._zoomCur==null) return;
    this._factZoom /= this._scaleFactLoupe;
    this._imgLoupe.width = this._zoomCur.getSmallImg().width * this._factZoom;
    this._imgLoupe.height = this._zoomCur.getSmallImg().height * this._factZoom;    
    this._zoomCur.move(null);
  }

  this.addFactZoom = function() {
    if (this._zoomCur==null) return;
    this._factZoom *= this._scaleFactLoupe;
    this._imgLoupe.width = this._zoomCur.getSmallImg().width * this._factZoom;
    this._imgLoupe.height = this._zoomCur.getSmallImg().height * this._factZoom;    
    this._zoomCur.move(null);
  }

/**
* Configurations 
*/ 
  this.setFactZoom = function(fact) { this._factZoom = fact; }
  this.setDimsLoupeLoading = function(width, height) { this._widthLoupeLoading = width; this._heightLoupeLoading = height; }
  this.setInitialWidthLoupe = function(width, height) { this._copyWidthLoupe = width; this._copyHeightLoupe = height; }
  this.setMinMaxLoupe = function(min, max) { this._minWidthLoupe = min; this._maxWidthLoupe = max; }
  this.setSteps = function(width, zoom) { this._scaleDimsLoupe = width; this._scaleFactLoupe = zoom; }
  this.setBorder = function(widge, color) { this._border = widge; this._borderColor = color; }
  this.setTextLoading = function(text) { this._textLoading = text; }
}

function edz_chgZoom(evt) {
  var evt = evt?evt:window.event?window.event:null; if(!evt){ return true;}

  if (evt.keyCode==37 || evt.keyCode==100) { edz_zooms.delZoomWidth(); return false; } /* left */
  if (evt.keyCode==39 || evt.keyCode==102) { edz_zooms.addZoomWidth(); return false; } /* right */
  if (evt.keyCode==40 || evt.keyCode==98) { edz_zooms.delFactZoom(); return false; } /* down */
  if (evt.keyCode==38 || evt.keyCode==104) { edz_zooms.addFactZoom(); return false; } /* up */

  return true;
}

function Browser() {
  this._browser = navigator.appName;
  this._version = parseFloat(navigator.appVersion)

  this._name = "inconnu";
  if (this._browser=='Microsoft Internet Explorer') this._name = 'ie';
  else if (navigator.userAgent.toLowerCase().indexOf('opera')!=-1) this._name = 'opera';
  else this._name = 'mozilla';

  this.name = function() { return this._name; }
}



/**
* edz_zooms.setFactZoom(fact)                   : Facteur initial du zoom
* edz_zooms.setDimsLoupeLoading(width, height)  : Largeur et hauteur de la loupe 'En cours de chargement...'
* edz_zooms.setInitialWidthLoupe(width, height) : Largeur et hauteur initiales de la loupe (lorsque les images sont chargÃ©es)
* edz_zooms.setMinMaxLoupe(min, max)            : Largeur minimale et maximale que peut prendre la loupe modifiÃ©e par les flÃ¨ches
* edz_zooms.setSteps(width, zoom)               : Multiplicateurs de largeur et de facteur de zoom
* edz_zooms.setBorder(widge, color)             : bordure de la loupe en pixels et couleur
* edz_zooms.setTextLoading(text)                : texte Ã  afficher lorsque les images sont en cours de chargement
*/

