//---------------------------------------------------------------------
//	Tabbed
//---------------------------------------------------------------------

document.getElementsByTagName("html")[0].className = 'JavascriptEnabled';

document.TabbedInterval = function (index) {
	var group = document.getElementsByTagName("html")[0].tabGroups[index];
	var state = group.state+1;
	if (state>= group.boxList.length) state=0;
	group.Select (state, true);
};

if (!document.onLoadFunctions) {
	document.onLoadFunctions = new Array();
	window.onload = function () { for (var i=0; document.onLoadFunctions.length>i;i++) document.onLoadFunctions[i](); }
}

document.onLoadFunctions.push ( function () {

	var html = document.getElementsByTagName("html")[0];
	html.tabGroups=new Array();

	var list = document.getElementsByTagName("li");

	var parseState='-';
	var group = null;

	function doSelect (obj, on) {
		var className = obj.className;
		var oldnames = className ? className.split (" ") : [];
		var newnames = [];
		for (var i in oldnames) {
			var name=oldnames[i];
			if (name=='TabbedSelected' || name=='TabbedUnselected')
				continue;
			newnames.push (name);
		}
		newnames.push (on ? 'TabbedSelected' : 'TabbedUnselected');
		obj.className = newnames.join(" ");
	}

	for (var i=0; i<list.length; i++) {

		var li_node = list[i];
		if (li_node.parentNode.className.substr(0,6) != 'Tabbed') continue;

		if (li_node.parentNode.nodeName == 'OL') {
			if (parseState != 'inOL') {
				group = new Object;
				group.tabList= new Array();
				group.boxList= new Array();
				group.state = 0;
				group.Select = function (newstate, isInterval) {
					doSelect (this.tabList[this.state], false);
					doSelect (this.boxList[this.state], false);
					this.state = newstate;
					doSelect (this.tabList[this.state], true);
					doSelect (this.boxList[this.state], true);
					if (isInterval || !this.interval) return;
					window.clearInterval(this.interval);
					this.interval=null;
				};
				html.tabGroups.push(group);
				if (li_node.parentNode.className.substr(0,17) == 'Tabbed autorotate')
					group.delay = parseInt (li_node.parentNode.className.substr(17));
				parseState = 'inOL';
			}
			var a_node = li_node.firstChild;
			a_node.group = group;
			a_node.state = group.tabList.length;
			a_node.onclick = function () { this.group.Select(this.state, false); return false; }
			doSelect (li_node, group.tabList.length==0);
			group.tabList.push (li_node);
		}
		if (li_node.parentNode.nodeName == 'UL') {
			parseState = 'inUL';
			doSelect (li_node, group.boxList.length==0);
			group.boxList.push (li_node);
		}
	}
	for (var index=0; index<html.tabGroups.length; index++) {
		var group = html.tabGroups[index];
		if (group.delay)
			group.interval=window.setInterval("document.TabbedInterval("+index+")", group.delay);
	}
});

