//array that is used to keep track of dropdowns that have been opened at least once
var dropDownsArr = [];
//function that readjusts the positioning of the drop downs in case the document has been resized
//function is only called once per opened drop down
//s is the id of the element that needs adjusting
function adjustDDPos(s){
	//gettin our element reference
	var targetDD = document.getElementById(s);
	//the start x position that the element was originally at
	var startX = 0;
	//document width
	var docWidth = 0;
	//we get the start x position
	var startX = Number(targetDD.style.left.substring(0, targetDD.style.left.indexOf("px"))) - 190;
	//getting document width
	var docWidth = document.body.clientWidth;
	//alert("testing: " + docWidth);
	//creating the new left/x position
	var newLeft =  (docWidth - 750)/2 + startX;
	targetDD.style.left = String(newLeft)+"px";
}
//function that is called when we want to show a dropdown
// s is the id 
// t is the tier number - we need this to close all other drop downs that may be on the same level
function showDD(s, t){
	
if(document.getElementById(s) != null){
	//closing all of the selected teir's drop downs
	closeDD(t);	
	//checking to see if the drop down is the dropdowns array
	//if not we know it is the first time opening the drop down and we need to adjust its positioning
	if(dropDownsArr.toString().indexOf(s) == -1){
		dropDownsArr.push([s,t]);
		adjustDDPos(s);
	}
	//making the drop down visible
	
		var dd = document.getElementById(s).style.visibility = "visible";
	}
}

//function used to close all dropdowns on a teir and all children teirs
function closeDD(t){
	
	//looping through our cataloged drop downs
	for(var i = 0; i < dropDownsArr.length; i++){
		var teirNum = dropDownsArr[i][1];
		//if the drop down is on the current teir or on a child teir we close it
		if( teirNum >= t){
			document.getElementById(dropDownsArr[i][0]).style.visibility = "hidden";
			
		}
		
	}
	
}


