/*
Toni Rantanen
2008-05-15
www.kotimaa-yhtiot.fi/verkkopalvelut
based on the JS content rotator by deVpartment
requires at least mootools-beta-1.2b2
*/
var Rotator = new Class({
	options:
	{
		rotatorDuration: 2500,
		stopped: false,
		onRotatorStart: Class.empty,
		onRotatorStop: Class.empty
	}, 
	
	initialize: function(cont, titles, contents, opts)
	{
		this.setOptions(opts);
		this.accr = new Accordion(titles, contents, opts);
		this.rotate.periodical(this.options.rotatorDuration, this);
		cont.addEvent('mouseover', this.stop.bind(this));
		cont.addEvent('mouseout', this.start.bind(this));
	},
	
	stop: function()
	{
		this.fireEvent('onRStop', this.accr.previous);
		this.options.stopped = true;
	},
	
	start: function()
	{
		this.fireEvent('onRStart', this.accr.previous);
		this.options.stopped = false;
	},
	
	rotate: function()
	{
		if(!this.options.stopped)
		{
			var toShow = this.accr.previous + 1;
			if(toShow > this.accr.elements.length-1)
				toShow = 0;
			this.accr.display(toShow);
		}
	}
});
Rotator.implement(new Options);
Rotator.implement(new Events);