var autoShowTab=Class.create();
autoShowTab.prototype = {
	initialize:function(id,currentCss,mouseEvent,autoInterval){
		this.id = id;
		this.currentCss = currentCss;
		this.mouseEvent = mouseEvent;
		this.autoInterval = autoInterval;
		this.posNum = 1;
		this.posAll = $(id).down(1).childElements().length;
		this.intervalId;
		this.init();
	},
	
	init:function(){
		if($(this.id)){
			$(this.id).down(1).childElements().each(function(s,index){//鼠标事件绑定
				s.observe(this.mouseEvent, this.changeTab.bindAsEventListener(this,index));
			}.bind(this));

			//轮换Tab
			this.intervalId = setInterval(this.autoShowTab.bind(this),this.autoInterval*1000);
			$(this.id).observe("mouseover",function(){clearInterval(this.intervalId)}.bind(this));
			$(this.id).observe("mouseout",function(){this.intervalId = setInterval(this.autoShowTab.bind(this),this.autoInterval*1000);}.bind(this));
		}
	},

	changeTab:function(e){//鼠标事件监听
		this.posNum = $A(arguments).pop();
		var el =e.element();
		if (!el.hasClassName(this.currentCss)){
			this._tabShowHide(el);
		};
	},

	autoShowTab:function() {//轮换显示
		el = $(this.id).down(1).childElements()[this.posNum];
		this._tabShowHide(el);
		this.posNum++;
		if (this.posNum>=this.posAll)
		{
			this.posNum =0;
		}
	},

	_tabShowHide:function(el) {//改变标题样式和显示隐藏相应层
		var cssN = this.currentCss;
		el.addClassName(cssN).siblings().each(function(s){
			s.removeClassName(cssN);
		});
		el.up(1).next().childElements()[this.posNum].show().siblings().each(function(s){
			s.hide();
		});
	}
}
document.observe("dom:loaded",function(){
	var homeTab_Test = new autoShowTab("test","current","click",1);
});
