var bennerRotator = new Class({
  	
		options: {
			current :0,
			interval : 6,
			stop : false,
			elems : null
		},
		
		initialize: function(elems) {
			this.options.elems = elems;
			elems.each(function (item,index) {
				item.addEvent("mouseenter", this.rotate.bind(this,item));
				item.addEvent("mouseleave", this.continueRotating.bind(this));
			}.bind(this))
			this.rotate.periodical(this.options.interval*100,this,null);
		},
		
		rotate: function(elem) {
			if (this.options.stop) return;
			this.options.elems[this.options.current].removeClass("on");
			if ($chk(elem) && (newIndex = this.options.elems.indexOf(elem))  > -1 ) {
				this.options.stop = true;
				this.options.current = newIndex;
			} else {
				this.options.current++;
			}
			if (this.options.current >= this.options.elems.length) this.options.current=0;
			this.options.elems[this.options.current].addClass("on");
		},
		
		continueRotating: function() {
			this.options.stop = false;
		}
});

window.addEvent("domready", function() {
	new bennerRotator($$(".hrotate"));
});

