// core Basementia classes


//we use Scott Andrew's popular and robust addEvent function.
function addEvent (object, userAction, func, useCapture){
			if(!document.getElementById || !document.createTextNode){return;}
			if(object.addEventListener){
				object.addEventListener(userAction, func, useCapture);
				return true;
			}else if(object.attachEvent){
					var result=object.attachEvent('on'+userAction, func);
					return result;
			}else{
					object['on'+userAction]=func;
			}

		}
		
//this is our proprietary (if not very imaginative) original getElementsByClassName function, copyright 2009 by Basementia.

function findInArray(arrayHaystack, stringNeedle){//think there is an existing keyword for this...
	
	}

function findTargetInNodeArray(nodeArray, target){
	var found = new Array();
	
	for (var node=0; node<nodeArray.length; node++){
		//alert('using '+node+' as the key to '+nodeArray+' returns '+nodeArray[node]);
		if(!nodeArray[node]){continue;}//sends it to next loop, right?
		var currentNode = nodeArray[node];
		if(currentNode.nodeType == 1){
			if(currentNode.getAttribute('class') == target){//this wouldn't actually work if the attribute used two class names...
				found.push(currentNode);
				alert('findTarget function: currentNode is '+currentNode.nodeName);
				}
			}
		}
	if(!found){return false;}
	return found;
	}

function findAllTheNodes(targetNode){
	
	if(!targetNode){return false;}
	var found = new Array();
	found.push(targetNode);
	alert('found '+targetNode);
	if(targetNode.hasChildNodes()){
		alert('target has childNodes');
		for( var i=0; i<targetNode.childNodes.length; i++ ){
			alert('of type '+targetNode.childNodes[i].nodeType);
			if(targetNode.childNodes[i].nodeType == 1){			
				if( targetNode.childNodes[i].hasChildNodes() ){
					var findMore = findAllTheNodes(targetNode.childNodes[i]);
					for (var x in findMore){
						found.push(findMore[x]);
						alert('found node '+findMore[x]);
						}//end for loop
					}else{
						found.push(targetNode[i]);
						alert('found node '+targetNode[i]);
				}
			}
		}
	}//else{alert('no child nodes.');}
	return found;
}

function getElementsByClassName(targetNode, targetName){//the new version: appropriately brief.
	
	var nodeArray = findAllTheNodes(targetNode);
	
	alert('about to examine every node from '+nodeArray[0]+' to '+nodeArray.length);

	var results = findTargetInNodeArray(nodeArray, targetName);
	
	alert('className function will return: first result in array is '+results[0]);//confirmed: it is an array up to this point
	
	return results;
	
}

/*

this is the old version:

function getElementsByClassName(nodeArray, target){//to four levels...  a bit wordy.
	
	for (h=0; h<nodeArray.length; h++){
	var node = nodeArray[h];
	if(node.getAttribute('class')==target){found.push(node);}
	for(var i=0; i<node.childNodes.length; i++){
		firstGenNode = node.childNodes[i];
		if(firstGenNode.nodeType == 1){
			if(firstGenNode.getAttribute('class')==target){
				found.push(node.childNodes[i]);
			}
		}
		if(firstGenNode.hasChildNodes()){
			for(var j=0; j<firstGenNode.childNodes.length; j++){
				secondGenNode = firstGenNode.childNodes[j];
				if(secondGenNode.nodeType == 1){
					if(secondGenNode.getAttribute('class')==target){
						found.push(secondGenNode);
					}
				}
				if(secondGenNode.hasChildNodes()){
					for(var k=0; k<secondGenNode.childNodes.length; k++){
						thirdGenNode = secondGenNode.childNodes[k];
						if(thirdGenNode.nodeType == 1){
							if(thirdGenNode.getAttribute('class')==target){
								found.push(thirdGenNode);
							}
						}
						if(thirdGenNode.hasChildNodes()){
							for(var ell=0; ell<thirdGenNode.childNodes.length; ell++){
								fourthGenNode = thirdGenNode.childNodes[ell];
								if(fourthGenNode.nodeType == 1){
									if(fourthGenNode.getAttribute('class')==target){
										found.push(fourthGenNode);
									}
								}
							}
						}
					}
				}
			}
		}//end descendent nodes of the firstGenNode
	}
	}
	//alert(found);
	return found;

}
*/