var staffArray = new Array();

function formatStaffPictures(){
	
	var divArray = new Array();
	divArray[0] = document.getElementById("divHF");
	divArray[1] = document.getElementById("divIC");
	divArray[2] = document.getElementById("divAPC");
	divArray[3] = document.getElementById("divPS");
	divArray[4] = document.getElementById("divBS");
	
	for(var x=0; x<divArray.length; x++){
		
		if(divArray[x] != null){
			var innerDivs = divArray[x].getElementsByTagName('div');
			
			
			//// add padding to center staff divs depending on how many staffers are returned ////
	
			if(x==1 || x==2) divArray[x].style.paddingLeft = "160px";	
			
			else if(x==0 || x==3 || x==4) {
				if(innerDivs.length == 1) 
					divArray[x].style.paddingLeft = "160px";
				else if(innerDivs.length == 2) 
					divArray[x].style.paddingLeft = "80px";
			}
			
			
			//// set staffer images with PDF links to display PDF icon on hover //// 
	
			for(var z=0; z<innerDivs.length; z++){
				var pdfA = innerDivs[z].getElementsByTagName('a')[0];
				
				if(pdfA != null && pdfA.getElementsByTagName('img')[0] != null){  // only apply icon to staffers with a PDF link
					var pdfLink = document.createElement('a');
					pdfLink.href = innerDivs[z].getElementsByTagName('a')[0].href;  // icon links to the PDF document
					
					var pdfIcon = document.createElement('div');
					pdfIcon.className = "hoverIcon";
					
					pdfLink.appendChild(pdfIcon);
					innerDivs[z].appendChild(pdfLink);
				}
				
				if(x<3){	//// set housefellow, APC and IC email links to show a popup instead of acting as mailto links ////
				
					if(innerDivs[z].className == "staffer"){
						staffLink = innerDivs[z].getElementsByTagName('p')[0].getElementsByTagName('a')[0];
						if(x==0)		staffLink.onclick = preparePopupHF;
						else if(x==1)	staffLink.onclick = preparePopupIC;
						else if(x==2)	staffLink.onclick = preparePopupAPC;
						staffLink.href = "";	// this prevents users from right clicking and using "copy email address"
					}
				}
				
			} // end for loop traversing innerDivs
		} 
	} // end for loop traversing divArray

}

function preparePopupHF(){
	showPopup("The House Fellows aren't");
	return false;
}

function preparePopupIC(){
	showPopup("The Involvement Coordinator isn't");
	return false;
}

function preparePopupAPC(){
	showPopup("The Academic Program Coordinator isn't");
	return false;
}

// fine, have your dumb function name
function showPopup(staffStr) {

	var outString = staffStr + " able to respond to emails during the summer. Instead, try emailing one of the professional staff members for your hall.";

	var staffLink;
	
	// get AC name and email, if present
	if(document.getElementById("staffer4_1") != null) {
		staffLink = document.getElementById("staffer4_1").getElementsByTagName('p')[0].getElementsByTagName('a')[0];
		outString += '<br/><br/>Area Coordinator: <a href="' + staffLink.href + '">' + staffLink.innerHTML + '</a>';
	}
	
	// get RLC name and email, if present
	if(document.getElementById("staffer5_1") != null) {
		staffLink = document.getElementById("staffer5_1").getElementsByTagName('p')[0].getElementsByTagName('a')[0];
		outString += '<br/><br/>Residence Life Coordinator: <a href="' + staffLink.href + '">' + staffLink.innerHTML + '</a>';
	}
	
	outString += '<br/><br/><a href="javascript:closePopup();">Close</a>';

	// the screen -- goes behind the popup to shade the rest of the page
	var wilbur = document.createElement('div');
	wilbur.id = "screen";

	// the popup div, contains the message
	var orville = document.createElement('div');
	orville.id = "popup"
	orville.innerHTML = outString;
	
	// append elements to DOM
	var bod = document.getElementsByTagName('body')[0]; // i want your bod
	if(typeof document.body.style.maxHeight != "undefined") // check for IE6
		bod.appendChild(wilbur);
	bod.appendChild(orville); //tod man, by toddy fantasies
	
	orville.style.display = "block";
	if(typeof document.body.style.maxHeight != "undefined")
		wilbur.style.display = "block";
	else
		orville.style.position = "absolute";
	
	//return false;
}

function closePopup() {
	var bod = document.getElementsByTagName('body')[0]; // more, more!
	bod.removeChild(document.getElementById('popup'));
	if(typeof document.body.style.maxHeight != "undefined")
		bod.removeChild(document.getElementById('screen'));
}
