function popup(video,section) {
	popup = window.open('','popup','width=320,height=230,scrollbars');
	popup.document.write('<html>');
	popup.document.write('<head>');
	popup.document.write('<title>The Faculty</title>');
	popup.document.write('<link rel="stylesheet" type="text/css" href="inc/style.css">');
	popup.document.write('</head>');
	popup.document.write('<body id="'+section+'">');
	popup.document.write('<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="320" height="200" codebase="http://www.apple.com/qtactivex/qtplugin.cab">');
	popup.document.write('<param name="src" value="video/'+video+'">');
	popup.document.write('<param name="autoplay" value="true">');
	popup.document.write('<param name="controller" value="true">');
	popup.document.write('<embed src="video/'+video+'" width="300" height="200" autoplay="true" controller="true" pluginspage="http://www.apple.com/quicktime/download/">');
	popup.document.write('</embed>');
	popup.document.write('</object>');
	popup.document.write('<a href="#" class="btn" style="float:right;" onclick="window.opener.focus(); window.close();">close window</a></body></html>');
	popup.focus();
	return false;
}

function startList() {
	if (document.all&&document.getElementById) {
		if (document.getElementById("menu")) {
			navRoot = document.getElementById("menu");
			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 hideAll(menu) {
	if (document.getElementById('mn_hider1')) document.getElementById('mn_hider1').style.display='none';
	if (document.getElementById('mn_hider2')) document.getElementById('mn_hider2').style.display='none';
	for(i=0;i<document.getElementById('menu').getElementsByTagName('div').length;i++) {
		if (document.getElementById('menu').getElementsByTagName('div')[i].className=='dropdown')
			document.getElementById('menu').getElementsByTagName('div')[i].style.display='none';
	}
	for(i=0;i<document.getElementById('menu').getElementsByTagName('table').length;i++) {
		if (document.getElementById('menu').getElementsByTagName('table')[i].className=='dropdown')
			document.getElementById('menu').getElementsByTagName('table')[i].style.display='none';
	}
	var menubar = document.getElementById('nav-top').getElementsByTagName('img');
	// loop through each image in the menu bar. replace with it's rollover image onmouseover and vice versa.
	for(i=0;i<menubar.length;i++) {
		if (menubar[i].src.indexOf('_b.') != -1) {
			// use next line if menu section highlighting *not* required:
			menubar[i].src = menubar[i].src.replace('_b.','_a.');
			// use next line if menu section highlighting required:
			// menubar[i].src = (menubar[i].name.replace('img_','')!=pageId)? menubar[i].src.replace('_b.','_a.'): menubar[i].src.replace('_a.','_b.');
		}
	}
	window.status='';
}

function show(menu) {
	hideAll(menu);
	if (document.getElementById('mn_hider1')) document.getElementById('mn_hider1').style.display='block';
	if (document.getElementById('mn_hider2')) document.getElementById('mn_hider2').style.display='block';
	if (document.getElementById(menu)) document.getElementById(menu).style.display='block';
	var menubar = document.getElementById('nav-top').getElementsByTagName('img');
	for(i=0;i<menubar.length;i++) {
		if(menubar[i].src.indexOf(menu)==-1) {
			if (menubar[i].src.indexOf('_b.') != -1) {
				// use next line if menu section highlighting *not* required:
				menubar[i].src = menubar[i].src.replace('_b.','_a.');
				// use next line if menu section highlighting required:
				// menubar[i].src = (menubar[i].name.replace('img_','')!=pageId)? menubar[i].src.replace('_b.','_a.'): menubar[i].src.replace('_a.','_b.');
			}
		}
	}
}		

function attachFocus() {
	if (this.className.indexOf(" focus")<0) {
		this.className+=" focus";
	}
}

function attachBlur() {
	if (this.className.indexOf(" focus")>0) {
		this.className = this.className.substring(0,this.className.indexOf(" focus"));
	} else {
		this.className.replace(" focus","");
	}

	if (this.tempOnBlur) {
		// call existing onBlur event.
		this.tempOnBlur();
	}
}

function msgStatus() {
	if (this.tagName=="INPUT") {
		switch(this.type) {
			case 'image': // form button is an <input type="image"> (graphic);
				if (this.getAttribute('src').indexOf('_a.')!=-1) {
					this.src = this.getAttribute('src').replace('_a.','_b.');
					txtStatus=this.getAttribute('alt');
				}
				break;
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
				this.className="bnover";
				txtStatus=this.getAttribute('value');
				break;
			default:
				break;
		}
	} else {
		if (this.name) {
			for (i=0;i<document.getElementsByName(this.name).length;i++) {
				if (document.getElementsByName(this.name)[i]!=this) {
					if (document.getElementsByName(this.name)[i].tagName=='A') {
						if (document.getElementsByName(this.name)[i].getElementsByTagName('img').length!=0) {
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('_a.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('_a.','_b.');
							}
						} else {
							document.getElementsByName(this.name)[i].className="rollover";
						}
					}
				}
			}
		}
		if (this.innerText) {
			txtStatus=this.innerText;
		} else {
			if (this.text) txtStatus=this.text;
		}
		if (this.getElementsByTagName('img').length!=0) {
			txtStatus=this.getElementsByTagName('img')[0].getAttribute('alt');
			if (this.getElementsByTagName('img')[0].src.indexOf('_a.')!=-1) {
				this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('_a.','_b.');
			}
		} else {
			if (this.tagName=="AREA") {
				txtStatus=this.getAttribute('alt');
			}
		}
	}
	// txtStatus=toTitleCase(txtStatus);
	window.status=toTitleCase(txtStatus); return true;
}

function msgStatusOff() {
	txtStatus=window.defaultStatus;
	if (this.tagName=="INPUT") {
		switch(this.type) {
			case 'image': // form button is an <input type="image"> (graphic);
				if (this.getAttribute('src').indexOf('_b.')!=-1) {
					this.src = this.getAttribute('src').replace('_b.','_a.');
				}
				break;
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
				this.className="bnout";
				break;
			default:
				break;
		}
	} else {
		if (this.name) {
			for (i=0;i<document.getElementsByName(this.name).length;i++) {
				if (document.getElementsByName(this.name)[i]!=this) {
					if (document.getElementsByName(this.name)[i].tagName=='A') {
						if (document.getElementsByName(this.name)[i].getElementsByTagName('img').length!=0) {
							if (document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.indexOf('_b.')!=-1) {
								document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src = document.getElementsByName(this.name)[i].getElementsByTagName('img')[0].src.replace('_b.','_a.');
							}
						} else {
							document.getElementsByName(this.name)[i].className="";
						}
					}
				}
			}
		}
	}
	if (this.getElementsByTagName('img').length!=0 && this.getElementsByTagName('img')[0].src.indexOf('_b.')!=-1 && this.getElementsByTagName('img')[0].name.indexOf('img_')==-1) {
		this.getElementsByTagName('img')[0].src = this.getElementsByTagName('img')[0].src.replace('_b.','_a.');
	}
	window.status=txtStatus; return true;
}

function msgStatusAllLinks() {
	for(i=0; i<document.links.length; i++) {
		if (!document.links[i].onmouseover) {
			document.links[i].onmouseover=msgStatus;
			document.links[i].onmouseout=msgStatusOff;
		}
	}
	for(i=0; i<document.getElementsByTagName('input').length; i++) {
		switch(document.getElementsByTagName('input')[i].type) {
			case 'image': // form button is an <input type="image"> (graphic);
			case 'button': // form button is an <input type="button"> (webtext);
			case 'submit': // form button is an <input type="submit"> (webtext);
				document.getElementsByTagName('input')[i].onmouseover=msgStatus;
				document.getElementsByTagName('input')[i].onmouseout=msgStatusOff;
				break;
			case 'text':
			case 'password':
				document.getElementsByTagName('input')[i].onfocus=attachFocus;
				
				// Add element's existing onblur event (if it has one) before adding a new onBlur event 'attachBlur'
				// This ensures that any existing onBlur event the element has is still executed, as well as the 'attachBlur' event.
				// Check if IE or Netscape and use appropriate syntax accordingly.
				if (navigator.appName == 'Microsoft Internet Explorer') {
					if (document.getElementsByTagName('input')[i].onblur) {
						// Assign existing onBlur to a temp event 'tempOnBlur' - Later executed in attachBlur function.
						document.getElementsByTagName('input')[i].tempOnBlur = document.getElementsByTagName('input')[i].onblur;
					}
					// attach new onblur event. This will cause the input field colour to change.
					document.getElementsByTagName('input')[i].onblur=attachBlur;
				}
				else {
				
					// attach existing onblur event.
					document.getElementsByTagName('input')[i].addEventListener('blur',attachBlur,false);
				}		
				break;
			default:
				break;
		}
	}
	for(i=0; i<document.getElementsByTagName('textarea').length; i++) {
		document.getElementsByTagName('textarea')[i].onfocus=attachFocus;
		document.getElementsByTagName('textarea')[i].onblur=attachBlur;
	}
}

function enableMenu() {
	window.status='';
	txtName=this.name.replace('img_','mn_');
	show(txtName);
	if (this.src.indexOf('_a.') != -1) {
		this.src=this.src.replace('_a.','_b.');
	}
}

function enableAllMenus() {

	var menubar = document.getElementById('menubar').getElementsByTagName('img');
	for(i=0;i<menubar.length;i++) {
		if(menubar[i].alt) {
			if ( menubar[i].src.substring(menubar[i].src.lastIndexOf('mn_'), menubar[i].src.length).indexOf('_.',3)==-1 ) {
				menubar[i].onmouseover=enableMenu;
				/* // menu section highlighting (disabled, not required for STA site)
				if(menubar[i].name=='img_'+pageId && menubar[i].src.indexOf('_a.') != -1) {
					menubar[i].src = menubar[i].src.replace('_a.','_b.');
				}
				*/
			}
		}
	}

	if (document.getElementById('xcontent')) {
		document.getElementById('content').onmouseover = hideAll;
	}

}

// toTitleCase
function toTitleCase(strString) {
	// strString = fnTrim(strString);
	var firstSpace = strString.indexOf(' ');
	var currentWord;
	strString = strString.charAt(0).toUpperCase()+strString.substring(1,strString.length);
	if (firstSpace > -1) strString=strString.substring(0,firstSpace+1) + toTitleCase(strString.substring(firstSpace+1,strString.length));
	return strString;
}
