
function writeCookie(name,value,days){
  var expires = ""
  if (days) {
    var date = new Date()
    date.setTime(date.getTime() + days * (24*60*60*1000))
    var expires = "; expires = " + date.toGMTString()
  }
  document.cookie = name + "=" + value + expires + "; path=/"
}

function readCookie(name){
  var nameEQ = name + "="
  var ca = document.cookie.split(';')
  for(var i=0; i < ca.length; i++){
    var c = ca[i]
    while (c.charAt(0)==' ') 
      c = c.substring(1,c.length)
    if( c.indexOf(nameEQ) == 0) 
      return c.substring(nameEQ.length,c.length)
  }
  return null
}


/***/

function rnd(mi,ma){
  return Math.floor(mi + Math.random()*(ma-mi+1))
}
  
function chgBG(){
  var n = rnd(1,11);
  if( n < 10) n = '0' + n ;
  $('#header').css('background-image', "url('/img/bandeau-" + n + ".jpg')" )
}

/***/

/* target="..." n'est pas dans la norme XHTML */
function SetTarget(){
 var anchors = document.getElementsByTagName("a");
 for( var i=0; i<anchors.length; i++ ){
   var anchor = anchors[i];
   var rel = anchor.getAttribute("rel");
   if( rel != null) anchor.target = rel;
 } 
}

/***/

function ShowEmail(){
  em = "\x40";
  em = "1piculture2p3pul1ire4gm1il2c3m".replace(/1/g,"a")
                                       .replace(/2/g,".")
                                       .replace(/3/g,"o")
                                       .replace(/4/g,em);
  em = '<a href="mailto:#">#</a>'.replace(/#/g,em);
  $("#emailID").html(em);
}

/***/

function phpBB(fid,path){
  $(fid).attr("src", "http://apiculture-populaire.com/forum/" + path);
  return false;
}

function searchForums(sid){
  return phpBB('#activity', "search.php?search_id=" + sid);
}

function loadForum(sid){
  return phpBB('#forum', "viewforum.php?f=" + sid);
}

function frameHeight(fid){
  var frame = document.getElementById(fid);
  frame.height = frame.contentWindow.document.body.scrollHeight;
}

/***/
$(document).ready(function(){
  $("dl.menu dd").hide()
  var m = readCookie("menu");
  $(m ? m : '#m1').show();
  chgBG();
  $("dl.menu dt").bind("click", function(){
    $("dl.menu dd:visible").slideUp("slow");
    chgBG();
    var elem=$(this).next();
    elem.slideDown("slow");
    writeCookie('menu', "#" + elem.attr("id"));
    return false;
  });
  ShowEmail();
  SetTarget();
})

