
/*
CLASS: Collapsable
DESCRIPTION: overlapping html elements that are Collapsable
*/

function Collapsable(){
	this.contents = new Array();
	this.navigation = new Array();
	//change innerHTML of nav?
	this.navHTML = false;
	this.showNavHTML = "-";
	this.hideNavHTML = "+";
}//end function Collapsable

//begin class method definitions for Collapsable
Collapsable.prototype = {
	register: function(contentID,navID){
		this.addContent(contentID);
		this.addNavigation(navID);
	},
	
	addContent: function(id){
		var element = new ContentElement(id);
		if ( element.exists ){
			this.contents.push(element);
		}//end if
	},
	
	addNavigation: function(id){
		var nav = new NavElement(id);
		if ( nav.exists ){
			this.navigation.push(nav);
		}//end if
	},
	
	getContentIndex: function(contentID){
		var i = 0;
		for ( i=0; i < this.contents.length; i++ ){
			if ( this.contents[i].id == contentID ){
				return i;
			}//end if
		}//end for
	},
	
	toggle: function(contentID){
		var idx = this.getContentIndex(contentID);
		if ( this.contents[idx].status == 'show' ){
			this.collapse(idx);
		} else {
			this.expand(idx);
		}//end if
	},
	
	collapse: function(idx){
		this.contents[idx].hide();
		this.contents[idx].status = 'hide';
		if ( this.navHTML ){
			this.navigation[idx].htmlObj.innerHTML = this.hideNavHTML;
		}//end if
	},
	
	expand: function(idx){
		this.contents[idx].show();
		this.contents[idx].status = 'show';
		if ( this.navHTML ){
			this.navigation[idx].htmlObj.innerHTML = this.showNavHTML;
		}//end if
	},
	
	collapseAll: function(cmdID){
		for ( idx in this.contents ){
			this.collapse(idx);
		}//end for
		if ( cmdID == null ){ return; }
		var cmdObj = document.getElementById(cmdID);
		if ( typeof(cmdObj) == null || typeof(cmdObj) == 'undefined' ){ return; }
		cmdObj.innerHTML = "<a href=\"#\" onclick=\"CN.expandAll('" + cmdID + "');return false;\">expand all</a>";
	},
	
	expandAll: function(cmdID){
		for ( idx in this.contents ){
			this.expand(idx);
		}//end for
		if ( cmdID == null ){ return; }
		var cmdObj = document.getElementById(cmdID);
		if ( typeof(cmdObj) == null || typeof(cmdObj) == 'undefined' ){ return; }
		cmdObj.innerHTML = "<a href=\"#\" onclick=\"CN.collapseAll('" + cmdID + "');return false;\">collapse all</a>";
	}
	
};
//end class method definitions for Collapsable

/*
CLASS: ContentElement
DESCRIPTION: descriptiongoeshere
*/

function ContentElement(id){
	this.id = id;
	this.exists = false;
	this.htmlObj = null;
	this.register();
	this.status = 'show'; //show or hide
}//end function ContentElement

//begin class method definitions for ContentElement
ContentElement.prototype = {
	register: function(){
		var element = document.getElementById(this.id);
		if ( typeof(element) == null || typeof(element) == 'undefined' ){
			this.exists = false;
		} else {
			this.exists = true;
			this.htmlObj = element;
		}//end if
	},
	
	show: function(){
		this.htmlObj.style.display = 'block';
	},
	
	hide: function(){
		this.htmlObj.style.display = 'none';
	}
};
//end class method definitions for ContentElement

/*
CLASS: NavElement
DESCRIPTION: descriptiongoeshere
*/

function NavElement(id){
	this.id = id;
	this.exists = false;
	this.htmlObj = null;
	this.register();
}//end function NavElement

//begin class method definitions for NavElement
NavElement.prototype = {
	register: function(){
		var element = document.getElementById(this.id);
		if ( typeof(element) == null || typeof(element) == 'undefined' ){
			this.exists = false;
		} else {
			this.exists = true;
			this.htmlObj = element;
		}//end if
	},
	
	setClassName: function(className){
		this.htmlObj.className = className;
	}
};
//end class method definitions for NavElement
