﻿/************
*  FA PE
*****************/
var IS_IE = document.all && window.print && !window.opera && /MSIE [56]/.test(navigator.userAgent);
var IS_IE7 = document.all && window.print && !window.opera && /MSIE [78]/.test(navigator.userAgent);
var IS_IE_ALL = document.all && window.print && !window.opera && /MSIE/.test(navigator.userAgent);
var IE_W3C = IS_IE && /MSIE [789]/.test(navigator.userAgent);
var IS_Webkit = /Konqueror|Safari|KHTML/.test(navigator.userAgent);
var heightPropertyToUse = IS_IE ? "height" : "minHeight";

/* ecrit les classes dans le tag HTML, pas besoin d'attendre le chargement du body */
document.documentElement.className+=" hasJS"; //cette classe rajoute une classe CSS qui permet des actions afin de cacher ou afficher des elements seulement pour les visiteurs qui ont le Javascript active sur leur navigateur. (exemple le hidesubmit)
if (IS_IE) 
	document.documentElement.className+=" IS_IE"; //cette classe permet d'utiliser des hacks CSS/JS seulement pour IE6 et versions inferieures.
else if (IS_IE7)
	document.documentElement.className+=" IS_IE7"; //cette classe permet d'utiliser des hacks CSS/JS seulement pour IE7

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
function removeEvent(obj, eventType, functionToCall) {

	if(obj.removeEventListener)

		obj.removeEventListener(eventType, functionToCall, false);

	else if(obj.detachEvent)

		obj.detachEvent('on'+eventType, functionToCall);

}

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle) {
		try{ strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); }
		catch(e) { strValue = ""; }
	}
	else if(oElm.currentStyle) {
		try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
				return p1.toUpperCase();
			});
			strValue = oElm.currentStyle[strCssRule];
		} catch(e) {
			strValue = "";
		}
	}
	return strValue;
}

function intStyle(oElm, strCSSRule) {
	var val = parseInt(getStyle(oElm, strCSSRule));
	if (isNaN(val)) val=0;
	return val;
}
function floatStyle(oElm, strCSSRule) {
	var val = parseFloat(getStyle(oElm, strCSSRule));
	if (isNaN(val)) val=0;
	return val;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getMouse(e){
	var x,y; var elt = (navigator.userAgent.indexOf("MSIE 5")!=-1) ? document.body : document.documentElement;
	if ( document.captureEvents ) {
		x = e.pageX;
		y = e.pageY;
	} else if ( window.event.clientX ) {
		x = window.event.clientX+elt.scrollLeft;
		y = window.event.clientY+elt.scrollTop;
	}
	window.mouseX = x;
	window.mouseY = y;
}

var ifrlayer = {
	make:function(obj) {
		if(!obj) return; obj = (typeof(obj)=="string") ? document.getElementById(obj) : obj; if(!obj) return;
		if(document.all && !window.opera && document.getElementById) {
			if(obj.parentNode && !obj.iframelayer) {
			    var ifr = obj.parentNode.insertBefore(document.createElement('<iframe src="javascript:false"></iframe>'), obj);
			    if(obj.currentStyle.zIndex != "" && parseInt(obj.currentStyle.zIndex)>1 ) {
				    ifr.style.zIndex = parseInt(obj.currentStyle.zIndex)-1;
			    }
			    with(ifr.style) {
				    filter = "mask()";
				    position = "absolute";
			    }
                obj.iframelayer = ifr;
            }
		}
		if(obj.iframelayer) {
		    obj.iframelayer.style.visibility="visible";
            ifrlayer.resize(obj);
            ifrlayer.move(obj)
        }
	},
	hide:function(obj) {
		if(!obj) return; obj = typeof(obj)=="string" ? document.getElementById(obj) : obj; if (!obj) return;
		var ifr = obj.iframelayer;
		if(ifr) {
			ifr.style.visibility="hidden";
		}
	},
	move:function(obj) {
		if(obj && obj.iframelayer) {
		    with(obj.iframelayer.style) {
			    top = obj.offsetTop+"px";
			    left = obj.offsetLeft+"px"
		    }
		}
	},
	resize:function(obj) {
	    if(obj && obj.iframelayer) {
	        with(obj.iframelayer.style) {
	            width =  obj.offsetWidth+"px";
		        height =  obj.offsetHeight+"px";
		    }
		}
	}
}
function addHover(elm) {
	elm.style.behavior = " ";
	elm.onmouseenter = function() {
		this.className+= ' hover';
	}
	elm.onmouseleave = function() {
		this.className = this.className.replace(/\bhover\b/,"");
	}
}
var CSSBottomCorners=[]; //array pouvant contenir les coins absolu positionnes en bottom
var currentBlockToFixCorners=null; //variable gloable utilisee lorsqu'on veux fixer les coins sur un seul bloc
function cssRight(elm) {
	elm.style.right=(parseInt(elm.currentStyle.right)-(elm.parentNode.offsetWidth%2))+"px";
}
function cssBottom(elm, pushElement) {
	if (pushElement && !elm.CSSBottomAlreadyCSS) {
		CSSBottomCorners.push(elm);
		elm.CSSBottomAlreadyCSS=true;
	}
	elm.style.bottom=(parseInt(elm.currentStyle.bottom)-(elm.parentNode.offsetHeight%2))+"px";
}

function fixCorners(block) {
	if (IS_IE) {
		for (i=CSSBottomCorners.length-1; i>-1; --i) {
			CSSBottomCorners[i].style.bottom="";
		}
	} else {
		if (IS_Webkit || /Gecko\/200[56]|Opera 8.5/i.test(navigator.userAgent)) fixCornersOnBlocks(block);
	}
}

function fixCornersOnBlocks(block) {
	currentBlockToFixCorners = block || document.body;
	currentBlockToFixCorners.className+=" hidecorners";
	setTimeout("fixCornersOnBlocksShowCorners()",5);
}

function fixCornersOnBlocksShowCorners() {
	if (currentBlockToFixCorners) currentBlockToFixCorners.className=currentBlockToFixCorners.className.replace(/\bhidecorners\b/g,"");
	currentBlockToFixCorners=null;
}
var evaluationMaxNote = 5;
function evaluationInitFields() {
	var p = document.getElementsByTagName("p");
	for (var i=0; i<p.length; i++) {
		var x = p[i];
		if (x.className.match(/\beval\b/)) {
			var img = x.getElementsByTagName("img");
			if (img.length>0) {
				img = img[0];
				img.onmousemove=function(e) {
					evaluationAnimation(this,e);
				}
				img.onmouseout=function() {
					evaluationClearAnim(this)
				}
				img.onclick=function() {
					evaluationSetGrade(this, this.overGrade, true)
				}
			}
		}
	}
}

function evaluationAnimation(img,e) {
	getMouse(e);
	var starWidth = img.offsetWidth/evaluationMaxNote;
	var imgX = findPos(img)[0];
	var mousePosX = window.mouseX-imgX;
	var note = parseInt(mousePosX/starWidth)+1;
	note = note>evaluationMaxNote ? evaluationMaxNote : note<1 ? 1 : note;
	img.overGrade = note;
	if (!img.protectedGrade) evaluationSetGrade(img, note);
}

function evaluationSetGrade(img, note, saveGrade) {
	img.src=img.src.replace(/\d{1}sur/,note+"sur");
	if (saveGrade) {
		img.savedGrade = note;
		evaluationSendGradeByAjax(note);
	}
}

function evaluationClearAnim(img) {
	if (!img.savedGrade) img.savedGrade = 0;
	evaluationSetGrade(img, img.savedGrade);
}

function getElementsByClassName(oElm, sTagName, sClassName)
{
  var aElements = (sTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(sTagName);
  var aReturnElements = new Array();
  sClassName = sClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + sClassName + "(\\s|$)");
  var oElement;
  for(var i=0; i < aElements.length; i++)
  {
    oElement = aElements[i];
    if(oRegExp.test(oElement.className))
    aReturnElements.push(oElement);
  }
  return aReturnElements
}

function sousMenuAddHover(elm, position) {
  elm.style.behavior = " ";
  var menu = elm.getElementsByTagName("ul");
  if (menu.length>0) {
    elm.theUl = menu[0];
    ifrlayer.make(elm.theUl);
    elm.onmouseenter = function() {
      this.className+= ' currentJs';
      ifrlayer.make(elm.theUl);
    }
    elm.onmouseleave = function() {
      this.className = this.className.replace(/\b(right)?currentJs\b/,"");
      ifrlayer.hide(this.theUl);
    }
  }
}
function sousMenuActivation(obj,evt,boucle)
{
//  printDebug(evt.keyCode,0);
  function killSousMenu()
  {
    var allLi = obj.parentNode.getElementsByTagName("li");
    for (var i = 0; i < allLi.length; i++)
    {
      allLi[i].className = allLi[i].className.replace(/\b(right)?currentJs\b/,"");
      ifrlayer.hide(this.theUl);
    }
  }
// touche echap
  if (evt.keyCode==27)
  {
    killSousMenu();
  }
// fleche haut
  if (evt.keyCode==38)
  {
    if(!obj.id=="")
    {
      return;
    }
    else
    {
      killSousMenu();
    }
  }
// fleche droite
  if (evt.keyCode==39)
  {
    if(obj.id=="m_photo_camescope")
    {
      killSousMenu();
      document.getElementById("m_livres").getElementsByTagName("a")[0].focus();
      document.getElementById("m_livres").className+=" currentJs";
    }
    else
    {
      killSousMenu();
      var droiteMenu = (IS_IE_ALL) ? obj.nextSibling : obj.nextSibling.nextSibling;
//      var droiteMenu = obj.nextSibling.nextSibling;
      droiteMenu.getElementsByTagName("a")[0].focus();
      droiteMenu.className+=" currentJs";
    }
  }
// fleche bas
  if (evt.keyCode==40)
  {
    return;//non actif encore
    if(!obj.id=="")
    {
      var lesA = obj.parentNode.getElementsByTagName("a");
      for (var j=0;j > lesA.length; j++)
      {
        if(lesA[j])
        {
        }
      }
    }
    killSousMenu();
  }
// fleche gauche
  if (evt.keyCode==37)
  {
    if(obj.id=="m_livres")
    {
      killSousMenu();
      document.getElementById("m_photo_camescope").getElementsByTagName("a")[0].focus();
      document.getElementById("m_photo_camescope").className+=" currentJs";
      ifrlayer.make(elm.theUl);
    }
    else
    {
      killSousMenu();
      var gaucheMenu = (IS_IE_ALL) ? obj.previousSibling : obj.previousSibling.previousSibling;
//       var gaucheMenu = obj.previousSibling.previousSibling;
      gaucheMenu.getElementsByTagName("a")[0].focus();
      gaucheMenu.className+=" currentJs";
      ifrlayer.make(elm.theUl);
    }
  }
}

function printDebug(debug, ecrase){
  var monId = document.getElementById("header");
  if (document.getElementById("debugJS"))
  {
    if(ecrase==0)
    {
      nouveauDiv.innerHTML+="<pre>"+debug+"</pre>";
    }
    else
    {
      nouveauDiv.innerHTML="<pre>"+debug+"</pre>";
    }

  }
  else{
    nouveauDiv = document.createElement("div");//creation  de l objet
    nouveauDiv.id="debugJS";//identification
    nouveauDiv.style.display="block";//on le stylise un peu
    nouveauDiv.style.position="absolute";
    nouveauDiv.style.top="20px";
    nouveauDiv.style.left="0px";
    nouveauDiv.style.background="black";
    nouveauDiv.style.border="solid 1px #900";
    nouveauDiv.style.zIndex="60";
    nouveauDiv.style.fontSize="11px";
    nouveauDiv.style.color = "white";
    nouveauDiv.style.overflow="auto";
    nouveauDiv.style.height="400px";
    nouveauDiv.style.width="auto";
    nouveauDiv.style.padding="5px";
    nouveauDiv.innerHTML="<pre>"+debug+"</pre>";
    monId.parentNode.insertBefore(nouveauDiv, monId);//on insert l'objet avant la balise appele
  }
}

/* filter:  permet de filtrer un array avec une fonction passee en parametre*/ 
function filter(arr, f) {
	   	var out = new Array();
    	var j = 0;
		for(var i = 0; i<arr.length; ++i) {
	   		if(f(arr[i])) {
	       		out[j++] = arr[i];
	       	}
       	}
	return out;
}

/* getText : retourne le text d'un element */
function getText(elt) {
	if (elt.textContent) {
		return elt.textContent;
	} else {
		return elt.innerText;
	}
}
/* cancelClick, permet de supprimer la propagation du click sur un element */
var cancelClick=function(e){
	if (window.event){
		window.event.cancelBubble = true;
		return;
	}
	if (e){
		if (e.stopPropagation) {
			e.stopPropagation();
		}
	}
}

var cancelBubble=function(e) {
	if (window.event){
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return;
	}
	if (e){
		e.stopPropagation();
		e.preventDefault();
	}
}

 function getCookieVal(offset) 
 {
	
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
                        return getCookieVal (j);
                i=document.cookie.indexOf(" ",i)+1;
                        if (i==0) break;}
	return null;
}

function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

var readAllAdvicesLink = "readAllAdvicesLink";
var internautesadviceId = "lastBestComment";
function popLayerMakeContent(e, type, obj) {
	var pop = popLayerShow(e);	
	if (pop && type) {
		switch (type.toLowerCase()) {
			//get first user advice
		case "advice" :	var Avislst = document.getElementById(internautesadviceId);
						if (Avislst) {
							var avis = Avislst;
							if (avis) {
								pop.innerHTML = avis.innerHTML;
								var p = pop.getElementsByTagName("p");
								for (var i=0; i<p.length; i++) {
									if (p[i].className.indexOf("ndlr")!=-1) p[i].parentNode.removeChild(p[i]);
								}
							}
						}
						break;
		case "service" : pop.innerHTML = obj.innerHTML;
						 break;
		}
	}
	ifrlayer.make(pop);
}

function popLayerShow(e,normalTop) {
	var home = document.getElementById("home");
	var html = document.getElementsByTagName((navigator.userAgent.indexOf("MSIE 5")!=-1) ? "body" : "html")[0];
	var body = document.getElementsByTagName("body")[0];
	getMouse(e);
	var popup = document.getElementById("popLayer"); 
	if (!popup) {
		var tmp = document.createElement("div");
		tmp.className="hoverBlock filledBox";
		tmp.id="popLayer";
		with(tmp.style) {position="absolute"; display="block";}
		popup = home.appendChild(tmp);
	}
	
	if (popup) {
		if (popup.className!="hoverBlock filledBox") popup.className="hoverBlock filledBox";
		with(popup.style) {
			if (display!="block") display = "block";
			left = (window.mouseX+popup.clientWidth+10>html.scrollLeft+html.clientWidth-10) ? (html.scrollLeft+html.clientWidth-popup.clientWidth-10)+"px" : window.mouseX+10+"px";
			top = (window.mouseY+popup.clientHeight+10>html.scrollTop+html.clientHeight-10 && !normalTop) ? (window.mouseY-popup.clientHeight-10)+"px" : window.mouseY+10+"px";
		}
	   popup.style.visibility = "visible";
		ifrlayer.move(popup);
		return popup;
	}
	return null;
}

function popLayerClose() {
	var popup = document.getElementById("popLayer"); 
	if (popup) {
	   popup.style.visibility = "hidden"; 
	    popup.innerHTML="";
	    ifrlayer.hide(popup);
	}
}
function closePop(str){ // ajout pour les FAPE uniquement, nouvelle fonction de fermeture des zooms
	var pop = document.getElementById(str);
	if(typeof(pop) != "undefined" && pop != null)
	{
		$(pop).children("p").children("span").children("img").attr("src","");
		$(pop).css("visibility","hidden");
		ifrlayer.hide(pop);
	}
}

var navDiaporama={
    container:null,
    container2:null,
    imagesContainer:null,
    imagesContainer2:null,
    imagesList:[],
    imagesList2:[],
    indexSoftList:null,
    currentImg:null,
	hiddenImgs:[],
	hiddenImgsSrc:[],
    zoomButton:null,
    turnpagesButton:null,
	turnpages:"false",
    arrow:{ left:null, right:null },
    popZoomId:"popZoomImage",
    popZoom:null,
    init:function() {

        var x, firstArrow=false;
        var home = document.getElementById("home"); if (!home) return;

	    var divtmp = getElementsByClassName(home, "div", "nav-diaporama");
			
        if (divtmp.length > 0) { var nav=divtmp[0]; }
        else return;
		if (divtmp.length > 1) { var nav2=divtmp[1]; }
        //else return;
        
		//on parcourt les childnodes de l'element pour ajouter les fonctionnalites necessaires.
		//Le contenu de l'element doit respecter le schema : <a flechegauche><span blockdimages><a flechedroite> 

	    navDiaporama.container=nav;
	    var childs=nav.childNodes;
	    for (var i=0; i<childs.length; i++){ 
		    var chd=childs[i];
		    switch (chd.nodeName) {
			    case "A": //si on rencontre un lien on le considere comme une fleche de nav
				    if (!firstArrow) {
					    chd.onclick=function() {
						    navDiaporama.gotoImg(1);
						    return false;
					    }
					    navDiaporama.arrow.left=chd;
					    firstArrow=true;
				    } else {
					    chd.onclick=function() {
						    navDiaporama.gotoImg(-1);
						    return false;
					    }
					    navDiaporama.arrow.right=chd;
				    }
				    break;
			    case "SPAN": //ici on doit obligatoirement rencontrer le bloc d'images
				    navDiaporama.imagesContainer=chd;
				    var imgs = chd.childNodes;
				    var k=0;
				    for (var j=0; j<imgs.length; j++) {
					    var img=imgs[j];
					    if (/A|SPAN/.test(img.nodeName)) {
						    navDiaporama.imagesList.push(img);
						    img.indexNumber=navDiaporama.imagesList.length-1;
						    if (img.nodeName=="A") {
							    img.onclick=navDiaporama.showZoomImg;
						    }
						    if (img.className.match(/\bactiveimg\b/)){
							    navDiaporama.currentImg = img;
						    }
						    else {
							    navDiaporama.hiddenImgs[k] = img;
							    navDiaporama.hiddenImgsSrc[k] = navDiaporama.hiddenImgs[k].childNodes[0].src;
							    k++;
						    }
					    }
				    }
		    }
	    }
	    
	    if (divtmp.length > 1) { 
	        navDiaporama.container2=nav2;
	        var childs2=nav2.childNodes;
	        var j = 0;
	        for (var i=0; i<childs2.length; i++){ 
	            if (childs2[i].nodeName == "A") {
			       navDiaporama.imagesList2.push(childs2[i]);
			       navDiaporama.indexSoftList=navDiaporama.imagesList2.length-1;
                   childs2[i].onclick=navDiaporama.showSoftZoomImg;
                   childs2[i].indexImg = j;
                   j++;
	            }
	        }
	    }
	    
		//initialise le lien pour zoomer l'image et les liens pour Feuilleter les pages
		var par = navDiaporama.container.parentNode;
		var a = par.getElementsByTagName("a");
		for (var i=0;i<a.length;i++) {
			if (a[i].className.match(/\b(expandimg)\b/)) {
				navDiaporama.zoomButton = a[i];
				navDiaporama.zoomButton.onclick = navDiaporama.showZoomImg;
			}
			if (a[i].className.match(/\b(turnpagesButton)\b/)) {
				navDiaporama.turnpagesButton = a[i];
				navDiaporama.turnpagesButton.onclick = navDiaporama.showTurnpagesImg;
			}
		}

		//verifie s'il y a une image par defaut, sinon on en active une
		if(navDiaporama.imagesList.length>0 && !navDiaporama.currentImg) {
			navDiaporama.currentImg = navDiaporama.imagesList[0];
			navDiaporama.showImg(0);
		}
		
		//verifie si il n' y a plus d'une image dans le diaporama, dans ce cas on affiche les fleches
		if (navDiaporama.imagesList.length>1) {
			for (elt in navDiaporama.arrow) {
				var x = navDiaporama.arrow[elt];
				if (x && x.style) { x.style.display="inline"; }
			}
		}
	},
    gotoImg:function(sens) {
        var num =  navDiaporama.currentImg.indexNumber;
        num+=sens;
        if (num<0) num = navDiaporama.imagesList.length-1;
        if (num>=navDiaporama.imagesList.length) num=0;
        navDiaporama.showImg(num);
    },
    showImg:function(imgIndex) {
        navDiaporama.currentImg.className="";
        if (!navDiaporama.imagesList[imgIndex]) return;
        navDiaporama.currentImg=navDiaporama.imagesList[imgIndex];
        navDiaporama.currentImg.className="activeimg";
        if (navDiaporama.zoomButton) {
            if (navDiaporama.currentImg.nodeName!="A" || navDiaporama.currentImg.href=="" || !/.jpg$|.bmp$|.image$|.gif$|.png$/.test(navDiaporama.currentImg.href.toLowerCase())) {
                navDiaporama.zoomButton.parentNode.style.visibility="hidden";
            } else {
                navDiaporama.zoomButton.parentNode.style.visibility="visible";
            }
        }
    },
    showZoomImg:function(e) {
        if (navDiaporama.currentImg.nodeName=="A" && navDiaporama.currentImg.href!="" && /.jpg$|.bmp$|.image$|.gif$|.png$|.media$/.test(navDiaporama.currentImg.href.toLowerCase())) {
            navDiaporama.turnpages = "false";
			var pop=navDiaporama.makePopZoom();
			pop.zoomImage.src = navDiaporama.currentImg.href;
            pop.move();
            ifrlayer.make(pop);
        }
		return false;
    },
    showSoftZoomImg:function(e) {
       var firingElement = e.currentTarget;
       if( firingElement != null )
       {
            navDiaporama.turnpages = "false";
            pop=navDiaporama.makePopZoom();
            pop.zoomImage.src = navDiaporama.imagesList2[firingElement.indexImg];
            pop.move();
            ifrlayer.make(pop);
       }
       return false;
    },
    showTurnpagesImg:function(e) {
	 if (navDiaporama.currentImg.nodeName=="A" || navDiaporama.currentImg.nodeName=="SPAN") {   
        //evite d'ajouter un 2e navPage
        var navPage = document.getElementById("navPage");
	    var popZoomId = document.getElementById("popZoomImage");
	    if (navPage) { popZoomId.removeChild(navPage); }
	    ///
        navDiaporama.turnpages = "true";
		var pop=navDiaporama.makePopZoom();
		pop.zoomImage.src = navDiaporama.hiddenImgsSrc[0];
        pop.move();
        ifrlayer.make(pop);
     }
	 return false;
    },
    makePopZoom:function(e){
		
		var pop = document.getElementById(navDiaporama.popZoomId);
		
		if (!pop) {
		
		    var div = document.createElement("div");
		    div.id=navDiaporama.popZoomId;
		    div.innerHTML = '<ul><li><a href="#" onclick="closePop(\'popZoomImage\');return false">Fermer</a></li></ul>';

		    div.style.visibility="hidden";
    		
		    var zoomBlock = div.appendChild(document.createElement("p"));
    		
		    zoomBlock.style.verticalAlign="middle";	
    		
		    var span = zoomBlock.appendChild(document.createElement("span"));
		    var img = span.appendChild(document.createElement("img"));
		    img.onload=function() {
			    pop.className="";
			    pop.getPositionFromWindow;
			    this.pop.move();
			    ifrlayer.resize(pop);
		    } 
    		
		    div.zoomImage = img;
		    img.pop = div;
		    div=document.body.appendChild(div);
		    pop=div;
		    navDiaporama.popZoom = div;
    		
		    var AllElt = div.getElementsByTagName("*");
		    for(var i=0; i<AllElt.length;i++) {
			    AllElt[i].onmousemove=AllElt[i].onmousedown=function() {return false};
		    }

		    pop.move        = navDiaporama.movePopZoom;
		    pop.onmousedown = navDiaporama.makePopZoomDraggable;
		    addEvent(pop,"mousedown", cancelBubble);
		    addEvent(pop,"dblclick", navDiaporama.hidePopZoom);
		    
		    
		    //gestion du copyright de l'image
            
            copyright = null;
            eltParentImg = navDiaporama.currentImg.parentNode;
            bElementCurrent = false;
            
            var i;
            for( i=0;i<eltParentImg.childNodes.length;i++ ) { 
                if( navDiaporama.currentImg == eltParentImg.childNodes[i] ) {
                    bElementCurrent = true;
                }
                else if( bElementCurrent ) {
                    // si le type du noeud n'est pas du texte et que c'est un element span, alors on recupere le copyright
                    if (eltParentImg.childNodes[i].nodeType != 3 && eltParentImg.childNodes[i].nodeName.toLowerCase() == "span" ) {
                        var span = eltParentImg.childNodes[i];
                        if (span.childNodes[0].nodeName.toLowerCase() != "img") {
                            copyright = eltParentImg.childNodes[i];
                            break;
                        }
                    }
                    if (eltParentImg.childNodes[i].nodeType != 3 && eltParentImg.childNodes[i].nodeName.toLowerCase() != "span" ) {
                        copyright = null;
                        break;
                    }
                }
            }


            if (copyright != null) {
               if (!pop.copyright ) {
                    var popCopyright = pop.appendChild(document.createElement("p"));
                    popCopyright.className = "copyright noir lienInverse";
                    pop.copyright = popCopyright;
                }
                if (/\w/.test(getText(copyright)) ) {
                    pop.copyright.innerHTML = copyright.innerHTML;
                    pop.copyright.style.display = "block";
                } else {
                    pop.copyright.style.display = "none";
                }
            }

            //fin du copyright
        }

        //gestion des fleches pour feuilletter les pages

        //pour passer du zoom "Feuilleter les pages" au zoom "Agrandir l'image" on supprime les fleches
		if (pop && navDiaporama.turnpages == "false") {
		    var navPage = document.getElementById("navPage");
		    var popZoomId = document.getElementById("popZoomImage");
		    if (navPage) { popZoomId.removeChild(navPage); }
		}
		else if (!navPage) {
            //on ne compte pas le dernier span qui contient le copyright
            if (copyright != null) var numPage = navDiaporama.hiddenImgsSrc.length-1;
            else var numPage = navDiaporama.hiddenImgsSrc.length;
			
			if (numPage > 1) {

                var navPage = pop.appendChild(document.createElement("p"));
                navPage.id = "navPage";
                navPage.className = 'txt_c';
                //navPage.style.backgroundColor = '#eee';
                navPage.style.Height = '2em';
               
                var aPrev = navPage.appendChild(document.createElement("a"));
                aPrev.href = "#";
                aPrev.innerHTML = '<img src="'+scriptImagesPath+'pictos/arrows/picto_arrow_previous.gif" alt="previous image" />';
		        aPrev.style.verticalAlign = '-0.5em';

                var popNumPage = navPage.appendChild(document.createElement("span"));
                popNumPage.className = 'noir';
                popNumPage.style.lineHeight = '3em';
                popNumPage.style.verticalAlign = 'middle';

                var aNext = navPage.appendChild(document.createElement("a"));
                aNext.href = "#";
                aNext.innerHTML = '<img src="'+scriptImagesPath+'pictos/arrows/picto_arrow_next.gif" alt="next image" />';
                aNext.style.verticalAlign = '-0.5em';

                popNumPage.innerHTML = 'Image : 1 / '+ numPage;
    		    
	            var i = 1;
	            aPrev.onclick=function() {
					i--;
					if (i < 0 || i == 0) i = numPage;
		            pop.zoomImage.src = navDiaporama.hiddenImgsSrc[i-1];
		            popNumPage.innerHTML = 'Image : '+ i +' / '+numPage;
		            return false;
	            }	
	            aNext.onclick=function() {
		            i++;
		            if (i > numPage && pop.zoomImage.src == navDiaporama.hiddenImgsSrc[numPage-1]) i = 1;
		            pop.zoomImage.src = navDiaporama.hiddenImgsSrc[i-1];
		            popNumPage.innerHTML = 'Image : '+ i +' / '+numPage;
		            return false;
	            }    
	        }
		}
		
		//fin de la gestion des fleches
		
		//if (!navPage) {
		    //la position du popin en haut a gauche de la fenetre du navigateur n'est initialise
		    //qu'a l'ouverture de la popin
			//pop.getPositionFromWindow = navDiaporama.getPositionFromWindow;					
		//}
		
		pop.style.visibility="visible";
		pop.onmousemove=function(){};
		if (pop.zoomImage.complete) {
			pop.zoomImage.onload();
		}
		return pop;
    },
    movePopZoom:function(){
       if (!isNaN(this.x)) this.style.left = this.x+"px";
       if (!isNaN(this.y)) this.style.top = this.y+"px";
       ifrlayer.move(this);
    },
    hidePopZoom:function(e){
        var pop = navDiaporama.popZoom;
        pop.style.visibility="hidden";
        ifrlayer.hide(navDiaporama.popZoom);
    },
    getPositionFromWindow:function(e){
        var doc = (/MSIE 5|Opera/.test(navigator.userAgent)) ? document.body : document.documentElement;  //document.documentElement;
        /*  
        this.x = doc.scrollLeft+parseInt((doc.clientWidth-this.offsetWidth)/2);
        this.y = doc.scrollTop+parseInt((doc.clientHeight-this.offsetHeight)/2)
        if (this.x<0) this.x=0;
        if (this.y<0) this.y=0;
        */
         this.x = doc.scrollLeft;
         this.y = doc.scrollTop;
    },
    makePopZoomDraggable:function(e) {
        getMouse(e);
        this.className+=" dragmode";
        this.mouseOffsetX = window.mouseX-this.offsetLeft;
        this.mouseOffsetY = window.mouseY-this.offsetTop;
        document.onselectstart = function() {return false};
        document.onmousemove = navDiaporama.moveFromMouse;
        this.onmouseup = function() {
            document.onmousemove=function() {}; //retire les fonctionnalite sur le deplacement
            document.onselectstart=function() {};
            this.className = this.className.replace(/dragmode/g,"");
        };
    },
    moveFromMouse:function(e) {
        var doc = document.documentElement;
        var p = navDiaporama.popZoom;
        getMouse(e);
        p.x = window.mouseX-p.mouseOffsetX;
        p.y = window.mouseY-p.mouseOffsetY;
        p.move();
    } 
}

/* Genere un message d'attente avec */
/*var waitingMsg={
    shadowLayer:null,
    layerId:"waitingMsg",
    defaultTimeout:15000,
    timer:null,
    show:function() {
        var div = document.getElementById(waitingMsg.layerId);
        var doc = /MSIE 5|OPERA/.test(navigator.userAgent) ? document.body : document.documentElement;
        if (!waitingMsg.shadowLayer) {
            var shadow = document.body.appendChild(document.createElement("div"));
            waitingMsg.shadowLayer = shadow;
            shadow.id="shadowLayer";
            with(shadow.style) {
                left=0;
                right=0;
                height=doc.scrollHeight+"px";
            }
        }
        waitingMsg.shadowLayer.style.display="block";
        ifrlayer.make(waitingMsg.shadowLayer);
        if (div) {
            div = document.body.appendChild(div);
            div.style.display="block";    
            ifrlayer.make(div);
            div.style.left = (doc.scrollLeft+parseInt((doc.clientWidth-div.offsetWidth)/2))+"px";
            div.style.top = (doc.scrollTop+parseInt((doc.clientHeight-div.offsetHeight)/2))+"px"
        }
    },
    hide:function() {
        var div = document.getElementById(waitingMsg.layerId);
        waitingMsg.shadowLayer.style.display="none";
        ifrlayer.hide(waitingMsg.shadowLayer);
        div.style.display="none";
        ifrlayer.hide(div);
        clearTimeout(waitingMsg.timer);
    },
    setHideTimer:function(timer) {
        var timeforTimeout = timer || waitingMsg.defaultTimeout;
        if (!waitingMsg.timer) {
            waitingMsg.timer = setTimeout("waitingMsg.hide()",timeforTimeout);
        }
    }
}*/



var hoverblock = {
    init:function(parentElement) {
        var tmp=null;
        parentElement = typeof(parentElement)=="string" ? document.getElementById(parentElement) : parentElement;
        if (!parentElement) return;
        var table = parentElement.getElementsByTagName("table"); //init Accessories
        for (var i=0; i<table.length;i++) {
	        if (table[i].className.match(/\btbl-accessoires\b/)) {
		        var tds = table[i].getElementsByTagName("td");
		        for (var j=0; j<tds.length;j++) {
			        var td = tds[j];
        			
			        tmp = getElementsByClassName(td,"a", "picture");
			        if (tmp.length>0) {
			            td.eltPictureLink = tmp[0];
			            td.eltPicture = tmp[0].firstChild;
                    }
                    
                    tmp = getElementsByClassName(td, "a", "element");
			        if (tmp.length>0) td.eltTitle = tmp[0];
			        
			        var hblock = getElementsByClassName(td, "div", "hoverBlock");
			        if (hblock.length>0) {td.hoverBlock = hblock[0];}
			        
			        if (td.hoverBlock) {
			            td.eltTitle.AssociatedTd = td;
			            td.eltTitle.onmouseover = hoverblock.over;
				        addEvent(td.eltTitle, "mousemove", hoverblock.move);
				        addEvent(td.eltTitle, "mouseout", hoverblock.close);
				        if (td.eltPictureLink) {
				            td.eltPictureLink.AssociatedTd = td;
				            
				         /* over on the product picture */
                         /*   td.eltPictureLink.onmouseover = hoverblock.over;
                            addEvent(td.eltPictureLink, "mousemove", hoverblock.move);
                            addEvent(td.eltPictureLink, "mouseout", hoverblock.close);
                         */
				        }
			        }
		        }
	        }
        }
    },
    over:function(e) {
        var td = this.AssociatedTd;
        popLayerMakeContent(e, "service", td.hoverBlock);
    },
    move:function(e) {
        popLayerShow(e);
    },
    close:function(e) {
        popLayerClose();
    }
}

$(function rollHover(){
	// la nécessité d'avoir une variable globale rhChemin définie dans les pages
	if(typeof(rhChemin) == "undefined" || rhChemin == null) { return; }
	var construction = {
		process : null,
		path:function(file){
			var indice = file.lastIndexOf("/");
			var fichier = file.substring(indice+1);
			if(/on/.test(fichier))
			{
				process = fichier.replace(/on/,"off");
				return process;
			} else if(/off/.test(fichier))
			{
				process = fichier.replace(/off/,"on");
				return process;
			} else { return false; }
		}
	};
	$("a.rHover").mouseover(function(){
		var fichier = $(this).children("img").attr("src");
		if(f = construction.path(fichier))
		{
			$(this).children("img").attr("src",rhChemin+f);
		}
			
	});
	$("a.rHover").mouseout(function(){
		var fichier = $(this).children("img").attr("src");
		if(f = construction.path(fichier))
		{
			$(this).children("img").attr("src",rhChemin+f);
		}
	});
});

function highlightButton(){
    $(document).ready(function(){
	    $("img.rHvr").hover(function(){
		    $(this).css("opacity", "0.5");
	    },function(){
		    $(this).css("opacity",1);
	    });

	    /*Plug pour les input hover */
        $("input[type='image'].rHvr").hover(function(){
            //alert("ok");
            $(this).css("opacity","0.5");
        },function(){
            $(this).css("opacity","1");
        });

	    $("a.contextHelp").click(function(){
		    if($("div.aidePopin").css("display") == "none")
		    {
			    var popin = document.createElement("DIV");
			    popin.id = "contextHelp";
			    popin.innerHTML = $("div.aidePopin").html();
			    document.body.appendChild(popin);
			    $(popin).css({position:"absolute",display:"block","z-index":999,width:"300px"});
			    if(IS_IE) { ifrlayer.make($("div#contextHelp")); }
			    if(this["centerPopin"]) centerPopin("contextHelp");
			    $(popin).fadeOut(3000);
		    }
		    return false;
	    });
    });
}
highlightButton();

function adjustCol(){
    $(document).ready(function(){
    // Fonction pour l'alignement en hauteur des guides 
        $(".guides ul li").each(function(e){
            if (e != 0) {
                // Alignement des titres sur 2 lignes
                var hautDT = $(".guides ul li dl dt").eq(e).height(); 
                if (hautDT > $(".guides ul li dl dt").eq(e-1).height()) {
                    $(".guides ul li dl dt").each(function(){
                        $(this).height(hautDT);
                    });
                }
                // Alignement des textes Editoriaux
                var hautP2 = $(".guides ul li dl dd p").eq(e).height(); 
                if (hautP2 > $(".guides ul li dl dd p").eq(e-1).height()) {
                    $(".guides ul li dl dd p").each(function(){
                        $(this).height(hautP2);
                    });
                }    
            } 
        });
    });
}
adjustCol();

function cleanCesure(str, index)
{
    str = str.replace(/&nbsp;/gi, " ");
    var nb = str.length;
    var x = Math.floor(nb / index);
    var ok;
    for(var i=1;i<=x;i++)
    {
        index = index*i;
        if(str.charAt(index) == " ")
        {
            str = str.substring(0,index) + "<br />" + str.substring(index+1);
        } else {
            var o = str.indexOf(" ",index);
            str = str.substring(0,o) + "<br />" + str.substring(o+1);
        }
    }
    if(str.charAt(0) == "<")
        str = str.substring(6);
    return str;
}
var tooltServ = {
    t_running : 0,
    process : "off",
    obj : null,
    x : null,
    y : null,
    message : null,
    original : null,
    over : function(origin, message){
            tooltServ.t_running++;
            if(tooltServ.t_running > 1) return;
            var timer = setTimeout(function(){ tooltServ.t_running = 0; clearTimeout(this); }, 1000);
            if(tooltServ.obj.nodeName != "A" && tooltServ.obj.nodeName != "SPAN")
                tooltServ.obj = $(tooltServ.obj).parent();
            
            if(origin == 'bouton')
            {
                tooltServ.original = message;
            } else {   
                tooltServ.original = $(tooltServ.obj).attr("title");
                $(tooltServ.obj).attr("title","");
            }
            if($( tooltServ.obj).attr("href") == "#" || tooltServ.obj.nodeName == "SPAN") tooltServ.process = "on";
            var timer2 = setTimeout(function(){tooltServ.make();}, 1000);
        
    },
    make : function(){
        if(tooltServ.process == "on" && tooltServ.message != '')
        {
            if($("div#tooltipmessage").length > 0)
                $("div#tooltipmessage").remove();
            var text = document.createTextNode(tooltServ.original);
            $("body").append("<div id='tooltipmessage' style='display:none;'><p></p><span></span></div>");
            $("div#tooltipmessage").css({'position':'absolute','z-index':99,'width':'150px','padding':'10px','border':'3px solid #fddd98','background-color':'#fffaf1'});
            $("div#tooltipmessage p").css({'font-size':'12px','font-weight':'bold','color':'#000','display':'block','text-align':'center'});
            $("div#tooltipmessage span").css({'background':'transparent url(../Img/decos/pipe/fleche_popin_error_down.png) no-repeat center bottom','display':'block','height':'13px','width':'13px','position':'absolute','left':'47%','bottom':'-13px'});
            $("div#tooltipmessage p").html(text);
            tooltServ.message = cleanCesure($("div#tooltipmessage p").html(),24);
            $("div#tooltipmessage p").html(tooltServ.message);
            var xx = tooltServ.x-$("div#tooltipmessage").width()/2;
            var yy = tooltServ.y-$("div#tooltipmessage").height();
            $("div#tooltipmessage").css({"top":yy-30+"px","left":xx+"px"}).fadeIn(700)
                                                                                                                    .animate({'top':tooltServ.y-120+'px'}, 800)
                                                                                                                    .delay(2500)
                                                                                                                    .hide( function()
                                                                                                                                                                                        { 
                                                                                                                                                                                            tooltServ.t_running = 0;
                                                                                                                                                                                        } );
        }
    }
}

// laissez cette fonction en fin de fichier, merci
$(function initpage() {
    var message;
    navDiaporama.init();
    if($("div#userNotes ul li.add_advice, #socialNetworkOwner span.share a.btPartager").length > 0)
    {     
        $("div#userNotes ul li.add_advice").mouseenter(function(e){
            if(e.stopPropagation)
                e.stopPropagation();
            else
                e.cancelBubble = true;
            tooltServ.obj = e.target;
            tooltServ.x = e.pageX;
            tooltServ.y = e.pageY;
            tooltServ.over("", "");
        }).mouseleave(function(e){ tooltServ.process = "off"; if(tooltServ.original && $( tooltServ.obj).attr("title") == '') $(e.target).attr("title",tooltServ.original); });
    }   
});



