var RSSscrollerPlugin = {
	active: 0,
	elements: Array(),
	timer: false,
	init: function() {
		var wrapper = document.id('RSSscrollerplugin');
		RSSscrollerPlugin.elements = wrapper.getElements('div[class=rssimport] li');
		wrapper.getElement('ul').setStyles({
			'position': 'relative',
			'overflow': 'hidden',
			'height': RSSscrollerPlugin.elements[0].getSize().y
		});
		RSSscrollerPlugin.elements.each(function (element, i) {
			element.setStyles({
				'position': 'absolute',
				'top': 0
			});
			if(i>0) RSSscrollerPlugin.hide(element);
		});
		window.addEvent('domready', function() {
			RSSscrollerPlugin.timer = RSSscrollerPlugin.next.periodical(RSSscrollerPluginPeriod);
		});
		wrapper.addEvent('mouseenter', function() {
			window.clearInterval(RSSscrollerPlugin.timer);
		});
		wrapper.addEvent('mouseleave', function() {
			RSSscrollerPlugin.next();
			RSSscrollerPlugin.timer = RSSscrollerPlugin.next.periodical(RSSscrollerPluginPeriod);
		});
	},
	show: function(el) {
		el.morph({
			opacity: [1],
			height: [el.retrieve('default-height')],
			top: [el.retrieve('default-height'), 0]
		});
	},
	hide: function(el) {
		el.store('default-height', el.getSize().y);
		el.morph({
			opacity: [0],
			height: [0],
			top: [-el.retrieve('default-height')]
		});
	},
	next: function() {
		RSSscrollerPlugin.hide(RSSscrollerPlugin.elements[RSSscrollerPlugin.active]);
		if(RSSscrollerPlugin.active >= RSSscrollerPlugin.elements.length-1) {
			RSSscrollerPlugin.active = 0;
		} else {
			RSSscrollerPlugin.active++;
		}
		RSSscrollerPlugin.show(RSSscrollerPlugin.elements[RSSscrollerPlugin.active]);
	}
};
RSSscrollerPlugin.init();

