jQuery.fn.extend({
  autoModif: function(e,wiki){
  if(wiki==undefined)
   wiki=true;
  var elm1=$(this).eq(0);
  var elm2=$(e).eq(0);
  elm1.focus(function(){
   elm1.data("valeur",elm1.val());
   elm1.data("interval",setInterval(function(){
    if(elm1.data("valeur")!=elm1.val())
    {
     if(wiki)
      elm2.load("/elm/ajax.php?script=wiki",{txt:elm1.val()});
     else
      elm2.text(elm1.val());
     elm1.data("valeur",elm1.val());
    }
   },300));
  }).blur(function(){
   clearInterval(elm1.data("interval"));
   if(wiki)
    elm2.load("/elm/ajax.php?script=wiki",{txt:elm1.val()});
   else
    elm2.text(elm1.val());
   elm1.data("valeur",elm1.val());
  });
  }
});



$(document).ready(function() {
 //en bref
 if($("#enbref>.milieu>div").length>1){
  var taillebref=0;
  $("#enbref>.milieu>div").each(function(){
   if($(this).height()>taillebref)
    taillebref=$(this).height();
  });
  $("#enbref>.milieu").height(taillebref);
  /*
  $("#enbref>.milieu>div:gt(0)").hide();
  
  var bref=$("#enbref>.milieu>div:eq(0)");
  
  setInterval(function(){
   bref.fadeOut(1000,function(){
    bref=bref.next();
    if(bref.length==0)bref=$("#enbref>.milieu>div:eq(0)");
    bref.fadeIn(1000);
   });
  },10000);
  */
$("#enbref>.milieu").cycle({
  timeout:4000,
  speed:1000,
  pause:true
 });
 //$("#enbref>.milieu>div").css({padding: "0 15px"});  
 }
 //bandeau
 $("#bandeau>.images").cycle({
  timeout:8000,
  speed:2000
 });  
 //png ie fix
 $('img[@src$=.png],.haut,.bas').not($("#minimenu>img,.logoccepc>img,.miniature,.ensavoirplus>img")).ifixpng();
 $(".gallerie a:has(img)").lightBox();
 //appel de la météo en Ajax 
 $("#meteo").load("/elm/meteo.php",function(){
  if($.browser.msie || $.browser.safari)
   $(this).css("background-color","#7d677f");
  $(this).hide().fadeIn(500);
 });
 //passage des lien externe en ouverture dans une nouvelle fenetre
 $(".lien_externe").click(function(){
  window.open(this.href);
  return false;
 });
 //bouton tester de l'admin en ajax
 if(droits>0)
  $("#btntester").click(function(){
   $("#zonetest").load(
    "/elm/ajax.php?script=tester&p="+encodeURI($("input[@name=titreold]").val()),
    {
     titreold:$("input[@name=titreold]").val(),
     param:$("textarea#param").val(),
     code:$("textarea#code").val()
    },function(a,b,c){
     //$(this).html(a);
    }
   );
   return false;
  });
 //animation du menu
 var tempsMenu=500;
 if($(".m_sousmenu .courent").length>0)
 {
  $(".m_elm:has(.courent)").addClass("ouvert");
 }
 $("#menu .m_elm").each(function(){
  elm=$(".m_titre",this);
  hauteur=elm.height();
  elm.css({cursor:"pointer"}).addClass((hauteur>=30?"m_t_3":(hauteur>=17?"m_t_2":"m_t_1")));
  if($(".m_sousmenu>div:visible",this).length==0)
   $(this).hide();
  });
 $(".m_elm:not(.ouvert) .m_sousmenu").hide();
 $(".m_elm .m_titre").click(function(){
  $(this).parent().siblings().removeClass("ouvert");
  $(this).parent().toggleClass("ouvert");
  $(".m_elm:not(.ouvert) .m_sousmenu").slideUp(tempsMenu);
  $(".m_elm.ouvert .m_sousmenu").slideDown(tempsMenu);
 });
});
function init_bandeau()
{
 
}

////////////////////////
////////////////////////
////////////////////////

/**
Fonction d'insertion rapide pour l'outil d'édition
*/
function insertTags(tagOpen, sampleText, tagClose) {
 var txtarea=$("textarea#code")[0];
 var selText, isSample = false;

 if (document.selection  && document.selection.createRange) { // IE/Opera

  //save window scroll position
  if (document.documentElement && document.documentElement.scrollTop)
   var winScroll = document.documentElement.scrollTop
  else if (document.body)
   var winScroll = document.body.scrollTop;
  //get current selection  
  txtarea.focus();
  var range = document.selection.createRange();
  selText = range.text;
  //insert tags
  checkSelectedText();
  range.text = tagOpen + selText + tagClose;
  //mark sample text as selected
  if (isSample && range.moveStart) {
   if (window.opera)
    tagClose = tagClose.replace(/\n/g,'');
   range.moveStart('character', - tagClose.length - selText.length); 
   range.moveEnd('character', - tagClose.length); 
  }
  range.select();   
  //restore window scroll position
  if (document.documentElement && document.documentElement.scrollTop)
   document.documentElement.scrollTop = winScroll
  else if (document.body)
   document.body.scrollTop = winScroll;

 } else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla

  //save textarea scroll position
  var textScroll = txtarea.scrollTop;
  //get current selection
  txtarea.focus();
  var startPos = txtarea.selectionStart;
  var endPos = txtarea.selectionEnd;
  selText = txtarea.value.substring(startPos, endPos);
  //insert tags
  checkSelectedText();
  txtarea.value = txtarea.value.substring(0, startPos)
   + tagOpen + selText + tagClose
   + txtarea.value.substring(endPos, txtarea.value.length);
  //set new selection
  if (isSample) {
   txtarea.selectionStart = startPos + tagOpen.length;
   txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
  } else {
   txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
   txtarea.selectionEnd = txtarea.selectionStart;
  }
  //restore textarea scroll position
  txtarea.scrollTop = textScroll;
 } 

 function checkSelectedText(){
  if (!selText) {
   selText = sampleText;
   isSample = true;
  } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char
   selText = selText.substring(0, selText.length - 1);
   tagClose += ' '
  } 
 }
}