whereAreWe = function() {
	var where = window.location.pathname;
	var endPath = where.lastIndexOf("/");
	var whereDir = where.substring(1, endPath);
	whereDirs = whereDir.split("/", 2);
	return whereDirs;
}

navControl = function() {
	var ourDir = whereAreWe();
	var navitems = document.getElementById('nav').getElementsByTagName('LI');
	for (var h=0; h<navitems.length; h++) {
		if(navitems[h].id == ourDir[0]) {
			navitems[h].firstChild.className = "on";
			var subnav = document.getElementById(navitems[h].id + 'sub');
			if(subnav != undefined) {
				subnav.style.display = 'inline';
			}
			if(ourDir[1] != undefined && ourDir[1] != "admin") {
				var secondlevel = subnav.firstChild;
				var levelpoints = secondlevel.childNodes;
				for (var j=0; j < levelpoints.length; j++) {
					if(levelpoints[j].id == ourDir[1]) {
						levelpoints[j].firstChild.className = "on";
						navitems[h].firstChild.className = "twoon";
					}
				}
			}
					
		}
	}
}

newsHighlighter = function() {
	var newsbox = document.getElementById('newsitems');
	if(newsbox != undefined) {
		var newslist = newsbox.getElementsByTagName('LI')
		var photodis = document.getElementById('newsframe');
		var actualphoto = document.getElementById('homephoto');
		for (var i=0; i<newslist.length; i++) {
			newslist[i].onmouseover = function() {
				photodis.className = 'photoon';
				actualphoto.src="images/homephotos/"+this.id+".jpg";
			}
			newslist[i].onmouseout = function() {
				photodis.className = '';
			}
		}
	}
}

imgOn = function(imgId) {
	var theimage = document.getElementById(imgId);
	var imgType = /(\.gif|\.jpg|\.png)/;
	theimage.src=theimage.src.replace(imgType, "_on$1");
}

imgOff = function(imgId) {
	var theimage = document.getElementById(imgId);
	var imgType = /(_on)(\.gif|\.jpg|\.png)/;
	theimage.src=theimage.src.replace(imgType, "$2");
}

deleteCheck = function(pubid) {
	var x = window.confirm('Are you sure you want to delete this publication?');
	if(x) {
		window.location = "https://www.engr.utexas.edu/fsel/publications/admin/removepub.cfm?pubID="+pubid;
	} else {
		return false;
	}
}

addInput = function(inputcontain) {
	var holder = document.getElementById(inputcontain);
	var mommy = holder.parentNode;
	var field = holder.cloneNode(true);
	field.value = "";
	var lb = document.createElement('br');
	mommy.insertBefore(field, holder);
	mommy.insertBefore(lb, field.nextSibling);
}
	
window.onload = function() {
	navControl();
	newsHighlighter();
}
	