 
 var aCarousel = {
  thirdWidth: 192,
  thirdNum: 1,
  thirdPage: 1,
  currentInc: 0,
  maxHeight: 0,
  scrollTo: function(val){
    $('#carousel li').each(function(i){
      if($(this).attr('rel') == val)
      {
        this.currentInc = Math.floor(i / 3);
        aCarousel.moveBy(this.currentInc);
      }
    });
  },
  resizeCarousel_Timer: false,
 resizeCarousel: function() {
  var range = this.currentInc * 3;
  var maxHeightTmp = 0;
  for(var i = range; i <= range + 2; i++)
  {
    var height = $('#carousel li:eq(' + (i) + ')').height();
    if(maxHeightTmp < height)
     maxHeightTmp = height;
  }
  
  if(maxHeightTmp == this.maxHeight)
    clearInterval(this.resizeCarousel_Timer);
    
  this.maxHeight = maxHeightTmp;
  $('#carousel').animate({height: (maxHeightTmp + 10)}, {queue: false});
 } , 
 actualisePagination:  function() {
  var Base_href = $('#base_href').val();
  $('#aCarousel .util .selected').removeClass('selected').html('<img src="'+Base_href+'img/button.png?"/>');
  $('#aCarousel .util a:eq('+(this.currentInc + 1)+')').addClass('selected').html('<img src="'+Base_href+'img/button_selected.png?" alt="'+(parseInt(this.currentInc )+ 1) +'"/>');
  
  this.resizeCarousel_Timer = setInterval(function(){aCarousel.resizeCarousel()}, 500);
 },
 moveBy: function(inc)
  { 
    var position = inc * 640;
    this.currentInc = inc;
    $('#carousel').animate({opacity: 0.5}).animate({'marginLeft': '-' + position + 'px'}, function(){
       $('#carousel').animate({opacity: 1});}).dequeue();
    this.actualisePagination();
  },
  
  init: function(){
    this.thirdNum =  $('#aCarousel li').size();
    this.thirdPage = Math.ceil(this.thirdNum / 3);
    $('#carousel').width(/*(aCarousel.thirdNum + 2 )* (aCarousel.thirdWidth + 10)*/ 20000);
    $('#carousel li').each(function(i){
	  if(++i % 3 != 0)
	    return;
	  
    $(this).css('border', '1px solid #F7F7F7');
  });
  
  $('#aCarousel .util .changePage').each(function(){
      var page = $(this).html();
      $(this).html('<img src="'+$('#base_href').val()+'/img/button.png?" alt="'+page+'"/>');
    });
  
  $('.changePage').click(function(){
    var inc = $(this).attr('title');
    --inc;
    aCarousel.moveBy(inc);
  });
  
  $('.carousel_before').click(function(){
    if(aCarousel.currentInc > 0)
      aCarousel.currentInc--;
    aCarousel.moveBy(aCarousel.currentInc);
    
  });
  
  $('.carousel_next').click(function(){
    if(aCarousel.currentInc < aCarousel.thirdPage - 1)
      aCarousel.currentInc++; 
      
    aCarousel.moveBy(aCarousel.currentInc);
  });
  
  this.actualisePagination();
  
 }
 };
 
 function utf8_encode ( string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}
 
 function base64_encode( data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
 
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof window['atob'] == 'function') {
    //    return atob(data);
    //}
        
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = utf8_encode(data+'');
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}

 function sendLog()
 {
  var mail = $('#c_login').val();
  var mdp = $('#mdp').val();
  
   $.ajax({
   type: "POST",
   url: $('#base_href').val()+"module/login.php",
   data: "toLogin=true&login=" + mail + "&mdp=" + mdp,
   success: function(msg){
      $('#loginCont').html(msg);
      linker();
      
    $('#ajouter_commentaires').load('form_commentaires.php?id=' + $('#idArt').val());
    
   }
 });
  linker();
  return false;
 }
 
  var linker = function(){
    $('.link').fancybox({ frameWidth: 600, overlayShow: true, overlayOpacity: 0.2});
  } 
  
  function sendComment()
  {
    var mail = $('#c_email').css({border: ''}).val();
    var login = $('#c_login').css({border: ''}).val();
    var commentaire = $('#commentaire').css({border: ''}).val();
    
    var id = ((typeof($('#c_id').val()) != 'undefined') ? $('#c_id').val() : 0);
    var idArt = $('#idArt').val();
    if(id == 0)
    {
      if(mail == '')
        $('#c_email').css({border: '1px solid red'});
        
      if(login == '')
        $('#c_login').css({border: '1px solid red'});
        
      if(mail == '' || login == '')
        return false;
    }
    
    if(commentaire == '')
    {
      $('#commentaire').css({border: '1px solid red'});
      return false;
    }
    
    
    $('#submit').attr('disabled', true).val('En cours ...');
     $.ajax({
     type: "POST",
     url: $('#base_href').val()+"module/sendComment.php",
     data: "ajt=true&login="+ login +"&mail=" + mail + "&comment=" + commentaire + "&c_id="+ idArt +"&id="+ id+"&uri="+base64_encode(window.location),
     success: function(msg){
        $('#submit').attr('disabled', '').val('Envoyer');
          var tutu = eval(msg);
          afficher_commentaire(tutu);
     } 
  });
  
  }
  
function afficher_commentaire(array)
 {
 
    var avatar = array.avatar || $(array).attr('avatar');
    var date = array.date || $(array).attr('date');
    var login = array.login || $(array).attr('login');
    var text = array.comment || $(array).attr('comment');
    var id = array.id || $(array).attr('id');
    var idUsr = array.idUser || $(array).attr('idUser');
    
    var str = '<div class="commentCont"><div class="avatar">' + (( avatar != '') ? '<img src="' + avatar + '" alt="" class="img"/>' : '' ) + '</div>';
    str += 
    '<div class="commentaire">' +
    ' <p class="intitule"> ' +
    '  <span class="post">Post&eacute; par ' + login + ' - </span>' +
    '  <span class="date">' + date + '</span>' +
    ' </p> <p class="c_text">'+
     text + '</p></div><div class="c_user">';
    
    if($('#c_id').val() == idUsr || $('#c_admin').val() == 1) 
     str += '<a href="javascript:;" onclick="modifComment(' + id + ', $(this))">Modifier</a> | <a href="javascript:;" onclick="deleteComment('+id+', $(this))">Supprimer</a>';
    
    str += '</div></div>';
    
    $('#commentaires').show().append(str).find('>div:last').slideDown();
    
  }
  
  function deleteComment(id, where)
  {
    if(confirm('Voulez vous supprimer votre commentaire ?'))
    {
      $.ajax({
       type: "POST",
       url: $('#base_href').val()+"module/deleteComment.php",
       data: "c_id="+id,
       success: function(){
        where.parent().parent().fadeOut();
        }
    });
    
    }
  }
  var currentComment = false;
  function modifComment(id, where)
  {
  
    currentComment = where;
    href = $('#base_href').val()+'addComment.php?id='+id;
    
    $('#test').click();
    //where.click();
    $.fn.fancybox.showItem('<iframe id="fancy_frame" onload="$.fn.fancybox.showIframe()" name="fancy_iframe' + Math.round(Math.random()*1000) + '" frameborder="0" hspace="0" src="'+href+'"></iframe>');
    return false;
 }
 
 function sendModifComment(id, val){
    where = currentComment;   
    var conteneur = where.parent().parent();
    conteneur.find('.c_text').hide();
    var texte = conteneur.find('.c_text').html();
    
      $.ajax({
        type: "POST",
        url: $('#base_href').val()+"module/sendComment.php",
        data: "update=true&comment=" + val + '&c_id=' + id,
        success: function(msg){
          conteneur.find('.c_text').fadeOut().html($this.val()).fadeIn();
     } 
    
    });
    document.getElementById('toModif').focus();
    
  }
  
  
  $(function(){
    linker();
    
    $('.affComment').click(function(){
      var $c = $('#commentaires').show();
        $c.html('');
      $.getJSON($(this).attr('href'), {}, function(json){
        $.each(json, function(i, value){
          afficher_commentaire(value);
        });
      });
      $('.addComment').click();
      return false;
    });
    
  });
  
  