var ContentRotation = new Class({
	Implements: [Options, Events],
	options: {
		element: 'language-switch',
		anchors: 'li',
		delay:	3000
	},
	loopActive:true,
	initialize: function(options){
		this.setOptions(options);
		this.element = document.id(this.options.element);
		this.anchors = this.element.getElements(this.options.anchors);		
		this.delayfunc({id:0});
	},
	delayfunc: function(options){
		var id = options.id;
		this.fireEvent('action', options);
		if (this.anchors.length-1 == id) {
			id = -1;
		}
		(function() {
			this.delayfunc({id:id+1});
		}.bind(this).delay(this.options.delay));
		
	}
});

var rotator = null;

window.addEvent ('domready', function() {
	rotator = new ContentRotation({'onAction':function(options){
		if(this.loopActive){
			$('main-content-start').getElements('div').setStyle('display', 'none');
			$('item-'+options.id).setStyle('display', 'block');
			this.anchors.removeClass('active');
			this.anchors[options.id].addClass('active');
		}
	}
	});
	
	rotator.anchors.addEvent('mouseenter', function(ev){
		var liEl = null;
		if($(ev.target).get('tag') == 'li'){
			liEl = $(ev.target);
		} else {
			liEl = $(ev.target).getParent('li');
		}
		
		rotator.fireEvent('action', {id: liEl.getAllPrevious().length});
		rotator.loopActive = false;
	}).addEvent('mouseleave', function(){
		rotator.loopActive = true;
	});
	
});
