Collapsables=function(){
	// go through all collapse-sections
	this.sections=new Array;
	var sections=getElementsByClassName("collapse-section",document);
	for(var i=0;i<sections.length;i++){
		this.sections[this.sections.length]=new CollapseSection(sections[i]);
	}
	addClass(document.getElementsByTagName("body")[0],"collapsables-ok");
}

// destroy
Collapsables.prototype.destroy=function(){
	for(var h=0;h<this.sections.length;h++){
		var section=this.sections[h];
		for(var i=0;i<section.items.length;i++){
			section.items[i].button.context=section.items[i].button.onclick=null;
			section.items[i].DOMObject.onmouseover=section.items[i].DOMObject.onmouseout=null;
			section.items[i].DOMObject.context=section.items[i].DOMObject.onclick=null;
		}
	}
}

// group of collapsable items
CollapseSection=function(obj){
	this.DOMObject=obj;
	if(this.DOMObject.className.match("single-selection")) this.singleSelection=true;
	if(this.DOMObject.className.match("fully-clickable")) this.fullyClickable=true;
	this.items=new Array;
	var items=getElementsByClassName("collapse-item",this.DOMObject);
	for(var i=0;i<items.length;i++){
		this.items[this.items.length]=new CollapseItem(items[i],this);
	}	
}

// hide all but exception
CollapseSection.prototype.hideAll=function(exception){
	//alert(exception.DOMObject.tagName);
	for(var i=0;i<this.items.length;i++){
		if(this.items[i]==exception){
			addClass(this.items[i].DOMObject,"show");
		} else {
			removeClass(this.items[i].DOMObject,"show");
		}
	}
}

// collapsable item
CollapseItem=function(obj,section){
	this.DOMObject=obj;
	this.section=section;
	// behaviour for the whole item
	this.DOMObject.context=this;
	this.DOMObject.onmouseover=function(){addClass(this,"hover");}
	this.DOMObject.onmouseout=function(){removeClass(this,"hover");}
	if(this.section.fullyClickable){
		this.DOMObject.onclick=function(){
			if(this.context.section.singleSelection) this.context.section.hideAll(this.context);
			else this.context.toggle(this.context);
		}
	}
	// create collapse button
	this.button=document.createElement("a");
	this.button.href="#";
	this.button.context=this;
	this.button.onclick=function(e){
		cancelBubble(e);
		if(this.context.section.singleSelection) this.context.section.hideAll(this.context);
		else this.context.toggle(this.context);
		return false;
	}
	if(this.DOMObject.className.match("collapse-button")) var hook=this.DOMObject;
	else var hook=getElementsByClassName("collapse-button",obj)[0];
	hook.appendChild(this.button);
}

// open/collapse item
CollapseItem.prototype.toggle=function(obj){
	if(obj.DOMObject.className.match("show")){
		removeClass(obj.DOMObject,"show");
	} else {
		addClass(obj.DOMObject,"show");
	}
}




/* de volgende functies zijn nodig voor ondersteuning, maar kunnen beter in global.js geplaatst worden, 
omdat andere functies (zoals navigation.js) er ook gebruik van maken. Je kan ze vervolgens weghalen in 
navigation.js */




// add or remove classes
function addClass(obj,cName) { 
	removeClass(obj,cName); 
	return obj.className+=(obj.className.length>0?' ':'')+cName; 
}

function removeClass(obj,cName) {
	return obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); 
}

// cancel event propagation
function cancelBubble(e){
	if(window.event){
		window.event.cancelBubble=true;
		window.event.returnValue=true;
	}
	if(e && e.stopPropagation && e.preventDefault){
		e.stopPropagation();
		e.preventDefault();
	}
}

// retrieve elements of certain class
function getElementsByClassName(cName,baseElement){
	var results=new Array;
	var objs=document.getElementsByTagName("*").length>0 ? baseElement.getElementsByTagName("*") : baseElement.all;
	if(!objs) objs=baseElement.all;
	for(var i=0;i<objs.length;i++){
		if(objs[i].className.match(cName)) results[results.length]=objs[i]
	}
	return results;
}

// properties
function props(m){
	var r=m.tagName+":\n";
	for(i in m) r=r+i+" / ";
	return r;
}