/**
 * Shows a series of sentences in sequence.
 * @author Massimiliano Cingolani
 */
var SequenceOfSentences = new Class({
	Implements: Options,
	sentences: new Array(),
	item: 0,
	div: null,
	fx: null,
	options: {
		delay: '5000',
		href: '#'
	},
	initialize: function(element, options) {
		var element = $(element);
		this.setOptions(options);
		if (element.get('tag') == 'ul') {
			
			var items = element.getElements('li');
			for (n = 0; n < items.length; n++) {
				this.sentences.push(items[n].get('html'));
			}
			
			this.div = new Element('div', {
				id: element.get('id'),
				html: this.sentences[this.item],
				onclick: 'location.href=\''+this.options.href+'\''
			});
			this.div.replaces(element);

			this.fx = new Fx.Tween(this.div, {property:'opacity'});
			this.fade.periodical(this.options.delay, this);
			
		} else {
			alert("The selected element is not an unordered list");
		}
	},
	fade: function() {
		if (this.fx != null) {
			this.fx.start(1,0).chain(
				function() { this.nextSentences() }.bind(this),
				function() { this.fx.start(0,1) }.bind(this).delay(1000)
			);
		}
	},
	nextSentences: function() {
		if (this.div != null) {
			if (this.item < (this.sentences.length - 1)) {
				this.item++;
			} else {
				this.item = 0;
			}
			this.div.set('html', this.sentences[this.item]);
		}
	}
});

