/**
 * Tab Navigation
 * 
 * Based on having a tab nav as a UL of links, toggling the display of a
 * target boxes.
 */

function TabView(tabID)
{
	var tab = $(tabID);
	var targetID = tabID.substring(5,tabID.length);//5 for 'view_'
	var target = $(targetID);
	var targetParent = target.getParent();
	var targetNode = target.nodeName;
	var tabParent = tab.getParent().getParent();
	var node = null;

	//Tab content display

	target.style.visibility = "hidden";// This so page will handle spacing
	target.style.display = "block";    // before tab is visible

	for (i=0;i<targetParent.childNodes.length;i++)// Hide each node of the same type within parent
	{
		node = targetParent.childNodes[i];
		if(node.nodeName == targetNode && node.id != targetID)
			node.style.display = "none";
	}

	target.style.visibility = "visible";

	//Tab display 

	for (i=0;i<tabParent.childNodes.length;i++)// Hide each node of the same type within parent
	{
		node = tabParent.childNodes[i];
		if(node.nodeName == "LI")
			node.className = (node.childNodes[0] && node.childNodes[0] == tab)? 'Tab-Nav-Item Tab-Nav-Active':'Tab-Nav-Item';
	}	
	
	tab.blur();
	return false;
}

window.addEvent('domready', function() { 

	$$('div.Tab-Nav').getElements('ul a').each(function(Btns,Btn_n) {
		Btns.each(function(el,n) {
			el.removeProperty('href');
			el.addEvent('click', function(e) {
				TabView(this.id);
			});
		});
		TabView((Btns[0]).id);
	});

});
