/*---------------------------------------------------------------------
	JavaScript DOM Tabs function

	REQUIREMENTS:
		script.aculo.us and prototype
		div id="Tabs" surrounding <ul> with anchors inside links.
	
	USAGE:
		Make sure function initRollovers() is called in the window.onload event (found in /assets/js/init.js).
-----------------------------------------------------------------------*/

function initTabs() {
	if (!document.getElementById) return

	var oTabs = document.getElementById('Tabs');
	var oTabUL = getFirstChild(oTabs);

	for (var j=0; j < oTabUL.childNodes.length; j++) {
		if (oTabUL.childNodes[j].nodeName=="LI") {
			var oTempA = getFirstChild(oTabUL.childNodes[j]);
			sTempTab = oTempA.getAttribute('href');
			sTempTab = sTempTab.substring(1,sTempTab.length);
			oTempA.setAttribute("href","javascript:ShowTab('" + sTempTab + "')");
			oTempA.setAttribute("rel",sTempTab);
		}
	}
	ShowTab('Tab1');
}

function HideTabContents() {
	var aDIVs = document.getElementsByTagName('div');
	var oTabContentBlock = document.getElementById('TabContentBlock');
	
	for (var i = 0; i < aDIVs.length; i++) {
		if (cssClassActions('check',aDIVs[i],'TabContent')) {
			//Element.hide(aDIVs[i]);
			aDIVs[i].style.display='none';
		}
	}
	oTabContentBlock.style.display='block';
}

function ShowTab(sTab) {
	HideTabContents();
	
	var oTabs = document.getElementById('Tabs');
	var oTabUL = getFirstChild(oTabs);

	for (var j=0; j < oTabUL.childNodes.length; j++) {
		if (oTabUL.childNodes[j].nodeName=="LI") {
			var oTempA = getFirstChild(oTabUL.childNodes[j]);
			sTempTab = oTempA.getAttribute('rel');
			
			/*	IE has full link instead of just tab name, split on the # character if it exists */
			iTempPoundLoc = sTempTab.indexOf('#')
			if (iTempPoundLoc >= 0) {
				sTempTab = sTempTab.substring(iTempPoundLoc+1,sTempTab.length);
			}
			iPoundLoc = sTab.indexOf('#')
			if (iPoundLoc >= 0) {
				sTab = sTab.substring(iPoundLoc+1,sTab.length);
			}

			if (sTempTab == sTab) {
				cssClassActions('add',oTabUL.childNodes[j],'SelectedTab');
			} else {
				cssClassActions('remove',oTabUL.childNodes[j],'SelectedTab');
			}
		}
	}
	var oTabAnchor = document.getElementById(sTab);
	
	if (oTabAnchor.parentNode != null) {
		var oTabContent = oTabAnchor.parentNode;
		//new Effect.Appear(oTabContent);
		oTabContent.style.display='block';
	}
}


/*---------------
	Add to window.onload event
---------------*/
addEvent(window, 'load', initTabs, false);
