/**
 * @author - dirkjan@accensible.nl
 */


//------------------------------------------------------------------
/* Responsible to handle all functions 
 * which need to be called in the initialize/start phase.
 *
 */
function init(){	
	var W3CDOM = (document.createElement && document.getElementsByTagName); 
	if (W3CDOM) { 
		if(document.getElementById("dlist")) { toggleFaq('dlist','dt'); }
	}	
}	

function hasClass(target, theClass) {
	var pattern = new RegExp("(^| )" + theClass + "( |$)");
	if (pattern.test(target.className))	{ return true;	}
	return false;
}

function toggleFaq(el,tname) {
	// based on script found on http://bonrouge.com/~togglit
	clickers=document.getElementById(el).getElementsByTagName(tname);
	
	for (i=0; i<clickers.length; i++) {
		clickers[i].className="clicker";
		
		clickers[i].onclick=function() {
			toggleNext(this,tname)
	  	}
	  toggleNext(clickers[i],tname,1);
 	}
}

function toggleNext(el,tname,first) {
	 var next=el.nextSibling;
	 var tags=el.parentNode.getElementsByTagName(tname);
	 while(next.nodeType!=1) { next=next.nextSibling;} // make sure ie and firefox take the same next Sibling
	 
	 if(!hasClass(next,"open")) { next.className = "closed"; }
	 
	  if (first!=1){
	   for (i=0; i<tags.length; i++) {
	   var tohide=tags[i].nextSibling;
		   while(tohide.nodeType!=1) {
		    	tohide=tohide.nextSibling;
		   }	
		   if (tohide!=next){
		   		if(!hasClass(next,"open")) { next.className="open"; } else { next.className="closed";  }	
				if(!hasClass(el,"open")) { el.className+=" open"; } else { el.className="clicker"; }	    
			   	tohide.className="closed";
			 	tags[i].className="clickers";
		    }
	  }
 	}
} 

window.onload = init;
