widgets_slideshow = function(container,callback) { var that = this;

	that.init = function() {
	
	    $(container).find("div.widgets_slideshow_left").click(that.left);
	    $(container).find("div.widgets_slideshow_right").click(that.right);
	    that.total = that.getImages().length;
	    that.active = 4;
	    that.totalWidth = $(container).find("table").width();

	    that.images = [];
		that.getImages().each(function(n){
			that.images[n]=$(this);
		})

		that.imageOffset = [];
		var offset = 0;
		for(var i=that.total-1;i>=0;i--) {
		    that.imageOffset[i] = offset;
		    offset += that.images[i].width();
		}
		
		// Дублируем картинки еще два раза
		var html = $(container).find("tr").html();
		$(html).appendTo($(container).find("tr"));
		$(html).appendTo($(container).find("tr"));
		
		callback((that.active+that.total*10000)%that.total,that);
		
	}

	that.left = function() {
	    that.active--;
	    that.slideToActive();
	    callback((that.active+that.total*10000)%that.total,that);
	}
	
	that.right = function() {
	    that.active++;
	    that.slideToActive();
	    callback((that.active+that.total*10000)%that.total,that);
	}
	
	that.getImages = function() {
	    return $(container).find("img.widgets-slideshow-image");
	}
	
	that.slideToActive = function() {
		var index = that.active%that.total;
		that.dx = -(Math.floor(that.active/that.total))*that.totalWidth + that.imageOffset[(index+that.total*10000)%that.total];
	}
	
	that.x = 0;
	that.dx = 0;
	that.animate = function() {
		setTimeout(that.animate,20);
		that.x+=(that.dx-that.x)/10;
		var x = that.x;
		if(!that.x)
		    that.x = 0;
		that.getImages().css({left:(x+that.totalWidth*10000)%that.totalWidth+that.totalWidth});
	}
	
	that.preInit = function() {
	    var ready = true;
		that.getImages().each(function(){
		    if(!$(this).width())
		        ready = false;
		});
		
		if(!ready)
		    setTimeout(that.preInit,500)
		else
			that.init();
	}
	
	that.preInit();
	that.animate();
	return that;
}
