/*
 * Compte A Rebourd : on recherche des liens "[CAR]"
 * dans la target du lien est notre date et on transforme tout ca en j-54
 * ex <a href="10.08.2010">[CAR]</a>
 */
car_diff_date = function(temp) {

  ladates = temp.split('.');
  today= new Date();

  var ladate = new Date(ladates[2], ladates[1]-1, ladates[0]); // en js les mois commencent ŕ ...zéro et pas 1 d'ou le -1
  var one_day=1000*60*60*24;
  //Calculate difference btw the two dates, and convert to days
  var jours_restant = Math.ceil((ladate.getTime()-today.getTime())/(one_day));
  return jours_restant;
}

car_init = function() {
  $('a.car').addClass('external');
  $('a.car').each(
    function(elm) {
      var new_txt = car_diff_date($(this).html());
      if(new_txt > 0) {
      $(this).html("J -" + new_txt);
      } else {
        $(this).html("");
      }
    }
  );

  
}

colorbox_init = function() {
  // on met l'attribur rel a "gallery" pour tous les liens qui ont comme class "gallery"
  $('a.gallery').each(
    function(elm) {
      $(this).attr('rel', "gallery");      
    }
  );
  // colorbox sur les liens qui ont comme attribut "gallery"
  $("a[rel='gallery']").colorbox();
}

// retire la div appell2011 en fonction de la date 
removeencart_init = function() {
	if($('#appel2011').length > 0) {
		var d = new Date();
		var ladate_mois = d.getMonth();

		var ladate_jour = d.getDate() * 1;

		if(ladate_jour < 10) { ladate_jour = "0" + ladate_jour; }

		var ladate = ladate_mois + "" + "" + ladate_jour;
		ladate = ladate * 1;

		// on veut que ca se masque le 30 / 03 donc 330
		if(ladate > 330) { $('#appel2011').css("display", "none"); }
	}
}


// init démarrage
$(document).ready(function() {
    car_init();
    colorbox_init();
		removeencart_init();
  }
  );
