// This section equalizes the heights of the columns

matchColumns=function(){ 
     var divs,contDivs,maxHeight,divHeight,d; 
     // get all <div> elements in the document 
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 
     // initialize maximum height value 
     maxHeight=0; 
     // iterate over all <div> elements in the document 
     for(var i=0;i<divs.length;i++){ 
          // make collection with <div> elements with class attribute 'container' 
          if(/\bcolumn\b/.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d; 
                // determine height for <div> element 
                if(d.offsetHeight){ 
                     divHeight=d.offsetHeight; 					
                } 
                else if(d.style.pixelHeight){ 
                     divHeight=d.style.pixelHeight;					 
                } 
                // calculate maximum height 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 
     } 
     // assign maximum height value to all of container <div> elements 
     for(var i=0;i<contDivs.length;i++){ 
          contDivs[i].style.height=maxHeight + "px"; 
     } 
} 

//Runs functions when page loads 

function startFunctions(){ 
     if(document.getElementsByTagName){
		setPeople(); //  picks the profile to show and cycles through them
	 	checkOld(); // displays the current event items
		checkOldNews(); // displays the news items
        matchColumns();	// balances the columns
		cacheImages();
     } 
} 

// End of column equalization section


//Make new text window -- This function loads external links in new browser windows. The new window is 70% of the height and 85% of the width of the current window and should be centered. If the current window is not maximized or otherwise small, the new window will be even smaller.  Function checkWindowSize() gets dimensions of current window.  The "noResize" keeps the dimensions of the window set out in the calling function. The value of noResize can be any text string.

// This function is for pages. For images, see makeNewWindow() below

var newTextWindow;
function makeNewTextWindow(url,wid,hgt,noResize){
	var right = 100;
	var down = 50;
	if (noResize){
	} else {
	checkWindowSize();
	if (screen.availHeight){
	hgt = screen.availHeight * .7;
	wid = screen.availWidth * .85;
	}
	right = screen.availWidth * .075;
	down = screen.availHeight * .05;
	
	if (myWidth < wid){wid = myWidth * .8}
	if (myHeight < hgt){hgt = myHeight * .8}
	}
	var parameters = "status,menubar,location,resizable,titlebar,toolbar,height=" + hgt + ",width=" + wid + ",left=" + right + ",top=" + down + ",scrollbars";
	if(!newTextWindow || newTextWindow.closed){
	newTextWindow = window.open(url,"",parameters)
	if (!newTextWindow.opener) {
	newTextWindow.opener = window;
	}
	} else {
	newTextWindow.location = url;
	newTextWindow.focus()
	}
}

var myWidth = 0, myHeight = 0;  // These will be current window's dimensions

//  This funcion gets the width and height of the current window. This information is then used so that the new window will not cover the current one.

function checkWindowSize() {
  //var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

// End function to get size of current window

// Section to hide old items on home page.  The dl tags in the news section only need a title attribute with the 
// date of the event. When that date passes, the entire paragraph won't display.  
// The format is: title = "Event Date: January 1, 2006"
// The text up to the colon (:) is ignored and can be anything, except a colon. The date must be in the format of:
// Full month name, day, year (or other format that JavaScript's Date object recognizes.
  
var today = new Date(); // get the current date. Obviously depends on user's computer's clock being correct

// following function runs onload of the page

var startNumber = 0;
function checkOld(){
	var pTags = document.body.getElementsByTagName("dl");  // get all the dl tags
	var newsTags = new Array();
	var index = 0;
	for (i=0; i < pTags.length; i++){   // make array of the dl tags with titles
		if (pTags[i].title){
			newsTags[index++] = pTags[i];
		}
		}
	
	// get the expiration date out of the title attribute and, if the date has passed, set CSS display to none
	
	var counter=0;
	var numberNew = 0;
	//if(!eventsToDisplay){var eventsToDisplay = 2};
	if(startNumber >= (newsTags.length)){startNumber = 0}
	for (i=0; i < newsTags.length; i++){
		if (newsTags[i].title.match(/^Event Date/)){
			var expirationText = newsTags[i].title;
			var expirationText = expirationText.replace(/^.+: /, ""); 
			var expirationDate = new Date(expirationText);
			var dateInMs = expirationDate.getTime();
			dateInMs += (1000 * 60 * 60 * 20);  //event should disappear at 8 PM on day of event
			expirationDate.setTime(dateInMs);
			if (expirationDate < today){
			 	newsTags[i].style.display = "none";
			} else {
				numberNew++;
			if (counter >= startNumber && counter < (startNumber + eventsToDisplay) ){
			 	newsTags[i].style.display = "block";
				counter++;
			} else {newsTags[i].style.display = "none";
			counter++;
			}
			};
		};
		};
		if (counter == 0){   //if all events are old, display the two most recent
			newsTags[newsTags.length - 1].style.display = "block";
			newsTags[newsTags.length - 2].style.display = "block";
			
			}
		startNumber += eventsToDisplay;
		//if (numberNew <= eventsToDisplay){document.getElementById('more').innerHTML = ""}
}

// Makes new window for images. Does not resize for avaiable size of screen. This is for images. For pages, see makeNewTextWindow() above

var newWindow;
function makeNewWindow(img,wid,ht,msg){
	var winWid = parseInt(wid) + 40;
	var winHt = parseInt(ht) + 100;
	if(screen.availHeight < winHt + 100){
	winHt = screen.availHeight - 70}
	var features = "\"status,scrollbars,height=" + winHt + ",width=" + winWid + "\"";
	if(!newWindow || newWindow.closed){
	newWindow = window.open("", "", features)
	if (!newWindow.opener) {
	newWindow.opener = window
	}
	newWindow.moveTo(100,0);
	var winContent = "<html><head><title>Pop-Up Window</title></head>";
	winContent += "<body bgcolor='#f5eed8'><div align='center'><img border = '0' src='" + img + "' width='" + wid + "' height='" + ht + "'></div>";
	if (msg != null){
	winContent += "<p align='center' style='color: #cc0033; font-family: sans-serif; font-size: 12pt'>" + msg + "</p>";
	}
	winContent += "<p><form action='' name='but'><div align='center'><input type='button' value='Close this Window' name='btnCancel' onclick='window.close();'></form></div></p></body></html>";
	newWindow.document.write(winContent);
	newWindow.document.close();
	} else {
	newWindow.focus()
	}
}

// counts the news items and displays the first group. Variable maxNews determines how many to display at one time.  News items must have a class of "news"

if (!maxNews){var maxNews = 2};
var start = 0;
function checkOldNews(){
	
	var pTags = document.body.getElementsByTagName("p");  // get all the p tags
	var newsTags = new Array();
	var index = 0;
	for (i=0; i < pTags.length; i++){   // make array of the p tags for class "news"
		if (pTags[i].className == "news"){
			newsTags[index++] = pTags[i];
		}
		}
	
	if (newsTags.length <= maxNews){document.getElementById('moreNews').innerHTML = "<a href='news/news07Fall.htm'>News Archive</a>";  // if only one screenful of news items, kill the "More" link but keep the link to the archives
	
	} else {

	if (start >= newsTags.length){start = 0};
	var counter = 0;	
	for (i=0; i < newsTags.length; i++){
			if (i >= start && counter < maxNews){
			 	newsTags[i].style.display = "block";
				counter++;
			} else {newsTags[i].style.display = "none";
			}
		};
		start += maxNews;
	}
}


function changeAdvising(){
	document.getElementById('advising').style.color = "#fc3";
	document.getElementById('divide').style.color = "#fc3";
}
function returnAdvising(){
	document.getElementById('advising').style.color = "#063A4D";
	document.getElementById('divide').style.color = "#063A4D";	
}

var lastPerson;
var anchorLinks = new Array;
var imageLinks = new Array;
var personTexts = new Array;

// These arrays will be filled out in the HEAD of the page itself

function setPeople(direction){
	var number;
	var maxNum = personTexts.length - 1;
	if (lastPerson > 0){
		if (direction==1){lastPerson++};
		if (direction==0){lastPerson--};		
		if (lastPerson > maxNum){lastPerson = 1}; 
		if (lastPerson < 1){lastPerson = maxNum}; 
		number = lastPerson;} else {
	
	//var halfNumber = Math.random()*2;
	//if (halfNumber > 1){
	//number = Math.round((personTexts.length - 11) * Math.random()) + 11;
	//if (number == 11){number = 12}
	//} else {
	number = Math.round((personTexts.length) * Math.random());
	if (number == 0){number = 1}
		
	//}
	
	//number = Math.round((personTexts.length - 7) * Math.random()) + 7;
	//if (number == 0){number = 8}
	if (number == personTexts.length){number = personTexts.length - 1}	
	lastPerson = number;}
	var personNumber = number;
	var anchorLink = anchorLinks[personNumber];
	var imageLink = imageLinks[personNumber];
	var personText = personTexts[personNumber];
	
	var theCode = "<a href='people/index-new.htm#";
	
	theCode += anchorLink;
	theCode += "'><img src='people/images/";
	theCode += imageLink;

	var MoreCode =  " <a href='people/index-new.htm#";
	MoreCode += anchorLink;
	MoreCode += "' style='text-decoration: underline'>Others</a>";
	
	
	theCode += "' alt='Photo of Featured Person' title='Click for More' width='100' height='100' border='0' align='left' /></a> <h3>SIS People</h3><span>";
	theCode += personText;
	theCode +=  " <a href='people/index-new.htm#";
	theCode += anchorLink;
	theCode += "'>More</a></span>";
	theCode += "<div id='peopleNav'><a href='#' onclick='setPeople(0); return false'>&lt;</a> Others <a href='javascript' onclick='setPeople(1); return false'>&gt;</a></div>";
	
	if (document.getElementById('bodyTextBox3')){
		document.getElementById('bodyTextBox3').innerHTML = theCode;
	}
	document.getElementById('bodyTextBox3').innerHTML = theCode;
}

// This function opens a pop-up window with text that the function supplies. This is good for short notes to pop up.

var newMessageWindow;
function makeNewMessageWindow(wid,ht,msg,head){
	var winWid = parseInt(wid) + 40;
	var winHt = parseInt(ht) + 70;
	if(screen.availHeight < winHt + 100){
	winHt = screen.availHeight - 70}
	var features = "\"status,scrollbars,height=" + winHt + ",width=" + winWid + "\"";
	if(!newWindow || newWindow.closed){
	newWindow = window.open("", "", features)
	if (!newWindow.opener) {
	newWindow.opener = window
	}
	var top = screen.availHeight/2 - winHt/2;
	var left = screen.availWidth/2 - winWid/2;
	newWindow.moveTo(left,top);
	var winContent = "<html><head><title>More Information</title>";
	winContent += "<script language=javascript>function inMainWindow(page){window.opener.location = page; window.close();}</script></head>";
	winContent += "<body bgcolor='#f5eed8'>";
	var heading = "More Information";
	if (head != null){heading = head}
	if (msg != null){
	winContent += "<h3 align='center'>" + heading + "</h3><p style='color: black; font-family: sans-serif; font-size: 10pt; margin-top: -.4em'>" + msg + "</p>";
	}
	winContent += "<p><form action='' name='but'><div align='center'><input type='button' value='Close this Window' name='btnCancel' onclick='window.close();'></form></div></p></body></html>";
	newWindow.document.write(winContent);
	newWindow.document.close();
	} else {
	newWindow.focus()
	}
}

function cacheImages(){
	
//imageLinks[1]	
var imgName = new Array;
for (var count = 1; count < imageLinks.length + 1; count++){
	var imgLink = "people/images/" + imageLinks[count];
	imgName[count] = new Image(100,100)
	imgName[count].src = imgLink;	
}
}