var productsSlideshow = function(opts){
	var _this = this;
	this.moduletable	= $(opts.moduletable);
    this.container 		= $(opts.container,this.moduletable);
    // handles cases where an event doesnt have news but the constructor is called anyway
    if(this.container.length === 0){
        return;
    }
    this.childType			= this.container.children(":first-child").get(0).nodeName.toLowerCase();
	
    this.speed 				= opts.speed;
	this.interval 			= opts.interval;
	this.wait 				= opts.wait;

    this.isAnimated 		= false;
	this.timer				= false;

    var isAutoScroll 		= this.isAutoScroll = opts.isAutoScroll || false;
	var isInfiniteScroll 	= this.isInfiniteScroll = (this.autoScroll === true) ? true : (opts.isInfiniteScroll || false);

    this.currentPage	= 1;
    this.totalPages		= this.container.children().length;
    this.height			= opts.height;
    this.top			= 0;
	
    if(this.container.children(this.childType).length > 1){
        this.autoScrollTimer = false;
        if(isAutoScroll){
            this.launchAutoScroll();
        }
    }
}

productsSlideshow.prototype = {
	
	reLaunchAnimation: function(){
		var _this = this;
		if(this.autoScrollTimer){
        	clearInterval(_this.autoScrollTimer);
        	this.autoScrollTimer = null;
		
			if(this.timer){
				this.clearTimer();
			}
			
			this.timer = setTimeout(function(){
				_this.launchAutoScroll();
				_this.clearTimer();
			},this.wait);
		}
	},
	clearTimer: function(){
		clearTimeout(this.timer);
		this.timer = false;
	},
	launchAutoScroll: function() {
		var _this = this;
		this.autoScrollTimer = setInterval(function(){
               _this.gotoNext();
           },this.interval);
	},
    gotoNext:function(){

		var _this = this;
		if(!_this.isAnimated) {
			_this.isAnimated = true;
			this.top -= this.height;
			this.container.animate({"top":_this.top},_this.speed,function(){
				_this.container.children(_this.childType+":first").appendTo(_this.container);
				_this.container.css('top',0);
				_this.top = 0;
				_this.isAnimated = false;
			});
		}

    }
}


    


