// globally useful scripts
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function showBigBox() {
	this.style.zIndex = 2000;
	var divs = this.getElementsByTagName('div');
	for(var i=0; i < divs.length; i++) {
		if(divs[i].className == 'smallBox') {
			divs[i].className = 'bigBox';
		}
	}
}

function hideBigBox() {
	this.style.zIndex = 1;
	var divs = this.getElementsByTagName('div');
	for(var i=0; i < divs.length; i++) {
		if(divs[i].className == 'bigBox') {
			divs[i].className = 'smallBox';
		}
	}
}

function linkBox() {
	var anchors = this.getElementsByTagName('a');
	for(var i=0; i < anchors.length; i++) {
		if(anchors[i].className == 'siteLink') {
			window.location=anchors[i].href;
		}
	}
}

function attachSplashBox() {
	if(!document.getElementById) return false;
	if(!document.getElementById('AboutUndergrad')) return false;
	if(!document.getElementById('AboutJconnect')) return false;
	if(!document.getElementById('AboutCommunity')) return false;
	
	/*document.getElementById('AboutUndergrad').onmouseover = showBigBox;
	document.getElementById('AboutUndergrad').onmouseout = hideBigBox;
	document.getElementById('AboutJconnect').onmouseover = showBigBox;
	document.getElementById('AboutJconnect').onmouseout = hideBigBox;
	document.getElementById('AboutCommunity').onmouseover = showBigBox;
	document.getElementById('AboutCommunity').onmouseout = hideBigBox;*/
	document.getElementById('AboutUndergrad').onclick = linkBox;
	document.getElementById('AboutJconnect').onclick = linkBox;
	document.getElementById('AboutCommunity').onclick = linkBox;
}

addLoadEvent(attachSplashBox);