var lhm=null; // last highlighted menu
var lhsm=null; // last highlighted submenu

var on = new Array();
var off = new Array();

function init(){
	cacheImages();
	fixPopupMenuPosition();
}

function stripeTable(id){
	if(o = document.getElementById(id)){
		for (i=0; i<o.rows.length; i++){
			if (i%2==0 && !o.rows(i).className)
				o.rows(i).className = "stripeHL";
		}
	}
}

function fixPopupMenuPosition(){
	var x = 184;
	var currentStudents = 250;  // y coordinate of current students popup menu
	var prospectiveStudents = 273;
	var clinicServices = 150;
	fixPosition("sub_current", x, currentStudents);
	fixPosition("sub_prospective", x, prospectiveStudents);
	fixPosition("sub_clinicServices", x, clinicServices);		
	
}

function fixPosition(id, x, y){
	if (o=document.getElementById(id) ){
		o.style.left = x+"px";
		o.style.top = y+"px";
	}
}
//*/
	
function cacheImages(){
	if (!document.images) return;
	var rootdir = "/hesp/";
	if (document.URL.indexOf("alpha") > -1)
		rootdir = "/hesp/alpha/";
	// if any .htm file is opened from a folder by double clicking such that the address starts with: x:\blah\blah.htm where x is the driver letter
	// then mouse roll over images will not show because the script assumes that the root directory of the hesp documents is in /hesp/
	on["home"] = new Image(); on["home"].src = rootdir + "common/home_on.jpg";
	off["home"] = new Image(); off["home"].src = rootdir + "common/home.jpg";
	//
	on["current"] = new Image(); on["current"].src = rootdir + "common/current_on.jpg";
	off["current"] = new Image(); off["current"].src = rootdir + "common/current.jpg";
	//
	on["prospective"] = new Image(); on["prospective"].src = rootdir + "common/prospective_on.jpg";
	off["prospective"] = new Image(); off["prospective"].src = rootdir + "common/prospective.jpg";
	
	on["research"] = new Image(); on["research"].src = rootdir + "common/research_on.jpg";
	off["research"] = new Image(); off["research"].src = rootdir + "common/research.jpg";
	//
	on["clinicServices"] = new Image(); on["clinicServices"].src = rootdir + "common/clinicServices_on.jpg";
	off["clinicServices"] = new Image(); off["clinicServices"].src = rootdir + "common/clinicServices.jpg";
	//
	on["continuingEducation"] = new Image(); on["continuingEducation"].src = rootdir + "common/continuingEducation_on.jpg";
	off["continuingEducation"] = new Image(); off["continuingEducation"].src = rootdir + "common/continuingEducation.jpg";
	//
	on["alumni"] = new Image(); on["alumni"].src = rootdir + "common/alumni_on.jpg";
	off["alumni"] = new Image(); off["alumni"].src = rootdir + "common/alumni.jpg";
	//	
	on["facultyStaff"] = new Image(); on["facultyStaff"].src = rootdir + "common/facultyStaff_on.jpg";
	off["facultyStaff"] = new Image(); off["facultyStaff"].src = rootdir + "common/facultyStaff.jpg";
	//
	on["contactus"] = new Image(); on["contactus"].src = rootdir + "common/contactus_on.jpg";
	off["contactus"] = new Image(); off["contactus"].src = rootdir + "common/contactus.jpg";
	//*/
}
//*/

// hlmemu, llmenu governs only it's 1st generation children submenus
// specific information on which to be closed after sibling is opened is to
// be decided inline
// this script assumes that the menus are static, and that the deepest level is 2
function hlmenu(name){
	if ((o = document.getElementById(name))){
		if (on[name])
			o.src = on[name].src;
		if (lhm != null && lhm!=name){
			llsubmenu(lhsm);  
			closeSubmenu("sub_"+lhm);  
			llmenu(lhm);
		}
		lhm = name;
		openSubmenu("sub_"+name);
	}
}

function openSubmenu(name){
	if ((o = document.getElementById(name))){
		lhsm = name;
		o.style.display = "block";
	}
}

function llmenu(name){
	if ((o = document.getElementById(name)) && off[name]){
			o.src = off[name].src;
	}
}

function closeSubmenu(name){
	if ((o = document.getElementById(name))){
		o.style.display = "none";
		lhsm = null;
	}
	// */
}

function hlsubmenu(name){
	if ((o = document.getElementById(name))){
		o.bgColor = '#CCCC99'; // first high light current item
		if (lhsm != null && lhsm != name){
			llsubmenu(lhsm); // second un-highlight last highted sub menu if there were one
			// if last highted submenu has its own children, we might want to hide that :)
			if ((o=document.getElementById("sub_"+lhsm))){
				o.style.visibility = 'hidden';
			}
			// then if current item has children, show it
			if ((o=document.getElementById("sub_"+name)))
				o.style.visibility = 'visible';
		}
		lhsm = name;
	}
}

function llsubmenu(name){
	if ((o = document.getElementById(name)))
		o.bgColor = '#A3D0FF';
}

function beforePrint(){
	var a = document.getElementById("cmdBeforePrint");
	var b = document.getElementById("cmdAfterPrint");
	var c = document.getElementById("menuCell");
	var d = document.getElementById('welcomeCell');	
	a.style.display = "none";
	b.style.display = "inline";
	c.style.display = "none";
	d.style.display = "none";
	window.print();
}

function afterPrint(){
	if (navigator.userAgent.match(/netscape/i))
		window.location.replace(window.location.href);
	else{
		var a = document.getElementById("cmdBeforePrint");
		var b = document.getElementById("cmdAfterPrint");
		var c = document.getElementById("menuCell");
		var d = document.getElementById('welcomeCell');
		b.style.display = "none";
		a.style.display = "inline";
		c.style.display = "inline";
		d.style.display = "inline";
	}
}

function mclick(){ // basicly reinitialize states of the menus
	llmenu(lhm);
	llsubmenu(lhsm);
	closeSubmenu("sub_"+lhm);
	lhsm=null;
	lhm = null;
}

var cursor_on = false;

function mover(){
	if (event.srcElement.target=="_blank")	{
		if( o = document.getElementById('nbCursor')){
			cursor_on = true;
			mmove(); // re-position cursor before turning it on
			o.style.visibility = "visible";
		}
	}
}

function mout(){
	if(o = document.getElementById('nbCursor')){
		o.style.visibility = "hidden";
		cursor_on = false;
	}
}

function mmove(){
	var x = event.x + document.body.scrollLeft+15;
	var y = event.y + document.body.scrollTop -25;
	if (cursor_on){
		var o = document.getElementById('nbCursor');
		o.style.left=x;
		o.style.top = y;
	}
}

document.onmousemove = mmove;
document.onmouseout = mout;
document.onmouseover = mover;
document.onclick = mclick;
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;

