/*
	Panels
	Mark Simon, Comparity Training
	http://resources.comparity.net
	Feel Free to use
	
	This script creates displays and manages tabbed panels.
	To use:

	1.	Copy the panels.js and panels.css files somewhere
	
	2.	Head Section:

		<script type="text/javascript" src="includes/panels.js"></script>

		<script type="text/javascript">
			window.onload=function() {
				new panels('panels');
			}
		</script>

	3. 	Create the following hierarchical structure:

		<div id="panels">
			<div>
				<div title="...">
					...
				</div>
				<div title="...">
					...
				</div>
				<div title="...">
					...
				</div>
				<div title="...">
					...
				</div>
				<div title="...">
					...
				</div>
			</div>
		</div>

		That is:

		(a)	You have a div called "panels"
		(b)	The div contains a set of divs.
			Each div may contain other divs, which will not appear as tabs.
		(c)	Each div has a title="..." attribute.

	The id of your list above defaults to "panels".

	Disclaimer:

	This script probably works and it does what it does.
	What it doesn’t do it doesn’t do. E & OE

*/

var panels=new Array();
var tabs=new Array();
var tab;

function showPanel(t) {
	for (i in panels) {
		panels[i].style["display"]="none";
		//panels[i].className="";
	}
	for (i in tabs) tabs[i].className="tab";
	setCookie("panel",t);
	panels[t].style["display"]="block";
	tabs[t].className="tab selected";
}

function initPanels(panel) {
	var i;
	var div=document.getElementById(panel);
	var node=div.firstChild;
	do {
		if(node.nodeName.toLowerCase()=='div') panels.push(node);
	}	while(node=node.nextSibling);
	if(!panels.length) return;

	var ul=document.createElement('ul');
	div.appendChild(ul);
	var li, title;
	for(i=0;i<panels.length;i++) {
		li=document.createElement('li');
		title=panels[i].title.split(/: */);
		li.appendChild(document.createTextNode(title.shift()));
		li.title=title.join(': ');
		li.onclick=new Function('showPanel('+i+')');
		tabs.push(li);
		ul.appendChild(li);
	}
	div.insertBefore(ul,div.firstChild); //(document.createTextNode('and more'));
}
