var ImageRotator = new Class({
	Implements	: [Events,Options],
	options		: {
		'rollingTimeout' : 5000, // msec per il rolling delle immagini
		'rollingObject' : []
	},
	
	initialize	: function(opzioni)
	{
		this.setOptions(opzioni);
		if((this.options['rolloverContainer']) && (this.options['rollingObject']) && (this.options['rollingObject'].length >= 3))
		{
			this.rolloverContainer = $(this.options['rolloverContainer']);
			this.largeThumb = $('grande_a');
			this.smallThumb1 = $('piccola1');
			this.smallThumb2 = $('piccola2');
			this.currentItem = 1;
			
			this.rollImages.periodical(this.options['rollingTimeout'], this);
		}
	}
});

ImageRotator.implement({
	getNextRollingObject : function(step) {
		var retVal = 0;
		//console.log(this.currentItem + step);
		if((this.currentItem + step) < this.options['rollingObject'].length)
			retVal = this.currentItem + step;
		else
		{
			retVal = step - 1;
			// console.log(retVal);
		}
		
		return retVal;
	},
	
	rollImages : function()
	{
		//console.log(this.currentItem, this.options['rollingObject'].length);
		var currObj = this.options['rollingObject'][this.currentItem];
		var nextObj1 = this.options['rollingObject'][this.getNextRollingObject(1)];
		var nextObj2 = this.options['rollingObject'][this.getNextRollingObject(2)];
		
		this.largeThumb.setStyle('opacity', '0.0');
		this.largeThumb.setAttribute('href', currObj['href']);
		this.largeThumb.getElements('img')[0].setAttribute('src', currObj['fnamel']);
		
		this.smallThumb1.setStyle('opacity', '0.0');
		this.smallThumb1.setAttribute('href', nextObj1['href']);
		this.smallThumb1.getElements('img')[0].setAttribute('src', nextObj1['fname']);
		
		this.smallThumb2.setStyle('opacity', '0.0');
		this.smallThumb2.setAttribute('href', nextObj2['href']);
		this.smallThumb2.getElements('img')[0].setAttribute('src', nextObj2['fname']);
		
		this.largeThumb.fade('in');
		this.smallThumb1.fade('in');
		this.smallThumb2.fade('in');
		
		this.currentItem = this.currentItem + 1;
		
		if(this.currentItem >= this.options['rollingObject'].length)
			this.currentItem = 0;
	}
});
