/*
Requires:
	addLoadEvent()
*/

// TODO: KEEP THIS SOMEWHERE
function getNextElement(objSource, strNextTagName)
{
	while( objSource.nextSibling )
	{
		objSource = objSource.nextSibling;
		
		if( objSource.nodeType == 1 /* Element Node */ )
		{
			if( objSource.tagName.toLowerCase() == strNextTagName.toLowerCase() )
			{
				return objSource;
			}
		}
	}
	
	return false;
}

/* Make FAQ questions toggle the answers */
function activate_faq()
{
	var lists;
	var k, m;
	var terms, definitions;
	var objNextDef;
	
	lists = document.getElementsByTagName('dl');
		
	// Loop through all the question/answer lists
	for(k = 0; k < lists.length; k++)
	{
		if( lists[k].className != "toggle" )
		{
			alert("ignoring list w/ classname: " + lists[k].className);
			continue;
		}
	
		terms = lists[k].getElementsByTagName('dt');
		
		// Activate the terms
		for(m = 0; m < terms.length; m++)
		{
			terms[m].className = "scripted";
			terms[m].onmouseover = function()
			{
				this.className = 'scripted_hover';
			}
			terms[m].onmouseout = function()
			{
				this.className = 'scripted';
			}
			
			objNextDef = getNextElement(terms[m], 'dd');
			if( objNextDef != false )
			{
				objNextDef.className = 'scripted_hidden';
			}
			
			terms[m].onclick = function()
			{
				var obj = getNextElement(this, 'dd');

				if( obj != false )
				{
					obj.className = (obj.className == 'scripted_hidden') ? '' : 'scripted_hidden';
				}
			}
		}
	}
}

addLoadEvent(activate_faq);