function ZAnim(o) {
    delai = 200;
    if (!o.hasClass('en_marche'))  {
        if (o.find('.delai')[0]) delai = parseInt(o.find('.delai').text());
        setTimeout('ChangeZAnim("'+o.attr('id')+'");',Math.ceil(Math.random()*200)+delai);
    }
    o.addClass('en_marche');
}
var zanim_to = new Array();
var zanim_prec = new Array();
function ChangeZAnim(id) {
 if (zanim_to[id]) clearTimeout(zanim_to[id]);
 if (ZEN(id)) {
   var anim = $('#'+id);

   var cache = anim.children('.cachette');
   AE_len = cache.children('a').length;
   src_index = 0;
   if (AE_len > 1) {
       base = cache.children('.base').text(); rand = cache.children('.rand').text();
       zanim_to[id] = setTimeout('ChangeZAnim("'+id+'");',(Math.ceil(Math.random()*parseInt(rand))+parseInt(base)));
       src_index = Math.ceil(Math.random()*AE_len)-1;
       if (zanim_prec[id] || zanim_prec[id] == 0) { //hhmm.. hehehe
          while (zanim_prec[id] == src_index) src_index = Math.ceil(Math.random()*AE_len)-1;//random ??
          zanim_prec[id] = src_index;
       } else zanim_prec[id] = src_index;
   }
   if (AE_len > 0)  {
       var w = anim.width(); var h = anim.height();
       var f_in = parseInt(cache.children('.f_in').text());
       var f_out = parseInt(cache.children('.f_out').text());

       anim.children('img').stop(false,false).css({zIndex:2}).fadeOut(f_out,function(){$(this).remove();});

       itemp = $('<img src="'+$(cache.find('a')[src_index]).attr('href')+'" />')
                .css({top:h,left:w,zIndex:3,opacity:'0.01'})
                .load(function(){Centre($(this),w,h);$(this).fadeTo(f_in,1,'easeOutQuad');});
       anim.append(itemp);
   }
 }
}
function Centre(ae,aew,aeh) {
  var w = ae.width();
  var h = ae.height();
  ft = Math.round((h-aeh)/2) * -1;
  fl = Math.round((w-aew)/2) * -1;
  ae.css({top:ft+'px',left:fl+'px'});
}



