function Gallery() {

    var gallery;
    var wrapper;
    var slider;
    var scroller;
    var images;
    var image;
    var thumbs;
    var offset;
    
    var linkUp;
    var linkDown;
    
    var scrollerHeight;
    var sliderHeight;
    
    var limiteInf;
    var limiteSup;
    
    var indiceFoto;
    var totaleFoto;
    
    var G;
    
    this.init = function init(container) {
        G = this;
        
        this.gallery   = jQuery(container);
        this.wrapper   = this.gallery.find('.wrapperImmagini');
        this.slider    = this.gallery.find('.sliderImmagini');
        this.scroller  = this.slider.find('.scroller');
        this.images    = this.wrapper.find('.immagine');
        this.image     = this.wrapper.find('.immagine img');
        this.thumbs    = this.slider.find('.immagine');
        
        this.linkUp     = this.gallery.find('.scrollUpHandler');
        this.linkDown   = this.gallery.find('.scrollDownHandler');
        
        this.indiceFoto = this.gallery.find('.indiceFoto');
        this.totaleFoto = this.gallery.find('.totaleFoto');
        
        this.indiceFoto.html(1);
        this.totaleFoto.html(this.thumbs.length);
        
        //calcolo i limiti di scorrimento...
        this.scrollerHeight = this.scroller.height();
        this.sliderHeight   = this.slider.height();
        
        this.limiteInf = this.sliderHeight - this.scrollerHeight;
        this.limiteSup = 0;
        
        this.offset = 0;
        
        //preparo le immagini...
        this.images.not(':first').hide();
        
        this.handleEvents();
    }
    
    //cambia l'immagine visualizzata...
    /*
    this.swap = function swap(elem) {
            G.index = G.thumbs.index(elem);
            G.currentImage = G.images.eq(G.index);
            G.currentImage.fadeIn('fast');
            G.images.filter(':visible').not(G.currentImage).fadeOut('fast');
            
            G.indiceFoto.html(G.index + 1);
            //return false;
    }
    */
    
    this.swap = function swap(elem) {
        G.index = G.thumbs.index(elem);
        //src = jQuery(elem).find('img').attr('src');
        src = jQuery(elem).find('input').attr('value');
        //src_grande = src.replace('PICCOLA.jpg', 'GRANDE.jpg');
        src_grande = src;
        G.image.attr('src',src_grande);
        G.indiceFoto.html(G.index + 1);
    }
    
    //muove il pannello in alto
    this.scrollUp = function scrollUp() {
            if (G.offset < G.limiteSup && !G.isMoving()) {
                G.offset += 80;
                G.scroller.animate({top: G.offset});
            }            
    }
    
    //muove il pannello in basso
    this.scrollDown = function scrollDown() {
            if (G.offset > G.limiteInf && !G.isMoving()) {
                G.offset -= 80;
                G.scroller.animate({top: G.offset});
            }
    }
    
    //determina se l'animazione è ancora in corso...
    this.isMoving = function isMoving() {
        if (G.scroller.queue('fx') == 0) {
            return false;
        } else {
            return true;
        }
    }
    
    //gestisce gli eventi della gallery
    this.handleEvents = function handleEvents() {
        //gestisco gli eventi...        
        this.linkDown.click(function() {
            G.scrollDown();
            return false;
        });
        
        this.linkUp.click(function() {
            G.scrollUp();
            return false;
        });
            
        /*
        this.thumbs.mouseover(function() {
            G.swap(this);
        });
        */
        
        this.thumbs.click(function() {
            G.swap(this);
            return false;
        });

        this.slider.mousewheel(function(event, delta) {
            if (delta<0) {
                G.scrollDown();
            } else {
                G.scrollUp();
            }
            return false;
        });
    }
}