//javascript for acadia2007

//generates e-mail link
function mailto(who, where, linktext){
 if (!linktext) linktext = who + '@' + where;
 document.write('<a href="mailto:' + who + '@' + where + '">' + linktext + '</a>');
}

function init(){
 var iBase = TextResizeDetector.addEventListener( onFontResize,null );
}
function onFontResize(e, args){
 getheights();
 /*
 var msg = "\nThe base font size in pixels: " + args[0].iBase;
 msg +="\nThe current font size in pixels: " + args[0].iSize;
 msg += "\nThe change in pixels from the last size:" + args[0].iDelta;
 alert(msg);
 */
}

function getheights(which) {
 document.getElementById('side').style.height = '';
 var sideheight = Element.getHeight(side);
 
 if (sideheight <= 445) {document.getElementById('side').style.height = '445px'}
 else if ((sideheight > 445) && (sideheight <= 503)) {document.getElementById('side').style.height = '503px';}
 else if ((sideheight > 503) && (sideheight <= 618)) {document.getElementById('side').style.height = '618px';}
 else if ((sideheight > 618) && (sideheight <= 676)) {document.getElementById('side').style.height = '676px';}
 else if ((sideheight > 676) && (sideheight <= 791)) {document.getElementById('side').style.height = '791px';}
 else if (sideheight >= 791) {return;}

 var sideheightpx = document.getElementById('side').style.height;
 var sideheightnum = sideheightpx.replace("px","");
 if (which == 'side') {return}
 
 document.getElementById('body').style.height = '';
 var bodyheight = Element.getHeight(body);
 
 if (bodyheight <= 433) {document.getElementById('body').style.height = '433px'}
 else if ((bodyheight > 433) && (bodyheight <= 492)) {document.getElementById('body').style.height = '492px';}
 else if ((bodyheight > 492) && (bodyheight <= 606)) {document.getElementById('body').style.height = '606px';}
 else if ((bodyheight > 606) && (bodyheight <= 664)) {document.getElementById('body').style.height = '664px';}
 else if ((bodyheight > 664) && (bodyheight <= 779)) {document.getElementById('body').style.height = '779px';}
  else if (bodyheight >= 779) {
  document.getElementById('body').style.height = '';
  document.getElementById('bodybottomleft').style.display = 'none';
  document.getElementById('bodybottomright').style.display = 'none';
  if (rightcolumn) {
   document.getElementById('body').style.background = '#eee url(images/body-column-no-corner.gif) repeat-y top right';
  }
 }
 if (bodyheight < 779) {
  document.getElementById('bodybottomleft').style.display = 'block';
  document.getElementById('bodybottomright').style.display = 'block';
 }
}

//shows and hides
function showhideid(thisid) {
 document.getElementById(thisid).style.display = (document.getElementById(thisid).style.display == 'none' || document.getElementById(thisid).style.display == '') ? 'block' : 'none';
}


var menusUnlocked = true;

function sidemenu(list) {
 if (menusUnlocked) {
  menusUnlocked = false;
  setTimeout('menusUnlocked = true', 500);
  
  var menuitems = new Array();
  //menuitems[0] = 'ul-papers';
  //menuitems[1] = 'ul-lectures';
  menuitems[0] = 'ul-workshops';
  //menuitems[3] = 'ul-projects';
 
  //when a menu item is clicked:
  //for each menu item: if it is not the clicked one, and it is down, pull it up.
  for (i=0; i<menuitems.length; i++) {
   if (list != menuitems[i] && document.getElementById(menuitems[i]).style.display != 'none') {
    Effect.BlindUp(menuitems[i],{duration:0.4});
    document.getElementById(menuitems[i]+'-a').style.backgroundImage = 'url(images/bar-plus.gif)';
    document.getElementById(menuitems[i]+'-a').style.backgroundPosition = '-190px 0px';
   }
  }
 
  //if the clicked item is pulled up (display = none), pull it down.
  if (document.getElementById(list).style.display == 'none') {
   Effect.BlindDown(list,{duration:0.4});
   document.getElementById(list+'-a').style.backgroundImage = 'url(images/bar-minus.gif)';
   document.getElementById(list+'-a').style.backgroundPosition = '-10px 0px';
  //otherwise, pull it up
  } else {
   Effect.BlindUp(list,{duration:0.4});
   document.getElementById(list+'-a').style.backgroundImage = 'url(images/bar-plus.gif)';
   document.getElementById(list+'-a').style.backgroundPosition = '-190px 0px';
  }
  //after a slight delay, adjust heights
  setTimeout("getheights('side')",500);
 }
}





/**
 *  @fileoverview TextResizeDetector
 *
 *  Detects changes to font sizes when user changes browser settings
 *  <br>Fires a custom event with the following data:<br><br>
 * 	iBase  : base font size
 *	iDelta : difference in pixels from previous setting<br>
 *  	iSize  : size in pixel of text<br>
 *
 *  * @author Lawrence Carvalho carvalho@uk.yahoo-inc.com
 * @version 1.0
 */

/**
 * @constructor
 */
TextResizeDetector = function() {
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};

 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();

 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {

		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	/*
		 	 * Initializes the detector
		 	 *
		 	 * @param {String} sId The id of the element in which to create the control element
		 	 */
		 	init: function() {

		 		createControlElement();
				_startDetector();
 			},
			/**
			 * Adds listeners to the ontextsizechange event.
			 * Returns the base font size
			 *
			 */
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
			/**
			 * performs the detection and fires textSizeChanged event
			 * @return the current font size
			 * @type {integer}
			 */
 			detect:function() {
 				return _detect();
 			},
 			/**
 			 * Returns the height of the control element
 			 *
			 * @return the current height of control element
			 * @type {integer}
 			 */
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;


 			},
 			/**
 			 * Stops the detector
 			 */
 			stopDetector:function() {
				return _stopDetector();
			},
			/*
			 * Starts the detector
			 */
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();

TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = null;

/* id of element to check for and insert test SPAN into */
TextResizeDetector.TARGET_ELEMENT_ID = 'top';
/* function to call once TextResizeDetector was initialized */
TextResizeDetector.USER_INIT_FUNC = init;

function openGenericWindow(url, w, h, winName, showMenus, showStatusBar ) 
{
	if (navigator.appName.substring(0, 5) == 'WebTV')   return true;
	
	//Determine the left and top position of the window
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;

	//Build the parameter list of features to be displayed on the new window
	var params = "toolbar=no,location=no,directories=no,status=" + showStatusBar + ",menubar=" + showMenus + ",scrollbars=yes,resizable=no,copyhistory=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",screenX=" + l + ",screenY=" + t + "";
		
	//Open a new window and set focus to it
	genericWindow = window.open(url, winName, params);
	genericWindow.focus();

	return false;
}
