if(window.addEventListener){
	window.addEventListener('load', clickableBoxes, false);
	window.addEventListener('load', extLinks, false);
	window.addEventListener('load', getHeaders, false);
	window.addEventListener('load', checkURL, false);
	window.addEventListener('load', addHelpIcon, false);
	window.addEventListener('load', imgGenerate, false);
}else{
	window.attachEvent('onload', function(){
		clickableBoxes();
		extLinks();
		getHeaders();
		checkURL();
		addHelpIcon();
		imgGenerate();
	});
}

//			::: START BREAK OUT OF FRAMES :::

if (window != top) top.location.href = location.href;

//			::: END BREAK OUT OF FRAMES :::

//			::: START MAIN MENU IMAGE GENERATOR :::

function imgGenerate() {
	/*if (document.getElementById) {
		rnd = String(Math.floor(Math.random() * 3) + 1);
		document.getElementById('header').style.backgroundImage = 'url(/man/images/header/' + rnd + '.jpg)';
	}*/
	
	var theDate   = new Date();
	var h = theDate.getUTCHours();
	
	if(h > 13 && h < 21){
		imgNum = 3;
	} else if(h > 2 && h < 14){
		imgNum = 2;
	} else {
		imgNum = 1;
	}
	
	document.getElementById('header').style.backgroundImage = 'url(/man/images/header/' + imgNum + '.jpg)';
}

//			::: END MAIN MENU IMAGE GENERATOR :::

//			:::		START MAKE BOXES CLICKABLE				:::

function clickableBoxes(){	
	//  Get the directory name	
	var url = document.location.href;
	if(url.length > 24){
		var directory = '';
		var i = 24;
		
		while(url.charAt(i) != '/'){
			directory += url.charAt(i);
			i++;
		}
	}
	
	//	Arrays for comparing directory and div IDs
	aDir = new Array();
	aDir[0] = "people";
	aDir[1] = "my";
	aDir[2] = "directory";
	
	aDivName = new Array();
	aDivName[0] = "biosummary";
	aDivName[1] = "icondesc";
	aDivName[2] = "file";

	for(x=0;x<aDir.length;x++){
		if(directory == aDir[x]){
			addEvents(aDivName[x])
		}
	}
}

function addEvents(theClass){
	var d = document.getElementsByTagName('div');
		
	for(i=0;i<d.length;i++){
		if(d[i].className == theClass){
			d[i].onmouseover = function() {
				this.className = theClass + ' hover';
			}
			d[i].onmouseout = function() {
				this.className = theClass;
			}
			
			d[i].onclick = function() {
				var a = this.getElementsByTagName('a')[0];
				
				document.location.href = a.href;
			}
		}
	}
}

//			:::		END MAKE BOXES CLICKABLE				:::

//			:::		START ALTER EXTERNAL LINKS	:::

function extLinks(){
	// get all links
	var a = document.getElementsByTagName('a');
	var x = 0;
	
	// get all external links
	for(i=0;i<a.length;i++){
		var h = a[i].href.substring(0,23);
		var p = a[i].href.substring(0,5);
		var m = a[i].href.substring(0,7);
		if(h != 'http://www.uleth.ca/man' && p != 'https' && m != 'mailto:'){
			// add unique class	
			a[i].className = 'extlink';
		}
	}
}

//			:::		END ALTER EXTERNAL LINKS	:::

//			:::		START TABLE OF CONTENT		:::

function getHeaders(){
/*	if(document.getElementById('content')){
		var d = document.getElementById('content');
		var h = d.getElementsByTagName('h2');
		var h1 = d.getElementsByTagName('h1');
		var url = document.location.href;
		var aURL = new Array();
		aURL = url.split('/');
		
		// Checks if more than four h2 elements exist
		if(h.length > 4 &&
			(aURL[3] != 'man-execprog' &&
				aURL[4] != 'my' &&
				aURL[4] != 'gallery' &&
				aURL[4] != 'people' &&
				aURL[4] != 'help' &&
				aURL[4] != 'courses' &&
				aURL[4] != 'rss' &&
				aURL[4] != 'students' &&
				aURL[5] != 'majors') &&
			h1.length == 1){
			// Create new unordered list
			var u = document.createElement('ul');
			
			for(i=0;i<h.length;i++){
				// assign new ID to h2 tag
				h[i].id = 'h2' + i;
				
				// get heading text
				var t = h[i].firstChild.nodeValue;
				// create new list item
				var li = document.createElement('li');
				// create new anchor tag and link text
				var a = document.createElement('a');
				var tt = document.createTextNode(t);
				
				// put the list of links together
				a.appendChild(tt);
				a.href = '#h2' +i;
				li.appendChild(a);
				u.appendChild(li);
				u.className = 'cleared';
				
				// create 'back to top' link for all but the first h2 element
				var img = document.createElement('img');					
					img.src = '/man/images/backtotop.gif';
					img.alt = 'Back to top';
					img.className = 'icon';
					
				var aTop = document.createElement('a');
					aTop.href = '#';
					aTop.appendChild(img);
					
				var p = document.createElement('p');
					p.appendChild(aTop);				
				
				// if first img, move to end of page; otherwise, put it above h2 element
				if(i==0){
					d.appendChild(p);
				} else {
					d.insertBefore(p,h[i]);
				}
			}
			
			// put list of links before first h2 element			
			d.insertBefore(u,h[0]);
		}
	}*/
}

//			:::		END TABLE OF CONTENT		:::

//			:::		START ALTERNATE STYLESHEET		:::

function altStyle(){

}

//			:::		END ALTERNATE STYLESHEET		:::

//			:::		START CHECK OF URL AND MENU TO BOLD MENU ITEM	:::

function checkURL(){
	var menu = document.getElementById('menu');
	var listItems = menu.getElementsByTagName('li');
	var url = document.location.href;
	var i = 24;
	
	if(url.length > i){	
		/*  Get the directory name  */
		var directory = '';
		while(url.charAt(i) != '/'){
			directory += url.charAt(i);
			i++;
		}
		
		if(directory == 'programs' || directory == 'courses'){
			directory = 'students';
		}
		
		if(directory == 'our_people' || directory == 'people'){
			directory = 'faculty';
		}
		
		/*  Loop through menu list until the matching ID is found; add new class  */
		for (i=0;i<listItems.length;i++){
			if(listItems[i].id == directory){
				listItems[i].className = 'currentpage';
			}
		}
	}
}

//			:::		END CHECK OF URL AND MENU TO BOLD MENU ITEM	:::

//			:::		START ADD HELP ICON :::

function addHelpIcon(){
	var h = document.getElementById('header');
	var fom = document.getElementById('fom');
	
	if(h.getElementsByTagName('h1')[0]){
		var fom = h.getElementsByTagName('h1')[0];
	}
	
	var a = document.createElement('a');
		a.href = '/man/help/';
		a.title = 'Help';
	
	var img = document.createElement('img');
		img.src = '/man/images/help.gif';
		img.alt = 'Help';
		img.id = 'helpicon';
		img.className = 'icon';
		
	a.appendChild(img);
	h.insertBefore(a,fom);
}

//			:::		END ADD HELP ICON :::