/************************************************************************
 * Capturing The Mouse Position in IE4-6 & NS4-6                        *
 * (C) 2000 www.CodeLifter.com                                          *
 * Free for all users, but leave in this  header                        *
 ************************************************************************/

var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) {
	document.captureEvents(Event.MOUSEMOVE);
}
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	// catch possible negative values in NS4
	if (tempX < 0) {
		tempX = 0;
	}
	if (tempY < 0) {
		tempY = 0;
	}  
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	if (document.Show) {
		document.Show.MouseX.value = tempX;
		document.Show.MouseY.value = tempY;
	}
	return true
}

/************************************************************************
 * Title:       E-mail hider                                            *
 * Creator:     Michael Bennett                                         *
 * Description: This function scans the page when it is opened and      *
 *              converts properly formatted strings to clickable email  *
 *              links.  Because this happens in JavaScript, most bots   *
 *              can only read the original, meaningless script.         *
 * Pre:         The document contains emails designated by id="email".  *
 *              It applies the span's class to the email and uses the   *
 *              title (if present) as the visible text.  Text within    *
 *              the span must be in the format username 'AT domain DOT  *
 *              topdomain.'                                             *
 * Post:        All spans marked with the id "email" are converted to   *
 *              clickable links.                                        *
 ************************************************************************/

function betterHider() {
	while ( document.getElementById('email') ) {
		var emailToHide = document.getElementById('email');		//Access the span we're going to be changing
		var finalOutput = "";						//Initialize the new output
		var info = emailToHide.innerHTML;				//Access the interior of the span we're changing
		var newInfo = new Array("", "", "", "");			//Set up the array with blanks for the new info
		var userInfo = info.substring(0, (info.indexOf('AT')-1));	//Get the user information out of 'info'; it ends just before AT
		while (userInfo.indexOf('DOT') != -1) {				//As long as there's a 'DOT' in the userInfo, keep replacing it with '.'
			userInfo = userInfo.substring(0,userInfo.indexOf('DOT')-1)+"."+userInfo.substring(userInfo.indexOf('DOT')+4);
		}
		var domain = info.substring(info.indexOf("AT")+3);		//Get the domain information out of 'info'; we'll have to do some operations on it, because of the DOTs in it
		while (domain.indexOf('DOT') != -1) {				//As long as there's a 'DOT' in the domain, keep replacing it with '.'
			domain = domain.substring(0,domain.indexOf('DOT')-1)+"."+domain.substring(domain.indexOf('DOT')+4);
		}
		newInfo[0] = userInfo;
		newInfo[1] = domain;
		newInfo[2] = emailToHide.className;				//Get the class information (same class that 'span' has)
		newInfo[3] = emailToHide.title;					//Get the 'to show' information ('span's title)
		emailToHide.title = "";						//This prevents us from the redundant case of having the title repeat the displayed text
		var recreateEmail = newInfo[0]+'@'+newInfo[1];			//This is the new link, and may also be the displayed text, if there was no SHOW specified
		if ( newInfo[3] == "" ) {					//If there was no SHOW specified, copy the link into the SHOW section of the array
			newInfo[3] = recreateEmail;
		}
		if ( newInfo[2] == "" ) {					//Check to see if a class was specified; if no class specified, leave it blank
			finalOutput = '<a href="mailto:'+recreateEmail+'">'+newInfo[3]+'</a>';
		}
		else {								//If a class was specified, put it in
			finalOutput = '<a class="'+newInfo[2]+'" href="mailto:'+recreateEmail+'">'+newInfo[3]+'</a>';
		}
		emailToHide.innerHTML = finalOutput;				//Change the displayed HTML so it has the clickable link
		emailToHide.id = "emailShown";					//Change the ID so the code won't endlessly 'fix' this one email
	}
}

/************************************************************************
 *Last-updated script                                                   *
 *Creator: someone at USC's English department?                         *
 ************************************************************************/
function showLastUpdated() {
	var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var dateObj = new Date(document.lastModified)
	var lmonth = months[dateObj.getMonth()]
	var date = dateObj.getDate()
	var fyear = dateObj.getYear()
	if (fyear < 2000) {
		fyear = fyear + 1900
	}
	document.write('<div><div class="left">Site updated ');
	document.write(lmonth + ' ' + date + ', ' + fyear + ' by ');
	document.write(' <span id="email" title="ISS webmaster">bennetmc AT engr DOT sc DOT edu</span></div><div class="right"><a href="http://www.sc.edu/usc/copyright.html">&copy; 2008</a> University of South Carolina Board of Trustees</div></div>');
}

/************************************************************************
 * Div displayer                                                        *
 * Creator: Michael Bennett                                             *
 ************************************************************************/
function switchDiv(whichDiv, multiChange) {
	if (multiChange) {
		if (document.getElementById(whichDiv).style.display=='block') {
			document.getElementById(whichDiv).style.display='none';
		}
		else {
			document.getElementById(whichDiv).style.display='block';
			/*document.getElementById(whichDiv).style.left=leftEdge;
			document.getElementById(whichDiv).style.top=topEdge;
			/*document.getElementById(whichDiv).style.left=tempX-10;
			document.getElementById(whichDiv).style.top=tempY-10;*/
		}
	}
	else {
		document.getElementById(whichDiv).style.display='block';
	}
}

/************************************************************************
 *Random functions                                                      *
 ************************************************************************/
function postComment2() {
	document.getElementById('postCommentLink').href="javascript:postComment();";
}
function postComment() {
	switchDiv('postCommentDiv', false);document.getElementById('linkSpan').innerHTML="";
}

/************************************************************************
 * Preloader                                                            *
 * Creator: 'Guest' at TechRepublic                                     *
 ************************************************************************/
images = new Array();
 
function preloader() {
	var i=0;
	imageObj = new Image();
	for (i=0; i<images.length; i++) {
		imageObj.src=images[i];  
	}
}

/************************************************************************
 * Image switcher                                                       *
 * Creator: Michael Bennett                                             *
 ************************************************************************/
captions = new Array();
tooltips = new Array();

function switcher() {
	var i=1;
	while (document.getElementById('picswitch'+i)) {
		document.getElementById('picswitch'+i).src = images[randomNum];
		document.getElementById('picswitch'+i).alt = tooltips[randomNum];
		if (document.getElementById('caption'+i)) {
			document.getElementById('caption'+i).innerHTML = captions[randomNum];
		}
		i++;
	}
}
function refresher() {
	document.getElementById('picswitch1').src = image;
	setTimeout("refresher()", t*1000);
}

/************************************************************************
 *Text truncator							*
 *Creator: Patrick Fitzgerald (www.barelyfitz.com)			*
 *Editor: Michael Bennett (added ability to return to small view)	*
 ************************************************************************/
function truncate()
{
	var lenShort = 225;
	var lenLong = 400;
	for ( j = 1 ; j < 50 ; ++j )
	{
		var lessstuff = document.getElementById('truncateMeShort'+j);
		if (lessstuff)
		{
			var trunc = lessstuff.innerHTML;
			if ( trunc.length > ( lenShort + 75 ) )
			{
				/* Add a link to the end of the original content; this link will 
				 only appear if the content is expanded */
				lessstuff.innerHTML += ' <a href="#" onclick="retruncateShort('+j+', '+lenShort+')">'+
					// '<span style="font-size: 10px;">[less...]</span><\/a>';
					'[less]<\/a>';
				
				/* Truncate the content of the P, then go back to the end of the
				 previous word to ensure that we don't truncate in the middle of
				 a word */
				trunc = trunc.substring(0, lenShort);
				trunc = trunc.replace(/\w+$/, '');

				/* Add an ellipsis to the end and make it a link that expands
				 the paragraph back to its original size */
				trunc += '... <a href="#" onclick="this.parentNode.innerHTML=unescape(\''+
					escape(lessstuff.innerHTML)+
					// '\');return false;"><span style="font-size: 10px;">[more...]</span><\/a>';
					'\');return false;">[more]<\/a>';
				lessstuff.innerHTML = trunc;
			}
		}
		var morestuff = document.getElementById('truncateMeLong'+j);
		if (morestuff)
		{
			var trunc = morestuff.innerHTML;
			if ( trunc.length > ( lenLong + 150 ) )
			{
				/* Add a link to the end of the original content; this link will 
				 only appear if the content is expanded */
				morestuff.innerHTML += ' <a href="#" onclick="retruncateLong('+j+', '+lenLong+')">'+
					// '<span style="font-size: 10px;">[less...]</span><\/a>';
					'[less]<\/a>';
				
				/* Truncate the content of the P, then go back to the end of the
				 previous word to ensure that we don't truncate in the middle of
				 a word */
				trunc = trunc.substring(0, lenLong);
				trunc = trunc.replace(/\w+$/, '');

				/* Add an ellipsis to the end and make it a link that expands
				 the paragraph back to its original size */
				trunc += '... <a href="#" onclick="this.parentNode.innerHTML=unescape(\''+
					escape(morestuff.innerHTML)+
					// '\');return false;"><span style="font-size: 10px;">[more...]</span><\/a>';
					'\');return false;">[more]<\/a>';
				morestuff.innerHTML = trunc;
			}
		}
	}
}

function retruncateShort(ident, len)
{
	var stuff = document.getElementById('truncateMeShort'+ident);
	var trunc = stuff.innerHTML;
	trunc = trunc.substring(0, len);
	trunc = trunc.replace(/\w+$/, '');
	trunc += '... <a href="#" onclick="this.parentNode.innerHTML=unescape(\''+
		escape(stuff.innerHTML)+
		'\');return false;">[more]<\/a>';
	stuff.innerHTML = trunc;
}

function retruncateLong(ident, len)
{
	var stuff = document.getElementById('truncateMeLong'+ident);
	var trunc = stuff.innerHTML;
	trunc = trunc.substring(0, len);
	trunc = trunc.replace(/\w+$/, '');
	trunc += '... <a href="#" onclick="this.parentNode.innerHTML=unescape(\''+
		escape(stuff.innerHTML)+
		'\');return false;">[more]<\/a>';
	stuff.innerHTML = trunc;
}
 
/************************************************************************
 * Multiple onload                                                      *
 * Creator: Simon Willison                                              *
 ************************************************************************/
function addLoadEvent( func ) {
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}