/* 
* based on domtab written by Chris Heilmann
* more info: http://www.onlinetools.org/tools/domtab.php
*/


function tabPane(el, cid)
{
	this.tabHighlightClass='tabon'; 
	this.currentTab;
	this.currentLink;
	var tabpane = this;
	this.navElement = el.id;
	this.navElementTabbedId = el.id + 'tabbed';	
	
	if(document.getElementById && document.createTextNode)
	{
		/*cid = window.location.toString().match(/#(\w.+)/);
		if(cid && cid[1])
		{
			cid = cid[1];
		}*/
			
	}
	var n = document.getElementById(this.navElement);
	n.id = this.navElementTabbedId;
	n = document.getElementById(this.navElementTabbedId)
	var as = n.getElementsByTagName('a');
	for(var i = 0; i < as.length; i++)
	{
		as[i].onclick = function()
						{
							showTab(this);
							return false;
						}
	
		id = as[i].href.match(/#(\w.+)/)[1];
		if(!cid && i == 0)
		{
			this.currentTab = id;
			this.currentLink = as[i];
		} else if(id == cid)
		{
			this.currentTab = id;
			this.currentLink = as[i];
		}
		if(document.getElementById(id))
		{
			document.getElementById(id).style.display='none';
		}
	}
	
	if(id != cid){
		if(document.getElementById(this.currentTab))
		{
			document.getElementById(this.currentTab).style.display='block';
		}
		re = new RegExp('\\b' + this.tabHighlightClass + '\\b');
		if(!re.test(this.currentLink.className))
		{
			this.currentLink.className = this.currentLink.className + ' ' + this.tabHighlightClass;
		}
	}
	
	function showTab(o)
	{
		var id = o.href.match(/#(\w.+)/)[1];
		if(tabpane.currentTab && tabpane.currentTab != id)
		{
			if(document.getElementById(tabpane.currentTab))
			{
				document.getElementById(tabpane.currentTab).style.display='none';
			}
			tabpane.currentLink.className = tabpane.currentLink.className.replace(tabpane.tabHighlightClass,'');
			
			tabpane.currentTab = id;
			tabpane.currentLink = o;
			if(document.getElementById(id))
			{
				document.getElementById(id).style.display='block';
			}
			var re=new RegExp('\\b' + tabpane.tabHighlightClass + '\\b');
			if(!re.test(o.className))
			{
				o.className = o.className + ' ' + tabpane.tabHighlightClass;
			}
		}
	}
}
