
var Collapse = new Object();

Collapse.blocks = new Array();
Collapse.blocklookup = new Array();

EventUtil.addEventHandler(
	window,
	'load',
	function(){
		//setTimeout('Collapse.init();',1000);
		Collapse.init();
	}
);

Collapse.add = function (hideId,controlId)
{
	this.blocks[this.blocks.length] = new Array();
	this.blocks[this.blocks.length-1]['hideId'] = hideId;
	this.blocks[this.blocks.length-1]['controlId'] = controlId;
	//alert(this.blocks[this.blocks.length-1]['collapse']);
	this.blocklookup[controlId] = hideId;

}
Collapse.init = function(){
	for (var b = 0; b < this.blocks.length; b++){
		var block = this.blocks[b];
		controlObj = document.getElementById(block['controlId'])
		controlObj.style.cursor = 'pointer';
		EventUtil.addEventHandler(
			controlObj,
			'click',
			function(){
				var e = EventUtil.getEvent();
				Collapse.change(e.target.id);
			}
		);
		hideObj = document.getElementById(block['hideId']);
		if (
			hideObj.className == "collapsable_collapsed"
		){
			Collapse.hide(hideObj, controlObj);
		} else {
			Collapse.show(hideObj, controlObj);
		}
	}
}
Collapse.hide = function(hideObj, controlObj)
{
	hideObj.style.display = 'none';
	hideObj.className = 'collapsable_collapsed';
	controlObj.className = "ctrl_collapsed";
}
Collapse.show = function(hideObj, controlObj)
{
	hideObj.style.display = 'block';
	hideObj.className = 'collapsable_expanded';
	controlObj.className = "ctrl_expanded";
}
Collapse.change = function(controlObjId){
	hideObjId = Collapse.blocklookup[controlObjId];
	hideObj = document.getElementById(hideObjId);
	controlObj = document.getElementById(controlObjId);
	
	if (hideObj.style.display == 'block'){
		Collapse.hide(hideObj, controlObj);
	} else {
		Collapse.show(hideObj, controlObj);
	}
}
