// JavaScript Document
/*
	Copyright (c) 2004 Duke University
  	Author: Justin Leonard
  	Released under the GNU General Public License
	
	Functions for finding the dimensions of the active page. These scripts are used to resize
	the page to fit better in the users window.
*/

/*
	Returns the height of the active window.
*/
function findActiveHeight()
{
	if(window.innerHeight != null)
		return window.innerHeight;
	if(document.body.clientHeight != null)
		return document.body.clientHeight;
	return null;
}

/*
	Changes the height of a element, based using the W3C's DOM and CSS style
*/

function changeHeight(elem, height)
{
	document.getElementById(elem).style.height = height; 
}

function changeTop(elem, top)
{
	document.getElementById(elem).style.top = top + "px"; 
}

/*
	Site specific fucntion to alter the different parts of the Oasis web page.
	
	Finds the height of the window, then calculates appropriate sizes for the
	named components.
*/

function sizePage()
{
	textHeight		= document.getElementById('MainText').scrollHeight;
	
	if(textHeight < 690)
		textHeight = 690;
	if(document.getElementById('Container') != null) changeHeight('Container', textHeight + 150 + "px");
	if(document.getElementById('ContentPane') != null) changeHeight('ContentPane', "100%");
	if(document.getElementById('MainText') != null) changeHeight('MainText', "100%");
	if(document.getElementById('Navigation') != null) changeHeight('Navigation', "100%");
	document.getElementById('Container').style.visibility = "visible";
	//alert(document.getElementById('MainText').scrollHeight);
}

// NOTE: KEEP MAX_NUM TO BE THE MAXIMUM PICTURES/HEADING PICTURES IN FOLDER THAT YOU WANT TO RANDOMIZE BETWEEN -- IF MUCH BIGGER, MAY CAUSE DELAY IN SELECTING RANDOM NUMER -- ALSO TRY TO KEEP THE NUMBERS CONSECUTIVE
function setImages()
{
	var min_num = 0;  
	var max_num = 8; 
	var diff = max_num-min_num+1 ; 
	var rnd_number = Math.floor(Math.random()*diff + min_num); 
	if(document.getElementById('HeaderImages') != null) document.getElementById('HeaderImages').innerHTML = '<img src="images/header/image' + rnd_number + '.jpg" onError="setImages()"> ';
}

//USED To Scroll to an element in a page such as a div
function ScrollToElement(name){

  var selectedPosX = 0;
  var selectedPosY = 0;
  
  var theElement = document.getElementById(name);
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
                        		      
 window.scrollTo(selectedPosX,selectedPosY);
}



function goToURL(url)
{
	window.location = url;
}

function setDepartments()
{

	var depts ="<h1>Participating Departments and Programs</h1>\n"+
          "<a href=\"http://www.duke.edu/web/art/\">Art, Art History & Visual Studies</a><br>\n"+
          "<a href=\"http://www.duke.edu/web/clas/\">Center for Late Ancient Studies</a><br>\n"+
          "<a href=\"http://www.duke.edu/web/classics/\">Classical Studies</a><br>\n"+
          "<a href=\"http://jhfc.duke.edu/cas/\">Comparative Area Studies</a><br>\n"+
          "<a href=\"http://ca-www.aas.duke.edu/\">Cultural Anthropology</a><br>\n"+
          "<a href=\"http://www.divinity.duke.edu/\">Divinity School</a><br>\n"+
	  "<a href=\"http://www.duke.edu/web/dukeperfs/\">Duke Performances</a><br>\n"+
          "<a href=\"http://www.duke.edu/web/english/\">English</a><br>\n"+
          "<a href=\"http://focus.aas.duke.edu/\">Focus Progam</a><br>\n"+
          "<a href=\"http://www.german.duke.edu/\">Germanic Languages & Literature</a><br>\n"+
          "<a href=\"http://www-history.aas.duke.edu/\">History</a><br>\n"+
          "<a href=\"http://jewishstudies.aas.duke.edu/\">Jewish Studies</a><br>\n"+
          "<a href=\"http://www.duke.edu/music/\">Music</a><br>\n"+
          "<a href=\"http://philosophy.duke.edu/\">Philosophy</a><br>\n"+
	   "<a href=\"http://literature.aas.duke.edu/\">Program in Literature</a><br>\n"+
          "<a href=\"http://www.duke.edu/religion/\">Religion</a><br>\n"+
          "<a href=\"http://www.romancestudies.aas.duke.edu/\">Romance Studies</a><br>\n"+
          "<a href=\"http://www.duke.edu/web/drama/\">Theater Studies</a><br>\n"+
          "<a href=\"http://www.duke.edu/womstud/\">Women's Studies</a><br><br>\n"+
	  "CMRS, Duke University<br> 351 Trent Hall Box 90656<br>\n" +
	  "Durham, NC 27708<br>Phone: 919-681-8883<br>Fax: 919-681-9298<br>\n"+
	  "email:<a href=\"mailto:cmrs@duke.edu\">cmrs@duke.edu</a>\n"; 



/*
var depts ="Center for Medieval and Renaissance Studies\n Duke University 201 West Duke Building\nBox 90743  Durham, North Carolina 27708-0743 Phone: 919-660-3050 Fax: 919-660-3060";
*/
	if(document.getElementById('Departments'))
	document.getElementById('Departments').innerHTML = depts;
}
