
var HeaderBlocks=new Class({
	Implements:Options,
	options:{speed:5000},
	initialize:function(c,d,b){
		this.setOptions(b);
		this.hover=$$(c);
		this.elements=$$(d);
		this.current=0;
		this.elements.setStyle("display","none");
		this.next();
		var a=this.next.periodical(this.options.speed,this);
		this.hover.each(function(f,e){
			f.addEvents({
				mouseenter:function(){
					//console.log('hover');
					$clear(a);
					this.hover.removeClass("active");
					f.addClass("active");
					this.elements.setStyle("display","none");
					this.elements[e].setStyle("display","block");
					this.current=e+1;
					if(this.current==this.hover.length){
						this.current=0
					}
				}.bind(this),
				mouseleave:function(){
					a=this.next.periodical(this.options.speed,this)
				}.bind(this),
				click:function(){
					window.location=f.getElement("a").get("href")
				}
			})
		}.bind(this))
	},
	next:function(){
		this.hover.removeClass("active");
		this.elements.setStyle("display","none");
		this.hover[this.current].addClass("active");
		this.elements[this.current].setStyle("display","block");
		this.current++;
		
		if(this.current==this.hover.length){
			this.current=0
		}
	}
});

window.addEvent("domready",function(){
	
	if ($('subject-wrapper-menu') && $('subject-wrapper-menu').getElements('ul li').length > 0) {
		new HeaderBlocks("#subject-wrapper-menu ul li","#subject-wrapper div.subject");
	}
});
