
var AUTO_SWITCH_TIME = 2000; // 轮询间隔(单位毫秒)

// 以下若非必须，慎动。
var TIMER, TABS = 4, PRE_T = 'tab', PRE_C = 'tab0', TAB = 1, CLASSS = [' ', 'hover'];
function stopSwitcher() {
	TIMER = clearInterval(TIMER);
}
function startSwitcher() {
	stopSwitcher();
	TIMER = setInterval(function(){
		var i = (TAB >= TABS || TAB <= 0) ? 1 : TAB + 1;
		switchTab(i);
	}, AUTO_SWITCH_TIME);
}
function toggle(id, hide) {
	var el = document.getElementById(id);
	if(el && el.style) el.style.display = hide ? 'none' : '';
}
function toggleCls(id, cls) {
	var el = document.getElementById(id);
	if(el) el.className = cls;
}
function switchTab(index, stop) {
	if(stop) stopSwitcher();
	if(TAB == index || index > TABS || index <= 0) return;
	for(var i = 1; i <= TABS; i++) {
		toggle(PRE_C + i, true);
		toggleCls(PRE_T + i, CLASSS[0]);
	}
	toggle(PRE_C + index);
	toggleCls(PRE_T + index, CLASSS[1]);
	TAB = index;
}
startSwitcher();
