/**
 * Ротация/показ по очереди блоков(li) из списка(ul) с заданным интервалом
 */
var BlocksRotator = Class.create({
	
	container: null,
	options: {},
	index: 0,
	
	initialize: function(container_id, options) {
		this.container = $(container_id);
		// defaults
		this.options = Object.extend({
	    	interval: 3 
	    }, options);
	    
		this._init();
	},
	
	_init: function() {
		this.hideAllBlocks();
		this.showNextBlock();
		// start on document loaded
	    document.observe('dom:loaded', function() {
	        new PeriodicalExecuter(function(pe) {
	            this.hideAllBlocks();
	        	this.showNextBlock();
	        }.bind(this), this.options.interval);
	    }.bind(this), false);
	},
	
	hideAllBlocks: function() {
	    this.container.select('li').invoke('hide');
	},
	
	showNextBlock: function(index) {
	    this._showBlockByIndex(this._getNextBlockIndex());
	},
	
	_showBlockByIndex: function(index) {
	    this.container.down('li', index).show();
	},
	
	_getNextBlockIndex: function(index) {
		if (++this.index > this.container.select('li').size()) { this.index = 1; }
		return this.index - 1;
	}
	
});
