(function($) {
$.fn.zoom = function(params) {
  /*
  Zoom jQuery Plugin
  Copyright: (C) 2009 - Francesco Paggin
  Parameters:
    (int) duration: the duration of the zooming animaton
    (int) small_width, small_height: the dimensions of the small thumbnails
    (int) big_width, big_height: the dimensions of the zoomed images
  */
  var defaults = {
    duration: 300,
    small_width:350,
    small_height:263,
    big_width:1200,
    big_height:900
  };
  var options = $.extend(defaults, params);
  
  return this.each(function() {
    //caching...
    var $container = $(this);
    var $link = $container.find('a');
    var $image = $link.find('img');
    
    //reading some parameters...
    var small_path = $image.attr('src');
    var big_path   = $link.attr('href');
    
    //status variables...
    var dragging = false;
    var zoomed   = false;
    
    //calculate correct positioning...
    var a_width  = (options.big_width  - options.small_width)  * 2 + options.small_width;
    var a_height = (options.big_height - options.small_height) * 2 + options.small_height;
    
    var a_top  = options.big_height - options.small_height;
    var a_left = options.big_width  - options.small_width;
    
    /*
      INITIALIZATION...
    */
    $link.css({
      display:'block',
      position:'absolute',
      width: a_width   + 'px',
      height: a_height + 'px',
      top:  '-' + a_top  + 'px',
      left: '-' + a_left + 'px'
    });
    
    /* Removing default link behaviour... */
    $link.removeAttr('href');
    
    $image.css({
      display:'block',
      position:'absolute',
      width:  options.small_width + 'px',
      height: options.small_height + 'px',
      top: a_top + 'px',
      left: a_left + 'px'
    });
    
    /*
      HANDLE EVENTS...
    */
    $image.unbind("mouseup");
    $image.mouseup(function() {
        
      if (!dragging) {
        if (zoomed) {
          zoomOut();
        } else {
          zoomIn();
        }
      }
    });
    
    /*
      METHODS...
    */
    function zoomOut() {
      $image.animate({
        width:options.small_width + 'px',
        height:options.small_height + 'px',
        top:  a_top  + 'px',
        left: a_left + 'px'
      }, options.duration, swapWithSmall);
      zoomed = false;
    }
    
    function zoomIn() {
      $image.animate({
        width:options.big_width + 'px',
        height:options.big_height + 'px',
        top:  a_top / 2  + 'px',
        left: a_left / 2 + 'px'
      }, options.duration, swapWithBig);
      zoomed = true;
    }
    
    function swapWithBig() {
      $image.attr('src', big_path);
      $image.draggable({
        containment: 'parent',
        start: handleStartDrag,
        stop: handleStopDrag
      });
    }
    
    function swapWithSmall() {
    
      $image.attr('src', small_path);
      $image.draggable('disable');
    }
    
    function handleStartDrag() {
      dragging = true;
    }
    
    function handleStopDrag() {
      dragging = false;
    }
  });
}
})(jQuery)
 
function mettiFoto(piccola, grande){
    document.getElementById('idPiccola').src = piccola;
    document.getElementById('idGrande').href = grande;
    $('.image-zoom').zoom();
}

