/*
 * Tooltip script
 * powered by jQuery (http://www.jquery.com)
 *
 * written by Alen Grakalic (http://cssglobe.com)
 *
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */



this.tooltip = function(){
  /* CONFIG */
    xOffset = 10;
    yOffset = 20;
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
  /* END CONFIG */
  $("a.tooltip").hover(function(e){
    this.t = this.title;
    this.title = "";
    $("body").append("<p id='o-tooltip'>"+ this.t +"</p>");
    $("#o-tooltip")
      .css("top",(e.pageY - xOffset) + "px")
      .css("left",(e.pageX + yOffset) + "px")
      .fadeIn("fast");
    },
  function(){
    this.title = this.t;
    $("#o-tooltip").remove();
    });
};




$(document).ready(function(){
  tooltip();

  $("#privacy").click(function(){
      if ($('#privacy').is(':checked')) {
           $('#invia_quesito').removeAttr('disabled');
      } else {
          $('#invia_quesito').attr('disabled', true);
      }
  });

  $("#privacyFormConferenzaLavoro").click(function(){
      if ($('#privacyFormConferenzaLavoro').is(':checked')) {
           $('#invioFormConferenzaLavoro').removeAttr('disabled');
      } else {
          $('#invioFormConferenzaLavoro').attr('disabled', true);
      }
  });

/**
Photogallery con possibilità di spostare le foto sullo schermo per visualizzarle dove è più comodo.
*/
// inizializzazione delle variabili utilizzate per posizionare sullo schermo il dettaglio della foto
   var mouseDown=false;
   var photoVertexY=0;
   var photoVertexX=0;
   var offsetPhVy=0;
   var offsetPhVx=0;

  $(".elencoFoto").click(function(e){
    wX = $(window).width()/4;
    wY = 10;
    imageId=0;
    $(e.target).parents(".elencoFoto").children("ul").children("li").children("a").each(function(){
        imageId= $(this).attr("href");
    });
    if($(e.target).attr('class')=='elencoFoto'){
      $(e.target).children("ul").children("li").children("a").each(function(){
          imageId= $(this).attr("href");
      });
    }
    $.get('../fotoGallery/getImageData.php?id='+imageId, function(imageData, textStatus){
      eval(imageData);
      $("#fotoBig").remove();
      $("body").append('<div id="fotoBig"><ul><li><h4><a href="#" title="Chiude il dettaglio della foto"><span id="closeImgDetail">X</span></a> '+imageData['titolo']+'</h4></li><li><img id="fotoBigPic" src="'+imageData['address']+'" alt="'+imageData['title']+'" /></li><li>'+imageData['descrizione']+'</li></ul></div>');
      if (photoVertexY>0 || photoVertexX>0){
        $("#fotoBig")
            .css("left", photoVertexX+"px")
            .css("top", photoVertexY+"px");
      }else{
        $("#fotoBig")
            .css("left", wX+"px")
            .css("top", wY+"px");
      }
      $("#fotoBig").fadeIn("slow", function(){
        $("#closeImgDetail").bind('click',function(){
          $("#fotoBig").fadeOut("slow", function(){
            $("#fotoBig").remove();
          });
        });

        $('#fotoBig').bind('mousedown',function(e){
              mouseDown=true;
              photoVertexY = $("#fotoBig").css("top");
              photoVertexX = $("#fotoBig").css("left");
              photoVertexY = photoVertexY.substring(0,photoVertexY.length-2);
              photoVertexX = photoVertexX.substring(0,photoVertexX.length-2);
              offsetPhVy = e.pageY - photoVertexY;
              offsetPhVx =  e.pageX - photoVertexX;
          });//mouse down

          $('#fotoBig').bind('mousemove',function(e){
              if (mouseDown){
                 $("#fotoBig")
                    .css("top",(e.pageY-offsetPhVy)+ "px")
                    .css("left",(e.pageX-offsetPhVx)+ "px");
                 photoVertexY = $("#fotoBig").css("top");
                 photoVertexX = $("#fotoBig").css("left");
                 photoVertexY = photoVertexY.substring(0,photoVertexY.length-2);
                 photoVertexX = photoVertexX.substring(0,photoVertexX.length-2);
              }
          });

          $('#fotoBig').bind('mouseup',function(e){
              mouseDown=false;
          });//mouseup

          $('#fotoBig').bind('mouseout',function(e){
              mouseDown=false;
          });//mouseup

          $('#fotoBig').bind('click',function(e){
              mouseDown=false;
          });//mouseup
        });
      });//$.get
    return false;
  });
});

