function slideshow() {
    var name;
    var $itens;
    var $activactors;
    var $container;
    var $prev;
    var $next;
    var $cloned;
    var delay;
    var animDelay;
    var curSlide;
    var numSlides;
    var autoPlay;
    var eventMode;
	var callback;

    var interval;
    var instance;

    this.inicializar = function (name, $itens, $activactors, $container, $prev, $next, delay, animDelay, autoPlay, eventMode, callback) {
        this.name = name;
        this.$itens = $itens;
        this.$activactors = $activactors;
        this.$container = $container;
        this.$prev = $prev;
        this.$next = $next;
        this.delay = delay + animDelay;
        this.animDelay = animDelay;
        this.autoPlay = autoPlay;
        this.eventMode = eventMode; //CLICK ou HOVER
		this.callback = callback;
        this.curSlide = -1;
        this.numSlides = $('> div', $itens).length - 1;

        this.instance = this;
		
     	this.setupEvents();
        if (autoPlay) {
			this.nextSlide(); 
			this.beginInterval();
		}
    }

    this.beginInterval = function () {
        this.interval = setInterval(this.name + '.nextSlide()', this.delay);
    }

    this.nextSlide = function () {
        if (this.curSlide < this.numSlides) this.curSlide++;
        else this.curSlide = 0;

        this.showSlide();
    }

    this.prevSlide = function () {
        if (this.curSlide > 0) this.curSlide--;
        else this.curSlide = this.numSlides;

        this.showSlide();
    }

    this.showSlide = function (slide) {
        if (slide != undefined) this.curSlide = slide;

        var $new = $('> :eq(' + this.curSlide + ')', this.$itens).clone();
        $new.css({
            position: 'absolute'
        });
        $new.data('instance', this);

        this.$container.append($new);

        //if (this.$cloned != undefined) {
        //this.$cloned.fadeOut(this.animDelay);
        $new.hide().fadeIn(this.animDelay, function () {
            var instance = $(this).data('instance');
            if (instance.$cloned != undefined) instance.$cloned.remove();
            instance.$cloned = $new;
			if (instance.callback != undefined)
				instance.callback();
        });
        //}
        //console.log($cloned);
        if (this.$activactors != null) {
            this.$activactors.removeClass('active');
            this.$activactors.eq(this.curSlide).addClass('active');
        }

        //$(':not:eq(' + slide + ')', this.$activactors).removeClass('active');
    }

    this.setupEvents = function () {
        if (this.$activactors == null) return

        if (this.eventMode == 'hover') {
            this.$activactors.mouseenter({
                instance: this.instance
            }, function (event) {
				var $this = $(this);
                var id = $this.parent().index();
                var instance = event.data.instance;
                instance.showSlide(id);
                if (instance.autoPlay) clearInterval(instance.interval);
            });
            this.$activactors.mouseleave({
                instance: this.instance
            }, function (event) {
                var instance = event.data.instance;
                if (instance.autoPlay) instance.beginInterval();
            });
        } else if (this.eventMode == 'click') {
            this.$activactors.click({
                instance: this.instance
            }, function (event) {
                event.preventDefault();
				
				var $this = $(this);
                var id = $this.index();
                var instance = event.data.instance;
				
                instance.showSlide(id);
                if (instance.autoPlay) clearInterval(instance.interval);
            });
        }

    }
}
