/* **********  Tab 标签动作脚本  ************** */
var switchTimeout = 60000;//切换时间，单位毫秒
var tabAutoPlayer = true;
function Tab(tabheader) {
	var self = this;
	var active = null;
	
	var tds = tabheader.getElementsByTagName("TD");
	var tbs = new Array();
	for (var i=0;i<tds.length;i++) {
		var td = tds[i];
		if (td.className != "blank") {
			tbs.push(td);
			if (this.active == null && td.className == "active") {
				this.active = td;
			}
			var link = td.getElementsByTagName("A")[0];
			link.td = td;
			link.onclick=function() {
				if (active == this.td) return false;
				active = this.td;
				display(); 
			}
		}
	}
	
	function pre() {
		if (active == null && tbs.length > 0) active = tbs[0];
		if (active == tbs[0]) {
			active = tbs[tbs.length-1];
		} else {
			for(var i=1;i<tbs.length;i++) {
				var tb = tbs[i];
				if (active == tb) {
					active = tbs[i-1];
					break;
				}
			}
		}
		display();
	}
	function next() {
		if (active == null && tbs.length > 0) active = tbs[0];
		if (active == tbs[tbs.length-1]) {
			active = tbs[0];
		} else {
			for(var i=0;i<tbs.length-1;i++) {
				var tb = tbs[i];
				if (active == tb) {
					active = tbs[i+1];
					break;
				}
			}
		}
		display();
	}
	var play = null;
	var player = null;
	try {player = getElementsByClassName(tabheader, "DIV", "player")[0];}catch(err){}
	if (player != null) {
		if (tabAutoPlayer) {
			var as = player.getElementsByTagName("A");
			as[0].onclick = pre;
			as[1].onclick = function() {
				if (play != null) {
					window.clearInterval(play);
					play = null;
				} else {
					play = window.setInterval(function() {next();}, switchTimeout);
				}
			}
			as[2].onclick = next;
			play = window.setInterval(function() {next();}, switchTimeout);
		} else {
			player.style.visibility = "hidden";
		}
	}
	
	display = function() {
		if (active == null && tbs.length > 0) active = tbs[0];
		active.className = "active";
		document.getElementById(active.getElementsByTagName("A")[0].rev).style.display = "";
		for (var i=0;i<tbs.length;i++) {
			var tb = tbs[i];
			if (tb == active) continue;
			tb.className = "normal";
			document.getElementById(tb.getElementsByTagName("A")[0].rev).style.display = "none";
		}
	}
	display();
}
function collectTab() {
	var elements = getElementsByClassName(document, "TABLE", "tabheader");
	for (var i=0;i<elements.length;i++) {
		new Tab(elements[i]);
	}
}
function getElementsByClassName(parent, tagName, className) {
	var result = new Array();
	var elements = parent.getElementsByTagName(tagName);
	for (var i=0;i<elements.length;i++) {
		var element = elements[i];
		if (element.className == className) {
			result.push(element);
		}
	}
	return result;
}
if (!window.Event) {
  var Event = new Object();
}
Event.observe = function(element, name, observer, useCapture) {
	if (element.addEventListener) {
		element.addEventListener(name, observer, useCapture);
    } else if (element.attachEvent) {
    	element.attachEvent('on' + name, observer);
    }
};
var ns_pos = (typeof window.pageYOffset!='undefined');
Event.observe(window, "load", collectTab);
