/*
	These are all functions that pertain to showing and hiding areas on a page
*/


function toggleVisibility(source,state) {
	//source = document[source];
	if (state == undefined){
		if (source.style.display == 'none') {
			source.style.display = '' ;
			} else {
			source.style.display = 'none' ;
		}
	} else {
		if (state == 'visible'){
			state = '';
		}
		if (source.style.display != state) {
			source.style.display = state;
		}
	}
}


function initPods(){
	// this holds the array of Pod Families
	Pods =  new Array();
	
	// set the default family name
	defaultFamName = 'defaultPodFamily';
	
	// add the default pod family to the array
	addPodFamily();
}


/*
	Toggles the visibility of all the pods in a Pod family
*/
function togglePodVisibility(source,state,podFamily ) {
	//source = document[source];
	
	// if a pod Family was not provided, create a default family
	// otherwise confirm the existence of the pod family or create a new one
	if (podFamily == undefined || podFamily == null) {
		// make the pod family the default family
		podFamily = defaultFamName;
		
	} else if (! podFamilyExists(podFamily) ) {
		// add the new podFamily
		// the new family name is returned
		podFamily = addPodFamily(podFamily);
	}
	
	// this will toggle the visibility of all pods,
	// and add new pods
	var isInArray = false;
	var podTmp = Pods[podFamily];
	
	toggleVisibility(source,state);
	
	// set the literal string for the display property
	if (state == 'visible'){
		oppositeState = literalOppositeState = 'none';
	} else {
		oppositeState = 'visible';
		literalOppositeState = '';
	}
	
	// loop through the pods and display or hide them
	for (var i = 0; i < podTmp.length; i++){
		if (source == podTmp[i]){
			isInArray = true;
		}else{
			if ( podTmp[i].style.display != literalOppositeState){
				toggleVisibility( podTmp[i],oppositeState );
			}
		}
	}
	
	// add this pod to the array if it is not already present
	if (!isInArray){
		podTmp.push(source);
	}
}

/**
	adds a new pod family to the Pods array
*/
function addPodFamily(podFamily) {
	
	if (podFamily == undefined || podFamily == null) {
			// return the default name without adding to the array if it is already defined
			if (podFamilyExists(defaultFamName)){
				return defaultFamName ;
			} else {
				podFamily = defaultFamName;
			}
	}
	
	// make the new family a new array
	Pods.push(podFamily);
	Pods[podFamily] = new Array();
	
	//return the new family name
	return podFamily;
}


/**
	confirms the existence of a pod family
	returns Boolean
*/
function podFamilyExists(podFamily) {
	// if null was passed stop processing
	if (podFamily == null || podFamily == undefined) {
		return false;
	}
	
	// check for existence of the family and return the result
	if (!Pods[podFamily] ) {
		return false;
	} else {
		return true;
	}
	
}

function initTogglePodVisibility(source,podFamily) {
	//source = document[source];
	// add the podFamily
	podFamily = addPodFamily(podFamily);
	
	// toggle the pod to visible
	togglePodVisibility(source,'visible',podFamily);
}

/*
	Init the pods
*/
initPods();