var AnnounceRotate = Class.create({
	
	iter: 0,
	items: null,
	delay: 5000,
	
	initialize: function() {
		
		this.items = $A($$('#novinki div.block'));
		if(this.items.length > 1) {
			this.startRotate();
		}
	},
	
	startRotate: function() {
		var self = this;
		window.setInterval(function() {
			self.showNextItem();
		}, this.delay+2000);
	},
	
	showNextItem: function() {
		var currentItem = this.items[this.iter];
		var item = this.getNextItem();
		
		new Effect.Fade(currentItem, {
			afterFinish: function() {
				window.setTimeout(function() {
					new Effect.Appear(item);
				}, 10);
			}
		});
	},
	
	getNextItem: function() {
		this.iter ++;
		if(this.iter < this.items.length) {
			var item = this.items[this.iter];
		} else {
			this.iter = 0;
			var item = this.items[0];
		}
		
		return item;
	}
	
});

document.observe("dom:loaded", function() {	
	new AnnounceRotate;
});
