var eyecatcher = new Class({
	Implements: Options,

	options: {
		element: false,
		delay: 4000,
		duration: 2000,
		messages: false
	},

	initialize: function(options) {
		this.setOptions(options);

		this.last = 0;
		this.current = 0;
		this.container = new Array();

		this.initialize_elements();
		this.fade();
	},

	initialize_elements: function() {
		if($type(this.options.messages) == "array") {
			this.options.messages.each(this.initialize_effects.bind(this));
		}
	},

	initialize_effects: function(item, index) {
		var box = new Element("div");
		box.grab(new Element("h3").set("html", item.headline));
		box.grab(new Element("p").set("html", item.text));
		box.addClass("text");
		box.fade("hide");
		box.set("tween", {duration: this.options.duration});

		this.container.push(box);
		this.id(this.options.element).grab(box);
	},

	id: function(element) {
		if($type($(element)) == "element") {
			return $(element);
		}

		return new Element();
	},

	fade: function() {
		if(this.container.length > 0) {
			this.container[this.last].fade("out");
			this.last = this.current;
			this.container[this.current].fade(0.95);
			this.current++;

			if(this.current > (this.container.length - 1)) {
				this.current = 0;
			}

			this.fade.bind(this).delay(this.options.delay);
		}
	}
});
