jQuery().ready(function(){
  
  //==================================================================================================
  //liste des participants  
  $('.supprimerParticipation').hide();
  
  $(".liste_participant,.liste_commentaire").mouseenter(function(e){
  
    if($(this).children('a').children('.supprimerParticipation').attr("src") !== undefined){
    
      $(this).children('a').children('.supprimerParticipation').fadeIn(200);

    }
    
  });
  
  $(".liste_participant,.liste_commentaire").mouseleave(function(e){
  
    if($(this).children('a').children('.supprimerParticipation').attr("src") !== undefined){
    
      $(this).children('a').children('.supprimerParticipation').fadeOut(200);

    }
  
  });
  
  //==================================================================================================
  //Calendrier fleche
  $(".calendrier_semaine_en_cours_blanc_gauche").click(function(){
    affichageCalendrier(-1);
  });
  
  $(".calendrier_semaine_en_cours_blanc_droit").click(function(){
    affichageCalendrier(1);
  });
  
  $(".calendrier_difference_semaine").each(function(){
    affichageCalendrier($(".calendrier_difference_semaine").html());
  });
  
  chargement_evenement();
  
});


function affichageCalendrier(semaineAjout){

  //mise en place du fond de chargement
  var position = $(".calendrier").position();
  $(".calendrier_chargement")
			.css("top" , position.top + "px")
			.css("left" , position.left + "px")
			.show();
	
  //récupération de id de la langue
  var idLangue = parseInt($(".calendrier_idLangue").html());
	
  //récupération du code de la page
  var codePage = $(".calendrier_codePage").html();
  
  //récupération de id de la ville
  var idVille = parseInt($(".calendrier_idVille").html());
  
  //récupération de la date en cours
  var annee = parseInt($(".calendrier_annee").html());
  
  //récupération du numéro de semaine en cours
  var semaine = parseInt($(".calendrier_semaine_en_cours1").html());
  
  //on ajout ou retir 1
  semaine = parseInt(semaine) + parseInt(semaineAjout);
  
  //semaine en cours
  var semaine_en_cours = $(".semaine_en_cours").attr("title");
  var difference = semaine - semaine_en_cours;
  
  if(difference>=2) $(".calendrier_semaine_en_cours_blanc_droit").hide();
  else if(difference<=0) $(".calendrier_semaine_en_cours_blanc_gauche").hide();
  else{
    $(".calendrier_semaine_en_cours_blanc_droit").show();
    $(".calendrier_semaine_en_cours_blanc_gauche").show();
  }
  
  //une année n'a que 52 semaine
  if(semaine>52) semaine = 1;
  if(semaine<1) semaine = 52;
  
  if(semaine==semaine_en_cours) $(".calendrier_semaine_en_cours_violet").html($(".calendrier_semaine_en_cours2").html());
  else $(".calendrier_semaine_en_cours_violet").html($(".calendrier_semaine_en_cours3").html()+" "+semaine);
  
  $(".calendrier_semaine_en_cours1").html(semaine);
  
  $.post("/pages/calendrier/front_office_calendrier.php", {postAnnee:""+annee+"",postSemaineAjout:semaineAjout,postIdLangue:idLangue,postIdVille:idVille,postCodePage:codePage}, function(data){
  
    $(".leCalendrier").html(data);
    
    $(".calendrier_chargement").hide();
    
    chargement_evenement();
    
  });
  
}

//==================================================================================================
//Calendrier chargement des événements
function chargement_evenement(){

  /*
  //==================================================================================================
  //Calendrier horaire
  $(".calendrier_tableau_case").click(function(){
    
    var recupHtml = $(this).children(".calendrier_tableau_description").html();
    
    if(recupHtml===null){}else{
      
      elementDinformation = $(this).parents(".calendrier_tableau").next(".calendrier_informations_supplementaires");
      
      var vitesse = 300;
      
      $(".calendrier_informations_supplementaires").hide(vitesse , function(){
      
        //la div est invisible , mettons le contenu
        elementDinformation.html(recupHtml);
        elementDinformation.show(vitesse);
        chargement_evenement();
        
      });
      
    }
    
    return false;
    
  });
  */
  
  
  //==================================================================================================
  //Calendrier preview
  xOffset = 10;
  yOffset = 30;

  $(".preview").mouseover(function(e){
  
    this.affichage = $(this).next("div").html();

		$("body").append("<div id='screenshot'>"+this.affichage+"</div>");
		
		$("#screenshot")
			.css("top",(e.pageY + xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");

  }).mouseout(function(){
    $("#screenshot").remove();
  });
  
	$(".preview").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY + xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
  
  $(".semaine_en_cours").click(function(){
    
    var semaine = parseInt($(".calendrier_semaine_en_cours1").html());
    var numeroSemaine = $(this).attr("title");
    
    var difference = numeroSemaine - semaine;
    
    affichageCalendrier(difference);
    return false;
    
  });
  
}


