if (document.getElementById && document.getElementsByTagName && document.createElement) {
	window.onload = initToggleCategories;
}

function initToggleCategories() {
	var as = document.getElementById('toggle').getElementsByTagName('a');
	for (var i = 0; i < as.length; i++) {
		as[i].onclick = function() {
			toggle(this);
			return false;
		}
	}
	// Activate the first tab by default or previously selected tab from cookie
	var cookieVal = null;
	try {
		cookieName = "tab_" + document.getElementById("pageIdentifier").innerHTML;
		cookieVal = getCookie(cookieName);
	} catch(e){}
	idx = (cookieVal != null)?cookieVal.substring(3)-1:0;
	toggle(as[idx]);
	if (cookieVal !=null){
		showhideContent(cookieVal);
	}
}

function toggle(l) {
	// Try to get a reference to an element with the id 'current' (a previously active tab header)
 	var oldCurrent = document.getElementById('current');
	// If this element exists, remove its ID attribute
	if (oldCurrent) oldCurrent.removeAttribute('id');
	// Add the ID attribute with value 'current' to the newly active tab header (LI element)
	l.parentNode.setAttribute('id', 'current');
}

// Displays content contained within each tab
function showhideContent(layer_ref) {
	if(showhideContent.last == undefined) {
		showhideContent.last = document.getElementById('tab1');
	} 
	showhideContent.last.style.display = 'none';
	showhideContent.last = document.getElementById(layer_ref);
	if(showhideContent.last != undefined)
	{
		showhideContent.last.style.display = 'block';
		try {
			cookieName = "tab_" + document.getElementById("pageIdentifier").innerHTML;
			setCookie(cookieName,layer_ref);
		} catch(e){}
	}
}
