$(document).ready(function(){ // This sets the opacity of the thumbs to fade down to 60% when the page loads

  $(function(){
    $(".thumbnail").fancybox({
      'zoomOpacity'			: true,
      'overlayShow'			: true,
      'overlayOpacity'  : 0.7,
      'zoomSpeedIn'			: 500,
      'zoomSpeedOut'	  : 500
    });
  });

  initVotes();
  initComments();
  initMap();
});

  function initVotes()
  {
    $(".bouton_etoiles > .etoiles").click(
      function(){
        $.ajax({
          url:route_add_vote,
          data:{score:$(this).attr("rel")},
          error:function(){alert('error : js/espPubllicationView.js::initComments()'); },
          success:function(data){    $('#vote_container').html(data);      initVotes();    }
        });
        return false;
      }
    )
  }

  //Code ajax pour caller l'action correspondante a l'enregistrement du commentaire et
  //Rafraichir le div correspondant au commentaire
  function initComments()
  {
    if($('#id_text_comment').val().trim() == "")
        $('#id_text_comment').val($('#id_text_comment').attr('default'));
      
    $('#id_text_comment').focus(function(){
      if($('#id_text_comment').val().trim() == $('#id_text_comment').attr('default'))
        $('#id_text_comment').val('');
      })

    $('#id_text_comment').blur(function(){
      if($('#id_text_comment').val().trim() == "")
        $('#id_text_comment').val($('#id_text_comment').attr('default'));
    })

    $("#id_submit_comment").click(
      function(){
        if($('#id_text_comment').val().trim() == $('#id_text_comment').attr('default'))
           return false;
        $.ajax({
          url:route_add_comment,
          data:{comment_text:$('#id_text_comment').val()},
          error:function(){alert('error : js/espReportageView.js::initComments()'); },
          success:function(data){    $('#id_bloc_comment').html(data);      initComments();    }
        });
        return false;
      }
    )
  }

  //Code ajax pour telecharger la carte
  function initMap()
  {
    $('#cadrecarte').hide();
    $("#voircarte").click(
      function(){
        $('#cadrecarte').toggle('slow');
         map.checkResize();
         map.zoomToMarkers(map.getMarkers(),8);
        /*$.ajax({
          url:route_load_map,
          data:{},
          dataType:"html",
          error:function(){alert('error : js/espReportageView.js::initMap()'); },
          success:function(data){ alert(data);$('#div_map_cadre').html(data);}
        });*/
        return false;
      }
    )
  }
  
