function startUp() {
	findExLinks();
	setUpNav(document.getElementById("nav"));
}

// set up external links to open in new window
// relies on rel="external" to be in <a> tag
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;
		}
	}
}

// open up new window
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;
}

// attach navigational event handlers
function setUpNav(ulObj) {
	var thisElement = null;
	var pos = null;
	var sel = false;

	for (var i = 0; i < ulObj.childNodes.length; i++) {
		if (ulObj.childNodes[i].nodeName == "LI") {
			if (ulObj.childNodes[i].className == "sel") {
				sel = true;
			}
			for (var j = 0; j < ulObj.childNodes[i].childNodes.length; j++) {
				if (ulObj.childNodes[i].childNodes[j].nodeName == "A") {
					for (var k = 0; k < ulObj.childNodes[i].childNodes[j].childNodes.length; k++) {
						thisElement = ulObj.childNodes[i].childNodes[j].childNodes[k];
						if (thisElement.nodeName == "IMG" && !sel) {
							thisElement.onmouseover = navFlip;
							thisElement.onmouseout = navFlip;
						}
					}
				}
			}
			sel = false;
		}
	}
}

// navigational event handler
function navFlip() {
	if(this.src.indexOf("-sel") > -1) {
		this.src = this.src.substring(0, this.src.indexOf("-sel")) + ".gif";
	}
	else {
		this.src = this.src.substring(0, this.src.indexOf(".gif")) + "-sel.gif";
	}

}

// array for home spotlight data
// order of items is header, spotlight copy, path to flash file from spotlights directory
var spotlights = new Array();
var randomNum = null;

spotlights[0] = new Array("Fusion Research at MIT", 'MIT graduate students, faculty, and staff prepare for the next generation of fusion reactors. <a href="http://techtv.mit.edu/videos/306-fusion-research-at-mit" rel="external">Watch the full video</a>.', "PlasmaCutdown");
spotlights[1] = new Array("Extraordinary Learning @ MIT", 'Students and professors talk about innovation and creativity in teaching and learning at MIT. <a href="http://techtv.mit.edu/videos/342-extraordinary-learning-mit" rel="external">Watch the full video</a>.', "DUE_Cutdown");
spotlights[2] = new Array("Presidential Campaigns Debate Energy", 'Representatives from the McCain and Obama campaigns faced off Monday, Oct. 6, 2008 for a debate on energy, moderated by NPR\'s Tom Ashbrook, host of  "On Point." <a href="http://techtv.mit.edu/videos/24-presidential-campaigns-debate-span-classhighlightenergyspan" rel="external">Watch the full video</a>.', "ENERGY_DEBATE_FINAL");
spotlights[3] = new Array("MIT 100K Competition 20th Anniversary", 'The MIT 100K Entrepreneurship Competition celebrates its 20th Anniversary.  Promo created for the 2009 Business Plan Competition Semi-Finals. <a href="http://techtv.mit.edu/videos/2048-mit-100k-2009-bpc-semi-finals" rel="external">Watch the event</a>.', "100k");


function setRandomFlash() {
	randomNum = Math.floor(Math.random() * spotlights.length);

	var s1 = new SWFObject("scripts/player.swf","single","480","300","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("streamer","rtmp://amps-videoserver1.mit.edu/streams/amps/site/");
	s1.addVariable("overstretch","true");
	s1.addVariable("autostart","true");
	s1.addVariable("id",spotlights[randomNum][3]);
	s1.addVariable("width","480");
	s1.addVariable("height","300");
	s1.write("player1");
}

function setFlashHeaders() {
	if (randomNum != null) {
		document.getElementById("spothead").firstChild.nodeValue = spotlights[randomNum][0];
		document.getElementById("spottext").innerHTML = spotlights[randomNum][1];
	}
}


function popitup(url) {
	newwindow=window.open(url,'name','height=500,width=660');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitupvid(url) {
	newwindow=window.open(url,'name','height=600,width=450');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popituprich(url) {
	newwindow=window.open(url,'name','height=600,width=600');
	if (window.focus) {newwindow.focus()}
	return false;
}


function popitupformats(url) {
	newwindow=window.open(url,'name','height=170,width=400');
	if (window.focus) {newwindow.focus()}
	return false;
}



