CrossFade2 = function(cnt)
{
	this.cnt = $('#' + cnt);
	this.img = [];
	this.suspend = false;

	this.interval = 5000;	// tempo fra un fade e l'altro
	this.speed = 2000;		// velocitˆ crossfading

	this.attach();
};

CrossFade2.prototype.attach = function()
{
	this.cur = -1;

	var me = this;
	this.cnt.css({position: 'relative'})
			.children('img')
			.css({opacity: 0, position: 'absolute', display: 'block'})
			.each(function() {
				me.img.push($(this));
			});

	this.animate();
};

CrossFade2.prototype.animate = function()
{
	if (this.suspend)
		return;

	if (this.cur >= 0)
		this.img[this.cur].animate({opacity: 0}, this.speed);

	if (++this.cur == this.img.length)
		this.cur = 0;

	this.img[this.cur].animate({opacity: 1}, this.speed);

	var me = this;
	setTimeout(function() { me.animate(); }, this.interval);
};

CrossFade2.prototype.pause = function()
{
	this.suspend = true;
};

CrossFade2.prototype.resume = function()
{
	this.suspend = false;
	this.animate();
};

