// Internet Explorer 6
 var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
 var IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
 var gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
 var isMSIE = /*@cc_on!@*/false;
var gteIE9 = false;
var IEV = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
 var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
 if (re.exec(navigator.userAgent) != null) { IEV = parseFloat( RegExp.$1 ); if (parseInt(IEV) >= 9) gteIE9 = true; }
}


 var isSafari = (navigator.vendor && navigator.vendor.indexOf('Apple') != -1);
 var isFirefox = /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);

/* ------------------  Fonctions pour rétro-compatibilité...  ------ */
function ZEN(id) { return document.getElementById(id) || false; }
function Ouvrir(id) {
  if (!isMSIE || gteIE9) $('#'+id).fadeIn('fast');
  else $('#'+id).stop(true,true).slideDown();
}
function Fermer(id) {
  if (!isMSIE || gteIE9) $('#'+id).fadeOut();
  else $('#'+id).stop(true,true).slideUp();
}
function SelectValeur(a,b){for(i=0;i<a.options.length;i++)if(a.options[i].value==b){a.selectedIndex=i;return true}return false}
function trans(a,b){if(isMSIE)a.style.filter="alpha(opacity="+b+")";else{a.style.opacity=b/100;a.style.MozOpacity=b/100}}
function Deconnecter() {
  if (CheckEdition()) {
    //$('#nom_utilisateur').effect('explode',{queue:false},300);
    $('#div_admin_generale, #toggle_admin_generale,#player, #registre_conteneur').hide();
    $('#complet').fadeOut({duration:1200,easing:"easeOutQuad",queue:false});
    setTimeout('window.location.href = "login.php?logout";',500);
  }
}
function GetToTop() {
    $('html,body').animate({scrollTop: 0}, {duration: 'fast', easing: 'swing', queue:false});
}

function CheckTimeup() {if (ZEN('time_up')) window.location.href=url_base;}

function SAImg(o) {
  if ($(o).attr('src') == null) $(o).css('display','none'); // si ça a été coupé par le code, balise incomplète...
  else { th = $(o).height(); tw = $(o).width();
      if (th > 90 || tw > 110) {
        if (th >= tw) $(o).css('width','auto').css('height','90px');
        else $(o).css('width','110px').css('height','auto');
      }
  }
}
//Fonctions de tri maison..
function zenStr(s) { return s.toLowerCase().replace(/[éèêë]/g,"e").replace(/[àâä]/g,"a").replace(/[îï]/g,"i").replace(/[ôöœ]/g,"o").replace(/[ùûü]/g,"u").replace(/[ç]/g,"c").replace(/[ñ]/g,"n"); }
function reculeElem(a,sel,dir){ while ($(a).prev().length > 0 && dir($(a).find(sel).text(),$(a).prev().find(sel).text())) { pr = $(a).prev(); pr.before(a); a = pr.prev(); }}

/* *******************************************************
 *    Fonctions pour navigation
 * ******************************************************* */
var bypass_histo = true;
var edition_active = false;
var efface_msg_admin = true;
var CEAffiche = true;
function CheckEdition(){if(ZEN("msg_admin")&&efface_msg_admin)ZEN("msg_admin").innerHTML="&nbsp;";efface_msg_admin=true;if(edition_active){msg=est_admin?'<div id="zen_edition_active"><div class="avertissement">Vous devriez finir ce que vous avez commencé !<br />Enregistrez ou annulez vos modifications puis ré-essayez.</div><br />Si vous êtes déjà en train de changer de page, veuillez patienter un moment...</div>':'<div id="zen_edition_active"><div class="note_opaque">Vous êtes déjà en train de changer de page, veuillez patienter un moment...</div></div>'; CEAffiche&&$(msg).dialog({autoOpen:true,modal:true,resizable:false,draggable:false,title:"Le site est d\u00e9j\u00e0 occup\u00e9 . . .",width:500,closeOnEscape:true,position:["center",150],close:function(){$(this).remove()}});if(est_admin){$("#zen_edition_active").dialog("option","buttons",{"Ne pas afficher les prochains avertissements":function(){CEAffiche=false;$(this).dialog("close")}});$("#zen_edition_active").next().find("button").focus()}return false}else return edition_active=true}
//function Highlight(a,b){if(ZEN("check_highlight").checked&&a&&a.className!="zen_light"&&!ZEN("cachette_admin_aj_elem")&&!(a.id&&a.id.substring(0,5)=="album")){nb=0;for(i in a.childNodes){nb++;Highlight(a.childNodes[i],b)}if(isMSIE){if(nb==1&&a.nodeValue&&b.test(a.nodeValue))if(a.parentNode&&a.parentNode.className!="zen_light"&&a.parentNode.innerHTML.indexOf("zen_light")==-1){temp=a.parentNode.innerHTML.replace(b,'<u class="zen_light">$&</u>');a.parentNode.innerHTML=temp}}else if(nb==0&&a.nodeValue&& b.test(a.nodeValue))if(a.parentNode&&a.parentNode.className!="zen_light"&&a.parentNode.innerHTML.indexOf("zen_light")==-1){temp=a.parentNode.innerHTML.replace(b,'<u class="zen_light">$&</u>');a.parentNode.innerHTML=temp}}}
function ZenConfirm(a,b,d){$('<div id="zen_confirm">'+a+"</div>").dialog({autoOpen:true,modal:true,closeOnEscape:true,open:"fade",close:function(){d();$(this).dialog("destroy");$(this).remove()},draggable:false,resizable:false,position:["center",100],width:600,title:"Veuillez confirmer cette action",buttons:{Ok:function(){b();$(this).dialog("destroy");$(this).remove()},Annuler:function(){$(this).dialog("close")}}});direction=$("#zen_confirm").next().find("button:first").css("float");$("#zen_confirm").next().find("button:first").focus(); direction=="right"?$("#zen_confirm").next().find("button").keypress(function(c){if(c.keyCode==37)if($(this).next().length!=0){$(this).blur();$(this).next().focus()}if(c.keyCode==39)if($(this).prev().length!=0){$(this).blur();$(this).prev().focus()}}):$("#zen_confirm").next().find("button").keypress(function(c){if(c.keyCode==39)if($(this).next().length!=0){$(this).blur();$(this).next().focus()}if(c.keyCode==37)if($(this).prev().length!=0){$(this).blur();$(this).prev().focus()}})};
//Google closure compiler (1kb sauvé!)..
function Highlight(a,b){
  if (!super_admin &&!ZEN("cachette_admin_aj_elem") && ZEN("check_highlight").checked && a&& a.className!="zen_light") {//patch pour éviter conflit lors d'édition.. voir article
      $(a).contents().each(function() {
      	 switch(this.nodeType) {
            case 1: // ELEMENT_NODE
                if ($(this).children().length > 0) Highlight(this,b);
                else $(this).html($(this).html().replace(b,'<u class="zen_light">$&</u>'));
            break;
            case 3: // TEXT_NODE
                $(this).wrap('<span/>').parent().html($(this).text().replace(b,'<u class="zen_light">$&</u>')).contents().unwrap();
            break;
      	 }
      });
  }
}
function ChangeVOnglet(id, prefix) {
 if (prefix === undefined) prefix = "";
 if (!edition_active) {
   if (ZEN(prefix+'vonglet_actif')) {
      ferme = ZEN(prefix+'vonglet_actif').innerHTML;
      ZEN(prefix+'vonglet_actif').innerHTML = id;
      if (ferme != id) {
         f = $('#'+prefix+'vonglet_'+ferme);
         f.parent().css('height',f.height());
         f.hide();
         $('#'+prefix+'menu_vonglet_'+ferme).parent().removeClass('ui-state-active');
         p=$('#'+prefix+'menu_vonglet_'+id).parent();
         p.addClass('ui-state-active').removeClass('ui-state-hover');
         //hcible = Math.max(p.parent().height(),$('#'+prefix+'vonglet_'+id).height());
         Ouvrir(prefix+'vonglet_'+id);
         f.parent().css('height','auto'); //l'animation coupe l'ombre des enfants..!!
         //.stop(true,true).animate({height:hcible},'fast', function(){$(this).css('height','auto')});//ajouter padding au hcible !!
      }
   }
 }
}

jQuery.fn.ombre = function(paramStr,IE) {
   if (!isMSIE || gteIE9) {
    if (isFirefox) $(this).css('-moz-box-shadow',paramStr);
    else $(this).css('-webkit-box-shadow',paramStr)
    $(this).css('box-shadow',paramStr);
   }
   return true;
}
   /*if (isMSIE && !gteIE9) { // ATTENTION, si on remet filter dans classe ombre !! && IE) {
    $(this).addClass('ombre');
   }*/

function PatchYoutube() {/* PATCH TEMPORAIRE, surveiller les petits sacripants de Youtube.. */
   $('iframe').each(function() { //:[title="YouTube video player"]
      s = $(this).attr('src');
      if (s.toLowerCase().indexOf('http://www.youtube.com') == 0){
       if (s.indexOf('wmode=') < 0) $(this).attr('src',s+(s.indexOf('?')<0?'?':'&')+'wmode=transparent');
      }
   });
}

function NettoieContenu(src_virtuelle) { //effectué après chaque page loadé
   if (!est_admin)
     try { _gaq.push(['_trackPageview', src_virtuelle]);  } catch(err) {}
   titre_lien = liste_ts[page_active][1]==""?liste_ts[page_active][0]:liste_ts[page_active][1];
   $('#lien_bookmark').attr('href',src_virtuelle).text(titre_lien);
   OuvreTypeArticles();
   OuvreTypeFiches();
   AfficheCAVPatch();
   
   $('#player').stop(true,true).animate({'top':'37px','left':'26%'},{duration:'fast',easing:'easeOutQuad',queue:false});
   
   $('.captcha').attr('src','securimage_show.php?rien='+(Math.random()*10000000));      
   $('.onglets').tabs().css({padding:"0px"});
   $('.ui-tabs-nav').css({margin :"-1.6em 0 0 0",padding:"0px"}).removeClass('ui-widget-header');
   $('.ui-tabs-nav li').ombre('3px -3px 3px rgba(20,20,20,0.2)');
   $('#contenu_pages .menu_vonglets p').addClass('ui-widget-header ui-state-default ui-corner-all');
   $('#contenu_pages .menu_vonglets p').hover(
        function() {if (!$(this).hasClass('ui-state-active')) $(this).addClass('ui-state-hover');},
        function() {$(this).removeClass('ui-state-hover');});
   $('#contenu_pages .accordeon').accordion({'header':'h3.h3_acc',collapsible:true,active:false,autoHeight:false});

   PatchYoutube();
   
   if (!isMSIE || gteIE9) {
       $('#contenu_pages .accordeon h3.h3_acc, #contenu_pages .accordeon > div').ombre('3px 3px 3px #666',false);
       $('#contenu_pages .vonglets, .onglets, #contenu_pages .menu_vonglets p').ombre('3px 3px 7px #666, inset -2px -2px 8px rgba(10,10,10,0.1)',false);//répété au cas où on arrive direct..
       $('#contenu_pages .ui-accordion .ui-accordion-header').css('margin-top','6px');
   }
   $("button, input:submit, input:button").button().css('padding','2px');

   // ----------------------------------------------------------------------
   // traitements spéciaux modules

    if (ZEN('form_plainte') && msg_fiche != "") {
       ZEN('form_plainte').objet.value = msg_fiche;
       msg_fiche = "";
    }

    $('.sommaire_articles img').load(function() {
      SAImg(this);
    });

    if (!est_admin || (!ZEN('cachette_admin_aj_elem') && page_active != liste_mod['art']  && page_active != liste_mod['fiche'])) {
        initColorBox('Aperçus','apercu',false);        // initialiser le lighbox avec les aperçus !
        $('#contenu_pages .apercu_iframe').colorbox({close:'Fermer',transition: 'fade',speed: 450,width:'96%',height:'96%',iframe:true});//width:$('body').width()-100,height:$('body').height()-20

        if ($('#contenu_pages .zentogglebox')[0]) {
            $('#contenu_pages .elements, #contenu_pages .elements_absolu, #contenu_pages .pa_cat').each(function() {
              var el = $(this);
              if (el.find('.zentogglebox')[0]) {
                el.find('h1,h2,h3,h4').filter(':first').click(function() {
                   el.find('.zentogglebox').stop(true,true).fadeToggle('fast');
                }).hover(function() {$(this).addClass('ztb_handle_hover');},function() {$(this).removeClass('ztb_handle_hover');})
              }
            });
        }
      if (zenMp3Listener.isPlaying) {
        $('.extrait').removeClass('encours');
        $('.extrait').each(function(){
            if ($(this).attr('onclick')) {
                test = $(this).attr('onclick').toString();
                if (test.indexOf(zenMp3Listener.url) > 0) $(this).addClass('encours');
            }
        });

      }
      $('.extrait').hover(function(){$(this).addClass('ehover');},function(){$(this).removeClass('ehover');});

    }
    if (ZEN('pa_liste')) {
      c1 = $('#pa_liste .colonne_gauche>div');
      c2 = $('#pa_liste .colonne_droite>div');
      //drole de classement, ça donne en gros, les plus "volumineux" en haut...
      c1.find('.pa_cat:odd').each(function() { if ((c1.height() - c2.height() > $(this).height())) c2.append($(this)); });
      chklast = c1.find('.pa_cat:last');
      while (c1.find('.pa_cat')[1] && (c1.height() - c2.height() > chklast.height())) {c2.append(chklast); chklast = c1.find('.pa_cat:last');}
      
      initColorBoxAnnonces();
      $('.pa_cat li a').hover(function() {$(this).parent().parent().addClass('pa_li_hover');},function() {$(this).parent().parent().removeClass('pa_li_hover');});
      PaInitial();
    }

    if (ZEN('album_premiere_page')) {
      $('#album_table_matieres').addClass('ombre').addClass('ui-widget-content').addClass('ui-corner-all');
      setTimeout("AfficheAlbumThumbs(ZEN('album_premiere_page').innerHTML);",50);
    }
    if (ZEN('grille_cal_ev')) {
      GetCalEv(0);
      $('.cal_ev_legende').hover(function(){$(this).addClass('cev_lhover');},function(){$(this).removeClass('cev_lhover');});
    }
    
    if (!est_admin) $('#contenu_pages').prepend('<iframe src="http://www.facebook.com/plugins/like.php?href='+encodeURIComponent(url_base+src_virtuelle)+'&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;font&amp;colorscheme=dark&amp;height=25" scrolling="no" frameborder="0" class="zenfb_jaime" allowTransparency="true"></iframe>');


    // ----------------------------------------------------------------------
    // traitements spéciaux admin
    if (est_admin) {
          CorrigeOptionsAdmin();
          //if (ZEN('registre_utilisateurs')) getRegistre();
    }


   // ancien traitement conservé pour IE7 et plus petit... au cas où
   if (isMSIE && !gteIE7) {
       var cp = ZEN("contenu_pages");
       for (i in cp.childNodes) {
         var child = cp.childNodes[i];
         if (child && child.tagName == 'DIV') {
            vide = true;
            if (child.className == "colonnes") {
              for (j in child.childNodes) {
                 col = child.childNodes[j];
                 if (col.tagName == 'DIV') {
                   if (col.innerHTML.replace(' ','').length > 0)
                    vide = false;
                   else
                    col.style.display = 'none';
                 }
             }
            }
            else if (child.innerHTML.replace(' ','').length > 0) vide = false;

            if (vide) {
              child.style.display = 'none';
            }
         }
       }
   }
   // -- fin ancien traitement...



   //<script src="http://connect.facebook.net/fr_CA/all.js#xfbml=1"></script><fb:like href="" show_faces="true" width="450" font=""></fb:like>
  // bonne page du calendrier ? histo pour le rest.. ?
//   bypass_histo = true;
// window.location.href=url_base+'#/'+liste_fp[page_active]+'.php'+(article_actif>0?"?art="+article_actif:"");
 // ne semble pas fonctionner avec l'historique, surdefinir notre systeme, alors beaucoup de tests s'imposent !!
 // inverser la question ? loader la bonne page sur "onHistoryChange avec la string dans l'URL???

}
var requete_visiteur = "";
var showContenu = function(str) {
  //GetToTop();
  $("#cherche_contenu").css('display','none');
  //FermeBarreDroite();

  $("#contenu_pages").html(str);
  if (est_intra) CheckTimeup();

  edition_active = false;
  if ($('#zen_edition_active').dialog('isOpen')) $('#zen_edition_active').dialog('close');

  if (requete_visiteur != "" && ZEN('form_plainte')) {
      ZEN('form_plainte').objet.value=requete_visiteur;
      requete_visiteur = "";
  }

  q = '';
  if (!q_cc_vide)
   q = ZEN('q_cc').value;

  if (liste_mod['art'] == page_active && ZEN('q_art') && q == "")
   q = ZEN('q_art').value;

  if (liste_mod['fiche'] == page_active && ZEN('q_fiche') && q == "")
   q = ZEN('q_fiche').value;

  if (q.replace(/\s{1,}/g,'').length > 2) {
      question = PrepareQ(q);
      Highlight(ZEN("contenu_pages"),question);
  }

  p = page_active;
  titre = "";
  if (section_active != 1)  //retire le mot "Accueil"
      titre = liste_sect[section_active];
  t2 = liste_ts[p][1];
  if (t2 == "") t2 = liste_ts[p][0];
  src_virtuelle = liste_fp[p]+'.php';
  titre_mod = false;
  if (liste_mod['art'] != p && liste_mod['fiche'] != p) {     
     article_actif = 0;
     fiche_actif = 0;
     if (!est_admin && !cache_pages[page_active])
        cache_pages[page_active] = str;
  }
  else {
     if (liste_mod['art'] == p) {
        if (objlu != "" && ZEN('masklu')) {
            $(objlu).addClass('lu');
            if ($('#masklu')[0].checked) $(objlu).slideUp();
        }
        if (article_actif > 0) {
           if (ZEN('titre_article')) {
               titre = ZEN('titre_article').innerHTML;
               titre_mod = true;
           }
           if ($('#src_article_actif')[0]) src_virtuelle = $('#src_article_actif').text();
           //ZEN('option_URL').value += '?art='+article_actif;
           if (!cache_art[article_actif])
            cache_art[article_actif] = str;
        }
        else {
           if (!est_admin && !cache_pages[page_active])
            cache_pages[page_active] = str;
        }
     }
     if (liste_mod['fiche'] == p) {
        /*if (objlu != "" && ZEN('masklu')) {
            $(objlu).addClass('lu');
            if ($('#masklu')[0].checked) $(objlu).slideUp();
        }*/
        if (fiche_actif > 0) {
           if (ZEN('titre_fiche')) {
               titre = ZEN('titre_fiche').innerHTML;
               titre_mod = true;
           }
           if ($('#src_fiche_actif')[0]) src_virtuelle = $('#src_fiche_actif').text();
           //ZEN('option_URL').value += '?fiche='+fiche_actif;
           if (!est_admin && !cache_fiche[fiche_actif])
            cache_fiche[fiche_actif] = str;
        }
        else {
           if (!cache_pages[page_active])
            cache_pages[page_active] = str;
        }
     }
  }
  if (!titre_mod) {
     if (titre == "") titre += t2;
     else if (titre != t2) titre += " - "+t2;
  }
  document.title = (est_admin?'ADMIN':titre_site)+" - "+titre;

  effacer_photo = false;
  
  if (!isMSIE || gteIE9) {
        //$('.fond_site').stop(true,true).fadeTo('fast',0.65);
        //if ($('#contenu_pages').html().length>0) // évite de "bouncer" les modules d'archives sous le contenu normal, si complètement vide..
        // mais bloque l'affichage de "j'aime"
          $('#contenu_pages').stop(false,true).css('opacity',0.3).slideDown({duration:'fast',easing:'easeOutQuart',queue:false}).fadeTo({duration:320,queue:false},1);
    //      $('#contenu_pages').stop(true,true).css('opacity',0.1).fadeTo('slow',1);
  }
  NettoieContenu(src_virtuelle);
/*
 *    if (!est_admin) {
    try { _gaq.push(['_trackPageview', src_virtuelle]);  } catch(err) {} 
  }
*/
  /*if (IE6 && !est_admin) supersleight.run();
   * // à voir si c'est nécessaire...
   **/
}

var registre_actif = false;
function getRegistre() {
  if (ZEN('registre_timer') && registre_actif)
    $('#registre_conteneur').css('display','block').fadeTo('fast',0.92);
    $.get('zen_registre.php',function(s) {
        $('#registre_utilisateurs').html(s);
        CheckTimeup();
        //setTimeout("getRegistre();", 120000);
        $('#registre_timer').stop(false).css({backgroundColor:'#000000',width:'98%'}).animate({width:'1%',backgroundColor:'#eecc99'},120000,'linear',function() {getRegistre() });
    });
}

function getContenuPatch(p) { /* Patch pour l'historique (retour du iframe..) */
   GetToTop();
   if (!isMSIE || gteIE9) {
           //$('.fond_site').stop(true,true).fadeTo('fast',1);
           $('#contenu_pages').stop(true,true).fadeOut({duration:'fast',queue:false}).slideUp({duration:'fast',easing:'easeOutQuart',queue:false});
      //      $('#contenu_pages').stop(true,true).fadeOut({duration:'fast',queue:false});
   }
   $.colorbox.close(); // au cas où.. (piton "back" historique..)

   s =  liste_ts[p][3];
   section_active = s;
   page_active = p;

   art = ""   
   if (p == liste_mod['art']) {
      getArchivesArticles();
      if (article_actif > 0) art = "&art="+article_actif;
      if (art == "") art = "&art=0";
   }
   else {
       article_actif = -1;
       $('#archives_articles').hide();
   }

   fiche = ""
   if (p == liste_mod['fiche']) {
      getArchivesFiches();
      if (fiche_actif > 0) fiche = "&fiche="+fiche_actif;
      if (fiche == "") fiche = "&fiche=0";
   }
   else {
       fiche_actif = -1;
       $('#archives_fiches').hide();
   }

   bp = "";
   if (est_admin) {
      bp = adbp; adbp = ""; // bypass pages temporaires :)
      $.get('zen_contenu_pages.php?p='+p+art+fiche+bp, showContenu);
   }
   else {
      charge = false; // vérifie les différents cache avant de charger
      if (p == liste_mod['art'] && article_actif > 0){
        if (cache_art[article_actif]) {
         showContenu(cache_art[article_actif]);
         $.get('zen_historique.php?session=1&p='+p+art);
        } else charge = true;
      }
      else if (p == liste_mod['fiche'] && fiche_actif > 0) {
        if (cache_fiche[fiche_actif]) {
         showContenu(cache_fiche[fiche_actif]);
         $.get('zen_historique.php?session=1&p='+p+fiche);
        } else charge = true;
      }
      else if (cache_pages[p]) {
         showContenu(cache_pages[p]);
         $.get('zen_historique.php?session=1&p='+p+art+fiche);
      } else charge = true;

      if (charge) $.get('zen_contenu_pages.php?p='+p+art+fiche, showContenu);
   }
   
}

var alterne_img = 0;
var histo_iframe = true;
var capture_lien = false;

function getContenu(p) {

 if (est_admin || page_active != p || (p == liste_mod['art']) || (p == liste_mod['fiche'])) {
  //if (capture_lien) {CaptureLien(p);}
  //else
  if (CheckEdition()){
   histo_iframe = false;
   ZEN('iframe_historique').src='zen_historique.php?p='+p;
   if (p == liste_mod['art'])
       article_actif = 0;
   if (p == liste_mod['fiche'])
       fiche_actif = 0;
   getContenuPatch(p);
  }
 }
}

var dernier_q_cc = "_rien_";
function PrepareQ(q,o) {
   q = q.replace(/[eéèêë]/gi,"[eéèêë]");
   q = q.replace(/[aàâä]/gi,"[aàâä]");
   q = q.replace(/[iîï]/gi,"[iîï]");
   q = q.replace(/[oôö]/gi,"[oôö]");
   q = q.replace(/[uùûü]/gi,"[uùûü]");
   q = q.replace(/[cç]/gi,"[cç]");
   q = q.replace(/^[\s,;:!\.?+]+/g,'').replace(/[\s,;:!\.?+]+$/g,''); //trim
   if (o === undefined) o = "gi";
   return new RegExp("("+q.replace(/[\s,;:!\.?+]+/g,")|(")+")",o);
}



var showChercheContenu = function(str) {
   ZEN('cherche_contenu').innerHTML = str;
   if (ZEN('cherche_contenu').style.display != "block")
      Ouvrir('cherche_contenu');
      question = "";
      result = new Array();

      nb_res = 0;
      if (ZEN('rcpt')) {
         for (p in liste_ts)
            if (ZEN('rcc'+p)) {
               result[nb_res] = new Array(liste_sect[liste_ts[p][3]],liste_ts[p][0],p,0);
               nb_res++;
            }
      }
      else {
         question = PrepareQ(dernier_q_cc);
         for (p in liste_ts) {
            s_test = liste_sect[liste_ts[p][3]]+" "+liste_ts[p][0]+" "+liste_ts[p][1];
            if (ZEN('rcc'+p) || s_test.search(question) > -1) { // checker noms fichier aussi ? || question.test(liste_fp[c][i][j])
               result[nb_res] = new Array(liste_sect[liste_ts[p][3]],liste_ts[p][0],p,0);
               nb_res++;
            }
         }

         for (p in liste_le) {
            s_test = liste_le[p][0]+" "+liste_sect[liste_le[p][3]];
            if (s_test.search(question) > -1) {
               result[nb_res] = new Array(liste_sect[liste_le[p][3]],liste_le[p][0],p,1,liste_le[p][1]);
               nb_res++;
            }
         }
      }

      lst = "<ul>";

      result.sort(function(a,b) {return zenStr(a[0])>zenStr(b[0]);});
      last_titre = "";
      for (p in result) {
        if (last_titre != result[p][0]) {
           last_titre = result[p][0];
           nb_res++;
        }
      }
      nb_div = Math.ceil(nb_res / 3);
      if (nb_div<3) nb_div=3;
      i = 0;
      last_titre = "";
      cols = 1;
      next = nb_div;
      for (p in result) {
         if (i>0 && (i > next) && (cols < 3)) {
            lst += "</ul><ul>";
            cols++;
            next += nb_div;
            // RÉPÉTER LE TITRE SI ON CHANGE DE COLONNE...
            if (last_titre == result[p][0]) {
               lst += "<p>"+last_titre+"</p>";
            }
         }
         if (last_titre != result[p][0]) {
            last_titre = result[p][0];
            lst += "<p>"+last_titre+"</p>";
            i++
         }
         i++;
         if (result[p][3] == 0)
            lst += '<li class="cmr_int" onmouseover="this.className=\'cmr_int_over\';" onmouseout="this.className=\'cmr_int\';" onclick="getContenu('+result[p][2]+');">'+result[p][1]+'</li>';
         else
            lst += '<li class="cmr_ext" onmouseover="this.className=\'cmr_ext_over\';" onmouseout="this.className=\'cmr_ext\';" onclick="window.open(\''+result[p][4]+'\',\'_BLANK\')">'+result[p][1]+'</li>';

      }

      lst += "</ul>";
      if (nb_res == 0) lst = "<h4 style='text-align:center;'>Aucun résultats</h4>";

      ZEN('cherche_contenu_resultats').innerHTML += lst;
      if (question != "") {
          Highlight(ZEN('cherche_contenu_resultats'),question);
          if (ZEN('resultats_annonces')) Highlight(ZEN('resultats_annonces'),question);
      }

}

var pa_cc = -1;
function ChercheContenu(q) {
 if (!q_cc_vide && !edition_active) {

  if (q.replace(/\s{1,}/g,'').length > 2) {
   if (q == dernier_q_cc) {
    if (ZEN('cherche_contenu').style.display != "block")
      Ouvrir('cherche_contenu');
   }
   else {
      ZEN('cherche_contenu').innerHTML = "<h4>Recherche en cours . . .</h4>";
      q_ajax = encodeURIComponent(q);
      $.get('zen_cherche_contenu.php?q='+q_ajax, showChercheContenu);  
      try { _gaq.push(['_trackEvent', 'Recherche dans tout le contenu', q]);   } catch(err) {}
   }
   getArchivesArticles(q);
   getArchivesFiches(q);
   pa_cc = page_active;
   page_active = -1;
   article_actif = -1;
   fiche_actif = -1;
   ZEN("contenu_pages").innerHTML = "";   
  }
  else {
       ZEN('cherche_contenu').innerHTML = '<div style="padding: 4px; position:relative;">'+
'<img style="cursor : pointer; position:absolute; top: 2px; right: 2px; width:20px; z-index : 10;" onclick="FermerChercheContenu();" src="images/fermer.png" title="Fermer la recherche" />'+
'<h4>Entrez au moins trois lettres pour chercher dans tout le site</h4></div><div class="cherche_contenu_resultats"></div>';
       if (ZEN('cherche_contenu').style.display != "block")
         Ouvrir('cherche_contenu');
   }
 }
 
 dernier_q_cc = q;
}
function FermerChercheContenu() {
   ZEN('cherche_contenu').style.display='none';
   if (page_active == -1) getContenu(pa_cc);
}

function Vide_q_cc() {
  if (!q_cc_vide) {
   $('#q_cc').val('');
   cc_blur(ZEN('q_cc'));
   if (page_active > 0) {
     getContenuPatch(page_active);
     //if (cache_pages[page_active]) showContenu(cache_pages[page_active]);
     //else getContenu(page_active);
   }
  }
}

var q_cc_vide = true;
function cc_blur(obj) {   
   if (obj.value == "") {
      obj.style.color = "#999999";
      obj.style.fontStyle = "italic";
      obj.value = "Chercher dans le contenu";
      q_cc_vide = true;
   }
}
function cc_click(obj) {
   if (q_cc_vide) {
      obj.style.color = "#000000";
      obj.style.fontStyle = "normal";
      obj.value = "";
      q_cc_vide = false;
   } else obj.select();
}

var menu_q_vide = true;
function cm_blur(obj) {
   if (obj.value == "") {
      obj.style.color = "#999999";
      obj.style.fontStyle = "italic";
      obj.value = "Chercher dans le menu";
      menu_q_vide = true;
   }
}
function cm_click(obj) {
   if (menu_q_vide) {
      obj.style.color = "#000000";
      obj.style.fontStyle = "normal";
      obj.value = "";
      menu_q_vide = false;
   } else obj.select();
}





function OuvreTypeArticles() {
  if (ZEN('type_article_actif')) { taa = parseInt(ZEN('type_article_actif').innerHTML); if (ZEN('artmenu_vonglet_'+taa)) ChangeVOnglet(taa,'art'); }
}

var dernier_q_art = "_tous_";
//var aa_temp = "";

function NettoieAArticles() {
   OuvreTypeArticles();
   $('#archives_articles>.contenant_vonglets>.vonglets').css('margin','-11px 0px 10px 0px');
   $('#archives_articles .menu_vonglets p').addClass('ui-state-default ui-corner-all');
   $('#archives_articles .menu_vonglets p').hover(
        function() {if (!$(this).hasClass('ui-state-active')) $(this).addClass('ui-state-hover');},
        function() {$(this).removeClass('ui-state-hover');});
   $('#archives_articles .accordeon').accordion({'header':'h3.h3_acc',collapsible:true,autoHeight:false});
   if (!isMSIE || gteIE9) {
      $('#archives_articles .accordeon h3.h3_acc, .accordeon > div').ombre('3px 3px 3px #666',false);
      $('#archives_articles .menu_vonglets p').ombre('3px 3px 7px #666, inset -2px -2px 8px rgba(10,10,10,0.1)',false);
      $('#archives_articles .ui-accordion .ui-accordion-header').css('margin-top','6px');
   }
   $("#archives_articles input:button").button().css('padding','2px');
}

var showArchivesArticles = function(str) {
   ZEN('archives_articles').innerHTML = str;
   //aa_temp = str;
   ZEN('archives_articles').style.display = "block";
   q = dernier_q_art;

   if (q.replace(/\s{1,}/g,'').length > 2 && q != '_tous_') {
      question = PrepareQ(q);
      Highlight(ZEN('arch_art_zenlight'),question); //bypass l'entête des archives d'articles, ne fouille que les titres
   }
   
   NettoieAArticles();
}


function getArchivesArticles(q){
   if (q === undefined) {
      q = "_tous_";
      if (ZEN('q_art')) {
       test = ZEN('q_art').value;
       if (test != "") {
           q = test;
           try { _gaq.push(['_trackEvent', 'Recherche spécifiquement dans les articles', q]);   } catch(err) {}
       }
      }
   }
   else {
      if (ZEN('q_art')) {
       ZEN('q_art').value = q;
      }
   }
   if (dernier_q_art != q || ZEN('archives_articles').innerHTML == "") {
      
      if (ZEN('bouton_q_art')) {
         ZEN('bouton_q_art').value='recherche...';
         ZEN('bouton_q_art').disabled=true;
      }
      q_ajax = encodeURIComponent(q);
      // n'est chargé que lorsqu'on en a besoin...
      $.get('zen_archives_articles.php?q='+q_ajax, showArchivesArticles);
   }
   
   if (ZEN('archives_articles').style.display != "block")
      Ouvrir('archives_articles');

   dernier_q_art = q;
}
var objlu = "";

function getArticle(art,obj){
 if (est_admin || art == 0 || art != article_actif) {
  //if (capture_lien) {CaptureLien(liste_mod['art'],art);}
  //else
  if (CheckEdition()){
   objlu = "";
   if (obj !== undefined) objlu = obj;
   histo_iframe = false;
   ZEN('iframe_historique').src='zen_historique.php?p='+liste_mod['art']+'&art='+art;
   article_actif = art;
   if (art==0 && ZEN('q_art')) ZEN('q_art').value = ""; //enleve la recherche si on fait "tout voir"
   getContenuPatch(liste_mod['art']);
  }
 }
}

function EffComm(id) {
    ZenConfirm('<br/><div class="gros zencentre">Êtes-vous certain de vouloir effacer ce commentaire ?</div>', function() {
      $.get('zen_modifier_article.php?effacer_comm='+id, function(s){
        if (s=='OK') {
           $('#app_acomm'+id+',#acomm'+id).fadeOut('fast',function(){$(this).remove();});
           dernier_q_art = ""; //recharger seulement "la prochaine fois"
           //getArchivesArticles();
        } else alert(s);
      });
    }, function(){});
   
}
function AppComm(id) {
    $.get('zen_modifier_article.php?approuver_comm='+id,function(s){
        if (s=='OK') {
            $('#app_acomm'+id+',#acomm'+id).addClass('art_comm').removeClass('art_comm_temp')
            .find('.art_comm_app').remove();
            dernier_q_art = ""; //recharger seulement "la prochaine fois"
           //getArchivesArticles();
        } else alert(s);
    });
}
function CommArt() {
 if (ZEN('art_comm_text') && CheckEdition()) {
     $('#art_comm_msg').text('');
     ZEN('art_comm_text').disabled = true;
     msg = 'Envoi du commentaire';
     valide = true;
     art_comm = ZEN('art_comm_text').value.replace(/\r/g,'').replace(/\n{2,}/g,'\n\n').replace(/\s{4,}/g,' ').replace(/</g,'&lt;');
     
     al = art_comm.length;
     if (al < 3) { valide = false;
         msg = "Message trop court.";
     }else if (al > 250) { valide = false;
         msg = "Message trop long. ("+al+" caractères)";
     }

     art_comm = "artid="+article_actif+"&art_comm="+encodeURIComponent(art_comm);

     if (valide) {
       edition_active = true;
       //alert(art_comm);
       $.post('zen_modifier_article.php',art_comm,function(s){
            edition_active = false;
            if (s=='OK') {
                $('#art_comm_msg').text('Le commentaire a été soumis.').fadeIn();
                page_active=-1;//bypass..
                if (super_admin) dernier_q_art = ""; //puisqu'on est certain que c'est auto-approuvé
                setTimeout("getArticle(article_actif);",700);
            } else {
                $('#art_comm_msg').text(s).fadeIn();
                ZEN('art_comm_text').disabled = false;
            }            
       });
     } else {
         edition_active = false;
         ZEN('art_comm_text').disabled = false;
     }

     $('#art_comm_msg').text(msg).fadeIn();
 }
}

/* **************----------------*********************************************
*/

function OuvreTypeFiches() {
  if (ZEN('cat_fiche_actif')) { cfa = parseInt(ZEN('cat_fiche_actif').innerHTML); if (ZEN('fichemenu_vonglet_'+cfa)) ChangeVOnglet(cfa,'fiche'); }
}

var dernier_q_fiche = "_tous_";
//var aa_temp = "";

function NettoieAFiches() {
   OuvreTypeFiches();
   $('#archives_fiches .menu_vonglets p').each(function(){reculeElem(this,'a',function(a,b) {return zenStr(a)<zenStr(b);})});
   $('#archives_fiches .menu_vonglets p').addClass('ui-state-default ui-corner-all');
   if (!isMSIE || gteIE9) $('#archives_fiches .vonglets, #archives_fiches .menu_vonglets p').ombre('3px 3px 7px #666, inset -2px -2px 8px rgba(10,10,10,0.1)',false);
   $('#archives_fiches .menu_vonglets p').hover(
    function() {if (!$(this).hasClass('ui-state-active')) $(this).addClass('ui-state-hover');},
    function() {$(this).removeClass('ui-state-hover');});
   $('#archives_fiches .vonglets div').hover(
    function () { $(this).addClass('fichelist_hover'); }, 
    function() { $(this).removeClass('fichelist_hover'); });
   $("#archives_fiches input:button").button().css('padding','2px');

   // stop propagation sur tous les icônes dans les archives (liens directs)...
   //$('#archives_fiches .af_opt').click(function(e){e.stopPropagation();});
   // BLOQUE AUSSI LE COLORBOX !! :(
   $('#archives_fiches .af_opt')    
    .hover(function(){$(this).css('background-color','#111111')},function(){$(this).css('background-color','transparent')})
    .addClass('ui-corner-all').ombre('1px 1px 4px #222,inset 2px 2px 4px #ddd');

   $('#archives_fiches .apercu_iframe').colorbox({close:'Fermer',transition: 'fade',speed: 450,width:'96%',height:'96%',iframe:true});


}
var showArchivesFiches = function(str) {
   ZEN('archives_fiches').innerHTML = str;
   //aa_temp = str;
   ZEN('archives_fiches').style.display = "block";
   q = dernier_q_fiche;
   if (q.replace(/\s{1,}/g,'').length > 2 && q != '_tous_') {
      question = PrepareQ(q);
      Highlight(ZEN('arch_fiche_zenlight'),question); //bypass l'entête des archives d'articles, ne fouille que les titres
   }
   NettoieAFiches();
}


function getArchivesFiches(q){
   if (q === undefined) {
      q = "_tous_";
      if (ZEN('q_fiche')) {
       test = ZEN('q_fiche').value;
       if (test != "") {
           q = test;
           try { _gaq.push(['_trackEvent', 'Recherche spécifiquement dans les fiches', q]);   } catch(err) {}
       }
      }
   }
   else {
      if (ZEN('q_fiche')) {
       ZEN('q_fiche').value = q;
      }
   }
   if (dernier_q_fiche != q || ZEN('archives_fiches').innerHTML == "") {

      if (ZEN('bouton_q_fiche')) {
         ZEN('bouton_q_fiche').value='recherche...';
         ZEN('bouton_q_fiche').disabled=true;
      }
      q_ajax = encodeURIComponent(q);
      // n'est chargé que lorsqu'on en a besoin...
      $.get('zen_archives_fiches.php?q='+q_ajax, showArchivesFiches);
   }

   if (ZEN('archives_fiches').style.display != "block")
      Ouvrir('archives_fiches');

   dernier_q_fiche = q;
}
//var objlu = "";

function getFiche(fiche){//,obj
 if (est_admin || fiche == 0 || fiche != fiche_actif) {
  //if (capture_lien) {CaptureLien(liste_mod['art'],art);}
  //else
  if (CheckEdition()){
   //objlu = "";
   //if (obj !== undefined) objlu = obj;
   histo_iframe = false;
   ZEN('iframe_historique').src='zen_historique.php?p='+liste_mod['fiche']+'&fiche='+fiche;
   fiche_actif = fiche;
   if (fiche==0 && ZEN('q_fiche')) ZEN('q_fiche').value = ""; //enleve la recherche si on fait "tout voir"
   getContenuPatch(liste_mod['fiche']);
  }
 }
}




/* ********************************** COMMENTAIRES ET SUGGESTIONS **************************************** */
    var backPlainte = function(str) {
       if (ZEN('msg_plainte')) {
          if (str=="OK") {
             ZEN('form_plainte').style.display = 'none';
             ZEN('msg_plainte').innerHTML = "<div class='note'>Un courriel a été envoyé à un responsable. Merci d'avoir utilisé ce service.</div>";
          }
          else {
             ZEN('msg_plainte').innerHTML = str;
             ZEN('form_plainte').code.value="";
             ZEN('img_captcha_plainte').src='securimage_show.php?sid='+(Math.random()*1000000000);
          }
       }
    }
    var msg_fiche = "";
    function CommentaireFiche() {
        msg_fiche = "Commentaire sur une fiche : "+$('#titre_fiche').text();
        getContenu(liste_mod['commentaires']);
    }

    function ValidePlainte() {
      if (f = ZEN('form_plainte')) {
        message = "";

        if (f.nom.value == "") message += "Vous devez entrer un nom.<br />";

        testc = f.courriel.value;
        testl = testc.length;
        at_pos = testc.indexOf("@");
        dot_pos = testc.lastIndexOf(".");

        if ((testl < 8) || at_pos == null || dot_pos == null || (at_pos < 1) || (dot_pos < (at_pos+2)))
            message += "Vous devez entrer un courriel valide.<br />";

        tel = f.telephone.value;
        len = tel.replace(/[^0-9]/gi,'').length;
        if (len != 10)
           message += "Vous devez entrer un numéros de téléphone valide, à 10 chiffres,<br />par exemple (819) 555-5555 ou encore 8195555555.<br />";

        if (f.objet.value == "") message += "Vous devez entrer un sujet.<br />";
        if (f.description.value == "") message += "Vous devez écrire un commentaire.<br />";

        if (message == "") {
           $.post('zen_traite_commentaires.php',$('#form_plainte').serialize(),backPlainte);
        }
        else {
         message = '<div class="avertissement">'+message+'</div>';
         ZEN('msg_plainte').innerHTML = message;
        }
      }
    }
/*********************   fonctions pour les UTILISATEURS        ************************************/
  /*********************--------------------------------------************************************/

   function SoumettreOptionsUtilisateur() {
      f = document.form_options_utilisateur;
      msg = "";
      // valider le mot de passe
      if (f.pwd_temp.value.length > 0) {
                p1 = f.pwd_temp.value;
                p2 = f.pwd_temp2.value;
                if (p1 < 6) 
                  msg += "Le mot de passe est trop court.<br />";
                if (p1 == p1.toLowerCase()) 
                  msg += "Le mot de passe doit contenir des majuscules ET minuscules.<br />";
                if (p1.search(/[0-9]/) == -1) 
                  msg += "Le mot de passe doit contenir des chiffres.<br />";
                if (f.pwd_temp.value != f.pwd_temp2.value) 
                  msg += "Les deux mots de passes ne correspondent pas.<br />";
                if (msg == "") {
                  f.pass.value = SHA1(p1);
                  f.pwd_temp.value = "";
                  f.pwd_temp2.value = "";
                }
      }

      if (msg == "") {
        $('#label_pwd_temp').removeClass('ui-state-error').addClass('ui-state-highlight')
        .html('Enregistrement en cours...').fadeIn();
        //écrire quelquepart que ça s'enregistre...

        $.post('zen_modifier_utilisateurs.php',$(f).serialize(),
         function(msg){
            if (msg.substr(0,3) == '!!!') {
              $('#label_pwd_temp').removeClass('ui-state-highlight').addClass('ui-state-error')
              .html(msg.substr(3));
            }
            else {
               $('#nom_utilisateur_span').text(document.form_options_utilisateur.nom.value);
               $('#label_pwd_temp').html(msg);
               setTimeout("$('#div_options_utilisateur').dialog('close');",500);
            }
        });
      }
      else
        $('#label_pwd_temp').removeClass('ui-state-highlight').addClass('ui-state-error')
        .html(msg).fadeIn();
   }
   
   function OptionsUtilisateur(id) {       
     if (CheckEdition()) {
        $('#label_pwd_temp').hide();
        $('#div_options_utilisateur').dialog('option',{position : ['center',150]});
        $('#div_options_utilisateur').dialog('open');
         f = document.form_options_utilisateur;
         f.id.value = id;
         f.nom.value = $('#nom_utilisateur_span').text();
         f.nom.focus();
         f.pwd_temp.value = "";
         f.pwd_temp2.value = "";
     }
   }
 if (isMSIE && !gteIE9) {
     var str = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,mark,menu,meter,nav,output,progress,section,time,video";
     var list = str.split(","); for(i = 0; i < list.length; i++) {document.createElement(list[i])}
    }
$(document).ready(function() {     
   


       if (est_intra) {
        $.ajaxSetup({
            beforeSend : function(xhr){ xhr.setRequestHeader("X-uzen", xuzen) }
        });

        $('#div_options_utilisateur').dialog({
            autoOpen: false, modal : true, show : 'fade', hide : 'fade', resizable : false,
            width: 520, minWidth : 520, close : function() {edition_active=false;}
	});
       }
       

   // ******* Trucs d'admin si c'est le cas...

   if (est_admin) AdminReady();


   // ******* Autocomplete pour chercher dans le menu

   source_ac = new Array();
   i = 0;
   for (j in liste_ts) {
       l = liste_ts[j][0];
       if (liste_ts[j][3] != 1) l = liste_sect[liste_ts[j][3]]+' - '+l;
       source_ac[i++] = {label:l,p:j,ext:false};//,s:liste_sect[liste_ts[j][3]]
   }
   for (j in liste_le) {
       l = liste_le[j][0];
       if (liste_le[j][3] != 1) l = liste_sect[liste_le[j][3]]+' - '+l;
       source_ac[i++] = {label:l,p:j,ext:true};
   }
   //ajouter les liens externes
   $('#cherche_menu_q').autocomplete({source:source_ac, select:function(e,ui){
           if (ui.item.ext) // genere encore
              window.open(liste_le[ui.item.p][1],'_BLANK');
           else getContenu(ui.item.p);
           t = ui.item.p+': '+ui.item.label;
           try { _gaq.push(['_trackEvent', 'Page accédée par la recherche rapide du menu', t]);   } catch(err) {}
       }});
   if (est_admin) 
       $('#asp_menu_lien').autocomplete({source:source_ac, select:function(e,ui){
           if (ui.item.ext) { $('#admin_sp_liens_ext').val(liste_le[ui.item.p][1]);
              // AppliqueLienSimple('ext'); //non car on ne garde pas la sélection quand on change le focus vers la recherche.. :(
           }
           else { SelectValeur(ZEN('admin_sp_liens_int'),ui.item.p);
               //AppliqueLienSimple(); //non car on ne garde pas la sélection quand on change le focus vers la recherche.. :(
           }
       }});
   $('.ui-autocomplete').addClass('ombre');


/*   // ******* Menu de thème
   tr = "";

   menuthemes = "<center class=\"zenbox ui-widget-content ui-corner-all ombre\" style=\"position:relative; margin:10px;\">"+
            "Thème : <select id='theme_sel' style=\"width:130px; margin:3px;\" onchange=\"$('#ui-theme-link').attr('href','themes/'+$(this).val()+'/jquery-ui-.custom.css');\">"
   for (i in UIthemes) {
       menuthemes += '<option value="'+UIthemes[i]+'">'+UIthemes[i]+'</option>';
   }
   menuthemes += '</select>'+tr+'</center>';
   $('.element_menu').after($(menuthemes));

*/

  // ******* Comportement du menu
  if (!est_admin) $('.fantome').hide();

  $('#menu li ol').css({
    display: "none"
  });

  $('#menu>ol>li>ol>li').hoverIntent(function() {
      if (!$(this).hasClass('contenu_section')) $(this).addClass('menu_hover');
  }, function() {
      $(this).removeClass('menu_hover');
  });

$('#menu>ol>li').each(function(){// initialisation..
  if ($(this).find('ol')[0]){
    csmol=$('<ol class="smol"></ol>');
    csmol.css({'z-index':10});
    if ($(this).find('.contenu_section')[0]) {
     cs=$('<ol></ol>').append($(this).find('.contenu_section')[0]);
     cs.css({left:'436px',width:'240px'});//,'z-index':100,width:'320px',
     csmol.css({width:'475px'});
     $(this).append(cs);     
     /*var i = 0;   var s = $(this).find('ol>li').length;//retirer ceux dont la valeur est 99 du résultat ?
     h = Math.ceil(s/2);   sol1 = // créer un nouveau "ol", etc....
     if (s>1) {  $(this).find('.sol0>li').each(function(){ i++; if (i>h) sol1.append(this); }); }
     // ajouter le sol1 et recalculer largeur csmol
     */
    }
    $(this).append(csmol);
  }
 });

  $('#menu>ol>li').hoverIntent(function() { // intent IMPORTANT pour l'animation
      mh = 0;
      clhover='menu_hover'; if (!isMSIE || gteIE9) clhover+=' ombre';
      $(this).find('ol').each(function(){if (!$(this).hasClass('smol') || edition_active) {h = $(this).height(); if (h>mh) mh=h;}});
      $(this).find('.smol').css({'height':mh});//,opacity:0.4
      $(this).addClass(clhover)
        .find('ol').stop(true, true).slideDown({duration: 200, easing: 'swing'});//, queue:false ?
     // $(this).find('.smol').fadeTo('fast',1);
  }, function() {
     if (!super_admin || !(mod_sect_parent != "" && $.contains(this,mod_sect_parent[0]))) {
      $(this).removeClass('menu_hover ombre')
        .find('ol').stop(true,true).hide();
     }
  });

  $('#menu>ol>li').css({
    'background-image':'url(images/carreau_menu.gif)',
    'height':'28px',
    'text-align':'center',
    'margin-bottom':'9px'
  });
  /*.each(function(){
    if ($(this).find('li.r4').length>0) $(this).addClass('reservee r4');
    else if ($(this).find('li.r3').length>0) $(this).addClass('reservee r3');
    else if ($(this).find('li.r2').length>0) $(this).addClass('reservee r2');
    else if ($(this).find('li.r1').length>0) $(this).addClass('reservee r1');
  });
$('.reservee').css('border-bottom','1px dotted #443311');
*/
  // Tri du menu !
  // algo de tri par insertion, jQuery style :)
  // rapide sur une liste presque déjà triée, inversion lente.. !!
   function recule(a){
     while ($(a).prev().length >0 && ($(a).attr('value') - $(a).prev().attr('value') < 0)) {
       pr = $(a).prev();
       pr.before(a);
       a = pr.prev();
     }     
   }
   $('#menu>ol>li').each(function(){recule(this);});

   var iter_menu=0;
   var tresh_menu = 20;
   $('#menu>ol>li').each(function(){
     v = $(this).attr('value');
     if (v >= tresh_menu) {
         $(this).css('margin-top','26px');
         tresh_menu = (Math.floor(v/20)*20)+20;// si premier = 40, next = 60 et non 20+20=40..
     }
     iter_menu++;
   });

   // ******* styles et comportements ajoutés au démarrage

   $('#menu li .smol').addClass('ui-corner-all');
   //$('#entete').addClass('ui-corner-bottom');//ui-widget-content
   $('#cherche_contenu').addClass('ui-widget-content ui-corner-all');
   $('.admin_options')
         .addClass('ui-corner-all')
         .fadeTo('fast',0.6)
         .hover(function(){$(this).stop().fadeTo('fast',1);},function(){$(this).stop().fadeTo('fast',0.6);});

   if (super_admin) {
     $('#menu li').each(function() {
       if ($(this).attr('value') >= 0)
        $(this).attr('title','Ordre: '+$(this).attr('value')+' (Bouton droit pour éditer)');
     });     
   }

   if (!isMSIE || gteIE9) {
       $('#complet').ombre('2px 2px 9px rgba(20,20,20,0.4)');
        $('#cherche_contenu').ombre('4px 4px 12px #675',false);
        $('#menu li>.smol').ombre('3px 3px 12px rgba(10,10,10,0.7), inset 12px 16px 36px rgba(210,210,210,0.3)',false);//, inset -60px -32px 180px rgba(210,230,150,0.4)
        $('.div_form_dialog').parent().ombre('12px 12px 25px #333',false);
        $('#div_options_utilisateur').parent().ombre('12px 12px 25px #333',false);
   }



   // ******* Historique et autres traitements particuliers au PREMIER chargement
   

   histo_iframe = false;
   src_virtuelle = liste_fp[page_active]+'.php';
   if ($('#id_article_actif').length > 0) {
      article_actif = $('#id_article_actif').text();
      // ici il faudrait marquer comme lu l'article en cours dans la liste des archives . .      
      cache_art[article_actif] = ZEN('contenu_pages').innerHTML;       
      ZEN('iframe_historique').src='zen_historique.php?p='+page_active+'&art='+article_actif;
      if (article_actif>0 && $('#src_article_actif')[0]) src_virtuelle = $('#src_article_actif').text();      
   } else if ($('#id_fiche_actif').length > 0) {      
      fiche_actif = $('#id_fiche_actif').text();      
      cache_fiche[fiche_actif] = ZEN('contenu_pages').innerHTML; 
      ZEN('iframe_historique').src='zen_historique.php?p='+page_active+'&fiche='+fiche_actif;
      if (fiche_actif>0 && $('#src_fiche_actif')[0]) src_virtuelle = $('#src_fiche_actif').text();
   } else  {
      cache_pages[page_active] = ZEN('contenu_pages').innerHTML;
      ZEN('iframe_historique').src='zen_historique.php?p='+page_active;  
   }
/* placé dans nettoiecontenu...
   if (!est_admin)
      try { _gaq.push(['_trackPageview', src_virtuelle]);  } catch(err) {}
*/
    // ZEN('option_URL').value += src_virtuelle; ????????6


    // active/config le module d'événement à venir..
    if (ZEN('cev_a_venir')) {
        activite_a_venir = 1; // false par défaut..
        //aav_max = 12; // 6 par défaut..
        if (!ZEN('grille_cal_ev')) GetCalEv(0); // sinon, il sera démarré dans nettoieContenu anyway.. :)
    }

    $('#player img').hover(function(){$(this).addClass('phover')},function(){$(this).removeClass('phover')}).addClass('ui-corner-all');
    $('#playervolume').slider({
       value : 0, slide : function(e,ui){ volume(ui.value)},
       animate : 600, change : function(e,ui){ volume(ui.value)}
    });
    $('#playerposition').slider({
       value : 0, min : 0,max:100, animate : {duration:440,easing:'linear'},
       stop : function(e,ui){ play_position(ui.value)}
    });
    $(window).unload(function() {
      if (ZEN('zenMp3Player')) _getFlashObject().SetVariable("enabled", "false");
    });

   $('#player').draggable();// { containment: 'body'}

   $('#player').hover(function(){
       if ($('#playersonglist').text().length > 0)
        $('#playersonglist').stop(true,true).fadeTo('slow',0.8);
   },function(){
       $('#playersonglist').stop(true,true).fadeOut('fast');
   });

    NettoieContenu(src_virtuelle); //effectué pour chaque pages...
    // puisque "backArchives.." n'est pas exécuté
    if (page_active == liste_mod['fiche']) NettoieAFiches();
    if (page_active == liste_mod['art']) NettoieAArticles();

    $('.sommaire_articles img').each(function() {    //RÉPÉTÉ au cas où il aurait la tête dur...
      SAImg(this);
    });

    /* ne fonctinonne pas ????*/
    //if (IE6 || IE7) $('#complet, .contenant_vonglets, .colonnes').css('height','100%');    // ?????????
    if (IE7) $('#complet').css('height','3000px');

    if (chk_msg_firefox && !isFirefox) {
        ZenConfirm('<div class="avertissement"><h4>Vous devriez utiliser Mozilla Firefox ® pour gérer ce site.</h4> Ce dernier ne prend que quelques minutes à installer et vous facilitera grandement l\'édition tout en donnant de bien meilleur résultats.<br /><br /><img src="images/firefox-logo-wordmark.png" class="img_droite" /><ul><li><u>OK</u> : Continuer vers la page de téléchargement</li><li><u>Annuler</u> : Ignorer cet avertissement</li></ul><div id="msgff_timer" style="position:relative; background-color:#556644; height:4px; margin:2px; width:80%; clear:both;"></div><br /><div class="ui-corner-all ui-state-highlight zenbox zencentre"><a href="http://www.solutions-zen-bamboo.com/pourquoi-firefox.php" target="_BLANK">Découvrez pourquoi nous firefox est préférable avec ce système.</a></div></div>', function() {
            window.open('http://www.mozilla-europe.org/fr/firefox/');
        }, function(){});
        $('#msgff_timer').animate({width:'1%'},12000,'linear',function(){$('#zen_confirm').dialog('destroy');});
    }
    
});

// -----------------------------------------------------------------------------------------------
// fonctions d'animation particulière au clients ....'
// -----------------------------------------------------------------------------------------------

/*
function AnimeCouleur(i) {
   $('#'+i).animate({color:'#ddff77'}, 2200,function() {
       $('#'+i).animate({color:'#331100'}, 1800);
   });
   setTimeout('AnimeCouleur("'+i+'")',8000);
}
*/

var player_pp = "";
var player_firefox = 0;


//<![CDATA[
        	var zenMp3Listener = new Object();

        	/**
        	 * Initialize
        	 */
               
        	zenMp3Listener.onInit = function()
        	{
                   volume(40);
                    $(document).keypress(function (e) {
                            if (!edition_active && e.ctrlKey && e.which == "32") {
                                if (zenMp3Listener.isPlaying == true) pause();
                                else play();
                            }
                        });
                    _getFlashObject().SetVariable("enabled", "true");
        	};
        	/**
        	 * Update
        	 */
                var last_duration = -1;
                var suivant_sent = false;
        	zenMp3Listener.onUpdate = function()
        	{   //console.log('update:'+this.isPlaying);
                        this.isPlaying = (this.isPlaying == "true");
        		var isPlaying = this.isPlaying;
           		var url = this.url;
           		var volume = this.volume;
           		var position = this.position;
                        var duration = this.duration;

                        var id3_artist = this.id3_artist;
                        var id3_album = this.id3_album;
                        var id3_songname = this.id3_songname;
                        var id3_genre = this.id3_genre;
                        var id3_year = this.id3_year;
                        var id3_track = this.id3_track;
                        var id3_comment = this.id3_comment;


                        if (_getFlashObject()) {                           
                            songtxt = "";//"Lecteur en attente...";
                            if (url && url != "undefined") {
                                songtxt = url.substring(url.lastIndexOf('/')+1);
                                if (id3_songname) songtxt = id3_songname;

                                if (id3_artist != "") songtxt = id3_artist+" - "+songtxt;
                                PlayList(url);
                            }
                            if (playlist_curr <= 1) $('#playerprecedent').fadeTo('fast',0.4);
                            else $('#playerprecedent').fadeTo('fast',1);
                            if (playlist_curr >= playlist_size) $('#playersuivant').fadeTo('fast',0.4);
                            else $('#playersuivant').fadeTo('fast',1);


                            $('#playervolume').attr('title','Volume : '+volume+'%');
                            $('#playervolume').slider('value',volume);
                            chargement = "Lecteur en attente...";
                            if (this.bytesPercent > 0) chargement = 'Chargement : '+this.bytesPercent+'% sur '+(Math.round(this.bytesTotal/1024))+'ko'
                            $('#playerposition').fadeTo('fast',this.bytesPercent/100).attr('title',chargement);
                            $('#playerposition').slider('value',Math.ceil((position/duration)*this.bytesPercent));

                            //songtxt += '<br />Position: '+position+" / "+duration+' ms - Chargement: '+this.bytesPercent+'% sur '+this.bytesTotal+' octets';
                            $('#playersongtext').html(songtxt);

                            if (isPlaying && url && url != "undefined" && (this.bytesPercent == 100) && position >= (duration-900)) {
                                if (!suivant_sent && (modeShuffle || playlist_curr < playlist_size)) {
                                    suivant_sent = true;
                                    setTimeout('suivant();',700);
                                    if (!est_admin && !timeShuffle) {
                                        if (id3_songname) songtxt = id3_songname;
                                        songartist = "Artiste non spécifié";
                                        if (id3_artist != "") songartist = id3_artist;
                                        try { _gaq.push(['_trackEvent', 'Écouté jusqu\'à la fin', songartist, songtxt]); } catch(err) {}

                                        // ENVOYER url À UN SCRIPT, ET INCRÉMENTER LE NOMBRE DE LECTURES
                                   //     $.post('zen_stats_ecoute.php',{url:url});
                                    }
                                }
                                $('.extrait').removeClass('encours');
                            } else suivant_sent = false;
                        }
        	};

        	/**
        	 * private functions
        	 */

        	function _getFlashObject() {
        		return document.getElementById("zenMp3Player");
        	}
        	/**
        	 * public functions
        	 */
            var lastPlay = "";
            var initu = inito = "";
            function play(u,options) {              
             if (!ZEN('zenMp3Player')) {
                initu = u; inito = options;
                $('#player').fadeIn(1600);
                $('body').append('<object id="zenMp3Player" style="position:absolute; top:-2px; left -2px;" type="application/x-shockwave-flash" data="player_mp3_js.swf" width="1" height="1"><param name="movie" value="player_mp3_js.swf" /><param name="wmode" value="transparent" /><param name="AllowScriptAccess" value="always" /><param name="FlashVars" value="listener=zenMp3Listener&amp;interval=360" /><p>Vous avez besoin de flash pour jouer les extraits...</p></object>');
                setTimeout('play(initu,inito)',1200);
             } else {
              o = {shuffle:false}//bypass:false,
              if (options !== undefined) $.extend(o,options);

              if (est_admin && edition_active) alert('Vous ne pouvez pas écoutez de musique pendant l\'édition.');
              else {
                isSame = false;
                if (u !== undefined) {
                    if (u != lastPlay) {
                        _getFlashObject().SetVariable("method:setUrl", u);

                        lastPlay = u;
                      //  if (!o.bypass || lastPlay != "")
                    //        if (!est_admin)
                      //          try { _gaq.push(['_trackEvent', 'Extrait démarré', u]); } catch(err) {}
                    } else {
                        if (zenMp3Listener && zenMp3Listener.isPlaying) {
                          if (!o.shuffle) {
                            stop();
                            isSame = true;
                            lastPlay = "";
                          }
                        }
                    }
                }
                $('.extrait').removeClass('encours');
                if (!isSame) {
                    _getFlashObject().SetVariable("method:play", "");
                    if  (!est_admin || !ZEN('cachette_admin_aj_elem')) {
                        $('.extrait').each(function(){
                            if ($(this).attr('onclick')) {
                                test = $(this).attr('onclick').toString();
                                if (u === undefined) u = zenMp3Listener.url;
                                if (test.indexOf(u) > 0) $(this).addClass('encours');
                            }
                        });
                    }
                }
              }
             }
            }
            function pause() {
                _getFlashObject().SetVariable("method:pause", "");
            }
            function stop() {
                _getFlashObject().SetVariable("method:stop", "");
                $('.extrait').removeClass('encours');
                modeShuffle = false;
                $('#playershuffle').attr('src','images/control_aleatoire_non.png');
            }
            function volume(volume) {
                    //var volume = document.getElementById("inputVolume").value;
                    _getFlashObject().SetVariable("method:setVolume", volume);
            }
            function play_position(p) {
                pos = Math.round((zenMp3Listener.duration/100)*p);
                _getFlashObject().SetVariable("method:setPosition", pos);
            }
            var playlist = new Array();
            var playlist_size = 0;
            var playlist_curr = 0;
            function PlayList(u,bp) {
               ajoute = true;
               $('#playersonglist').html('');
               for (i in playlist) {
                   st = "";
                   if (playlist[i] == u) {
                       if (bp === undefined) {
                           playlist_curr = i;
                       }
                       ajoute = false;
                   }
                   if (playlist_curr == i) st=' style="color:#bb3333; font-weight:bold;"';
                   $('#playersonglist').append('<p'+st+'>'+playlist[i].substring(playlist[i].lastIndexOf('/')+1)+'</p>');

               }
               if (ajoute) {
                   playlist_curr = ++playlist_size;
                   playlist[playlist_curr] = u;
                   st=' style="color:#bb3333; font-weight:bold;"';
                   $('#playersonglist').append('<p'+st+'>'+u.substring(u.lastIndexOf('/')+1)+'</p>');
               }
               $('#playersonglist').append('<div class="clearing"></div>');
            }
            function precedent() {
              if (modeShuffle) Shuffle();
              else if (playlist_curr > 1) play(playlist[--playlist_curr]);
            }
            function suivant() {
              if (modeShuffle) Shuffle();
              else if (playlist_curr < playlist_size) play(playlist[++playlist_curr]);
            }

            var nextShuffle = 0;
            var timeShuffle = false;
            var modeShuffle = false;

            // fonction supplémentaires possible (voir code source original...)
//]]>
