// JavaScript Document for IE subnav 

function startList() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("topnav");
		for (i = 0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
						this.className += " over";
				}
				node.onmouseout = function() {
						this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

function findExLinks() {
	var linkObjs = document.getElementsByTagName('a');
	for (var i = 0; i < linkObjs.length; i++) {
		link = linkObjs[i].getAttribute('rel');
		if (link == "external") {
			linkObjs[i].onclick = newWin;
		}
	}
}

function newWin () {
	// window features
	var status = "1";
	var toolbar = "1";
	var location = "1";
	var menubar = "1";
	var directories = "0";
	var resizable = "1";
	var scrollbars = "1";	
	var features = "status=" + status + ",toolbar=" + toolbar + ",location=" + location + ",menubar=" + menubar + ",directories=" + directories + ",resizable=" + resizable + ",scrollbars=" + scrollbars;
	var newWin = window.open(this, "newWin", features);

	newWin.focus();	
	return false;
}

function creditLink () {
	var creditObj = document.getElementById("credits");
	creditObj.onclick = function() {
		// window features
		var status = "0";
		var toolbar = "0";
		var location = "0";
		var width = "620";
		var height = "320";
		var menubar = "0";
		var directories = "0";
		var resizable = "1";
		var scrollbars = "1";	
		var features = "status=" + status + ",toolbar=" + toolbar + ",location=" + location + ",width=" + width + ",height=" + height + ",menubar=" + menubar + ",directories=" + directories + ",resizable=" + resizable + ",scrollbars=" + scrollbars;
		var newWin = window.open(this, "newWin", features);
	
		newWin.focus();	
		return false;
	}
}

function startUp () {
	startList();
	selPage();
	findExLinks();
	creditLink();
	flipHome();
}

var spotlights = Array();

spotlights[0] = Array("ChemE's newest faculty member is one of Popular Science's \"Brilliant Ten\"","http://web.mit.edu/newsoffice/2007/bazant-tt1024.html");
spotlights[1] = Array("Professor Bob Cohen and post-doc Anish Tuteja can show you how to design oil-repellent materials.", "http://web.mit.edu/cheme/news/archives/2008/BCohen-news.html");
spotlights[2] = Array("Using carbon nanotubes, MIT chemical engineers have built the most sensitive electronic detector yet for sensing deadly gases such as the nerve agent sarin.","http://web.mit.edu/newsoffice/2008/nanotube-0605.html");
spotlights[3] = Array("A new thin-film coating developed by MIT chemical engineers can deliver controlled drug doses to specific targets in the body following implantation, essentially serving as a \"micro pharmacy.\"","http://web.mit.edu/newsoffice/2008/drug-delivery-0211.html");
spotlights[4] = Array("MIT engineers have outfitted cells with tiny \"backpacks\" that could allow them to deliver chemotherapy agents, diagnose tumors or become building blocks for tissue engineering.","http://web.mit.edu/newsoffice/2008/cellbackpack-1106.html");
spotlights[5] = Array("Professor Paul Barton and grad student Ajay Selot have developed a mathematical model that could help energy companies produce natural gas more efficiently and ensure a more reliable supply of this valuable fuel.","http://web.mit.edu/mitei/research/spotlights/mit-math.html");

function flipHome () {
	var isHome = true;
	if (document.getElementsByTagName("body")[0].className != "home") {
		isHome = false;
	}

	if (isHome) {
		var total = spotlights.length;
		// get random class for background images
		var randomNum = Math.floor(Math.random() * total) + 1;
		var containerObj = document.getElementById("container");
		containerObj.className = "spot" + randomNum.toString();
		containerObj = document.getElementById("spotlightp");
		// set content of spotlight paragraph
		containerObj.firstChild.nodeValue = spotlights[randomNum - 1][0];
		// set link for "Learn more" button
		containerObj = document.getElementById("more");
		containerObj.href = spotlights[randomNum - 1][1];
	}
}

function selPage () {
	var navArray = document.getElementById("topnav").getElementsByTagName("li");
	var src = "";
	for (var i = 0; i < navArray.length; i++) {
		src = navArray[i].firstChild.toString();
		if (src.indexOf(thisPage) > -1 && (!navArray[i].className || navArray[i].className == "last")) {
			navArray[i].className += " sel";
			break;
		}
	}
}

