
/*
CLASS: Swappable
DESCRIPTION: overlapping html elements that are swappable
*/

function Swappable(){
	this.contents = new Array();
	this.navigation = new Array();
	this.currentIdx = 0;
	//css classes for nav
	this.normalClass = null;
	this.selectedClass = null;
}//end function Swappable

//begin class method definitions for Swappable
Swappable.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
	},
	
	setCurrent: function(contentID){
		var idx = this.getContentIndex(contentID);
		this.currentIdx = idx;
	},
	
	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
	},
	
	swap: function(contentID){
		this.setCurrent(contentID);
		this.swapContent();
		this.swapNav();
	},
	
	swapContent: function(){
		var i = 0;
		for ( i=0; i < this.contents.length; i++ ){
			if ( i == this.currentIdx ){
				this.contents[i].show();
			} else {
				this.contents[i].hide();
			}//end if
		}//end for
	},
	
	setClassNames: function(normal,selected){
		this.normalClass = normal;
		this.selectedClass = selected;
	},
	
	swapNav: function(){
		if ( this.normalClass == null ){ return; }
		var i = 0;
		for ( i=0; i < this.navigation.length; i++ ){
			if ( i == this.currentIdx ){
				this.navigation[i].setClassName(this.selectedClass);
			} else {
				this.navigation[i].setClassName(this.normalClass);
			}//end if
		}//end for
	}
};
//end class method definitions for Swappable

/*
CLASS: ContentElement
DESCRIPTION: descriptiongoeshere
*/

function ContentElement(id){
	this.id = id;
	this.exists = false;
	this.htmlObj = null;
	this.register();
}//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
