function BasicMenu(label) {

// Variables:
	this.fontSize = "8pt";
	this.fontFamily = "verdana";
	this.fontColor = "#ffffff";
	this.fontStyle = "normal";
	this.fontWeight = "normal";
	this.bgColor = "#000066";
	this.hiliteFontColor = "#ffbb22";
	this.hiliteFontStyle = "normal";
	this.hiliteFontWeight = "normal";
	this.hiliteBgColor = "#6699cc";
	this.borderStyle = "opaque";
	this.borderColor = "#000066";
	this.border = new Object;
	this.border.top = 0;
	this.border.bottom = 0;
	this.border.left = 0;
	this.border.right = 0;
	this.itemSpacer = 0;
	this.label = label;
	this.pageX = 0;
	this.pageY = 0;
	this.width = 100;
	this.height = 200;
	this.index = 0;
	this.layer;
	this.hideable = true;
	this.parentLayer;
	this.items = new Array();

// Functions:
	this.setSize = setMenuSize;
	this.setLocation = setMenuLocation;
	this.setBounds = setMenuBounds;
	this.addItem = addMenuItem;
	this.mouseExited = mouseExitedMenu;
	this.show = showMenu;
	this.hide = hideMenu;
	this.forceHide = forceHideMenu;
	this.render = renderMenu;
	this.contains = contains;

	if(!window.menus) window.menus = new Array();
	this.index = window.menus.length;
	window.menus[this.label] = this;
	window.menus[window.menus.length] = this;

}


function navmenu(label) {

// Variables:
	this.fontSize = "8pt";
	this.fontFamily = "verdana";
	this.fontColor = "#ffffff";
	this.fontStyle = "normal";
	this.fontWeight = "normal";
	this.bgColor = "#6699cc";
	this.hiliteFontColor = "#ffffff";
	this.hiliteFontStyle = "normal";
	this.hiliteFontWeight = "normal";
	this.hiliteBgColor = "#000066";
	this.borderStyle = "opaque";
	this.borderColor = "#000000";
	this.border = new Object;
	this.border.top = 0;
	this.border.bottom = 0;
	this.border.left = 0;
	this.border.right = 0;
	this.itemSpacer = 0;
	this.label = label;
	this.pageX = 0;
	this.pageY = 0;
	this.width = 125;
	this.height = 200;
	this.index = 0;
	this.layer;
	this.hideable = true;
	this.parentLayer;
	this.items = new Array();

// Functions:
	this.setSize = setMenuSize;
	this.setLocation = setMenuLocation;
	this.setBounds = setMenuBounds;
	this.addItem = addMenuItem;
	this.mouseExited = mouseExitedMenu;
	this.show = showMenu;
	this.hide = hideMenu;
	this.forceHide = forceHideMenu;
	this.render = renderMenu;
	this.contains = contains;

	if(!window.menus) window.menus = new Array();
	this.index = window.menus.length;
	window.menus[this.label] = this;
	window.menus[window.menus.length] = this;

}

if(document.layers) {
	ns4 = true;
	ie4 = false;
	show = "show";
	hide = "hide";
	document.captureEvents(Event.MOUSEMOVE);
} else if(document.all) {
	ns4 = false;
	ie4 = true;
	show = "visible";
	hide = "hidden";
}

var activeMenu;

document.onmousedown = mousePressed;


function mousePressed(evnt) {
	x = (document.layers) ? evnt.pageX : event.clientX + document.body.scrollLeft;
	y = (document.layers) ? evnt.pageY : event.clientY + document.body.scrollTop;
	if(activeMenu && !activeMenu.contains(x,y)) activeMenu.forceHide();
	activeMenu = null;
}

document.onmousemove = mouseMoved;
function mouseMoved(evnt) {
	window.mouseX = (document.layers) ? evnt.pageX : event.clientX + document.body.scrollLeft;
	window.mouseY = (document.layers) ? evnt.pageY : event.clientY + document.body.scrollTop;
}

function contains(x,y) {
	xlo = parseInt(this.pageX);
	ylo = parseInt(this.pageY);
	xhi = parseInt(xlo + this.width);
	yhi = parseInt(ylo + this.height);
//alert(xlo+" <= "+x+" <= "+xhi+"\n"+ylo+" <= "+y+" <= "+yhi);
	if(xlo <= x && xhi >= x && ylo <= y && yhi >= y) return(true);
	else return(false);
}

function mouseEnteredItem(evnt,item) {
	item = item || this;
	if(ns4) {
		norm = item.document.layers[0];
		hilite = item.document.layers[1];
		item.bgColor = item.menu.hiliteBgColor;
	} else {
		norm = item.all["normalText"].style;
		hilite = item.all["hiliteText"].style;
		item.style.backgroundColor = item.menu.hiliteBgColor;
		item.Menu.hideable = false;
	}
	norm.visibility = hide;
	hilite.visibility = "inherit";
	window.status = item.action;
	return(true);
}

function mouseExitedItem(evnt,item) {
	item = item || this;
	if(ns4) {
		norm = item.document.layers[0];
		hilite = item.document.layers[1];
		item.bgColor = item.menu.bgColor;
	} else {
		norm = item.all["normalText"].style;
		hilite = item.all["hiliteText"].style;
		item.style.backgroundColor = item.menu.bgColor;
		item.Menu.hideable = false;
	}
	norm.visibility = "inherit";
	hilite.visibility = hide;
	window.status = "";
	return(true);
}

function mouseExitedMenu(evnt,menuLayer) {
	menuLayer = menuLayer || this;
	menu = menuLayer.object;
	if(document.layers) {
		menu.forceHide();
		return;
	}
	x = (document.layers) ? evnt.pageX : event.clientX + document.body.scrollLeft;
	y = (document.layers) ? evnt.pageY : event.clientY + document.body.scrollTop;
	x += sign(x - window.mouseX);
	y += sign(y - window.mouseY);
	if(!menu.contains(x,y)) menu.forceHide();
}

function sign(val) {
	if(val > 0) return(1);
	else if(val < 0) return(-1);
	else return(0);
}

function fabs(val) {
	if(val < 0) return(-val);
	else return(val);
}

function invokeItemAction(evnt,item) {
	item = item || this.parentLayer;
	if (!item.targetwindow) {
		window.location = item.action;
	} else {
		window.open(item.action, item.targetwindow);
	}
}

function setMenuSize(width, height) {
	this.width = width;
	this.height = height;
	if(this.layer && document.layers) {
		this.layer.clip.width = width;
		this.layer.clip.height = height;
	} else if(this.layer && document.all) {
		this.layer.pixelWidth = width;
		this.layer.pixelHeight = height;
	}
}

function setMenuLocation(x, y) {
	this.pageX = x;
	this.pageY = y;
	if(this.layer && document.layers) {
		this.parentLayer.left = x;
		this.parentLayer.top = y;
	} else if(this.layer && document.all) {
		this.parentLayer.pixelLeft = x;
		this.parentLayer.pixelTop = y;
	}
}

function setMenuBounds(x, y, width, height) {
	this.pageX = x;
	this.pageY = y;
	this.width = width;
	this.height = height;
}

function addMenuItem(item,action,targetwindow) {
	var idx = this.items.length;
	this.items[idx] = new Object;
	this.items[idx].value = item;
	this.items[idx].action = action;
	if (targetwindow) {
		this.items[idx].targetwindow = targetwindow;
	}
}

function renderMenu(container,root) {
	menu = this;
	if (!container && document.layers) {
		if(eval("document.width")) container = new Layer(1000);
		container.left = menu.pageX;
		container.top = menu.pageY;
		container.clip.width = menu.width;
		container.clip.height = menu.height;
	} else if (!container && document.all) {
		if(!document.all["ticker"+this.tickerIndex+"Container"]) {
			document.writeln('<div id="menu' + this.index + 'Container" style="position:absolute;top:' + this.pageY + ';left:' + this.pageX + ';width:' + this.width + ';visibility:hidden;"></div>');
		}
		container = document.all["menu"+menu.index+"Container"];
		container.style.pixelLeft = menu.pageX;
		container.style.pixelTop = menu.pageY;
		container.style.pixelWidth = menu.width;
		container.style.pixelHeight = menu.height;
	} else if(document.layers) {
		menu.width = container.clip.width;
		menu.height = container.clip.height;
	} else {
		menu.width = container.offsetWidth;
		menu.height = container.offsetHeight;
	}

	ie4 = false;
	if(navigator.appVersion.indexOf("MSIE 4") >= 0) ie4 = true;

	var content = '<div id="menu' + menu.index + '" style="position:absolute;left:0;top:0;width:' + menu.width + ';height:' + menu.height + ';visibility:inherit;">\n';
	var styleTag = 'position:absolute;top:0;left:0;width:' + (menu.width-menu.border.left-menu.border.right) + ';font-family:' + menu.fontFamily + ';font-size:' + menu.fontSize + ';';
	if(ie4) styleTag += 'visibility:' + show + ';';
	else styleTag += 'visibility:inherit;';
	for(var i=0; i<this.items.length; i++) {
		content += ' <div id="item' + i + '" style="' + styleTag + '" onMouseOver="mouseEnteredItem(null,this)" onMouseOut="mouseExitedItem(null,this)" onMouseDown="invokeItemAction(null,this)">\n';
		content += '  <div id="normalText" style="position:absolute;left:0;top:0;width:' + menu.width + ';color:' + menu.fontColor + ';font-style:' + menu.fontStyle + ';font-weight:' + menu.fontWeight + ';">' + menu.items[i].value + '</div>\n';
		content += '  <div id="hiliteText" style="position:absolute;left:0;top:0;visibility:' + hide + ';color:' + menu.hiliteFontColor + ';font-style:' + menu.hiliteFontStyle + ';font-weight:' + menu.hiliteFontWeight + ';">' + menu.items[i].value + '</div>\n';
		content += '  <div id="cover" style="position:absolute;top:0;left:0;visibility:inherit;"></div>\n';
		content += ' </div>\n';
	}
	content += '</div>\n';

	if(document.all && !ie4) {
		container.innerHTML = content;
	} else if(document.all) {
		ie4 = true;
		content = '<div id="menu' + menu.index + 'Container" style="position:absolute;left:' + menu.pageX + ';top:' + menu.pageY + ';width:' + menu.width + ';height:' + menu.height + ';visibility:visible;">' + content + '</div>';
		container.document.open("text/html");
		container.document.writeln(content);
		container.document.close();
	} else {
		container.document.open("text/html");
		container.document.writeln(content);
		container.document.close();
	}

	if(document.layers) {
		margin = new Object;
		margin.vert = 4;
		margin.horiz = 15;
		menu.layer = container.document.layers["menu" + menu.index];
		var mLayer = menu.layer;
		menu.parentLayer = container;
		mLayer.onmouseout = menu.mouseExited;
		mLayer.object = menu;
		if(menu.borderStyle == "opaque") mLayer.document.bgColor = menu.borderColor;
		var width = mLayer.clip.width + 2*margin.horiz, h = menu.border.top;
		for(var i=0; i<mLayer.layers.length; i++) {
			var item = mLayer.document.layers[i];
			item.left = menu.border.left;
			item.top = h;
			item.bgColor = menu.bgColor;
			norm = item.document.layers[0];
			hilite = item.document.layers[1];
			cover = item.document.layers[2];
			item.clip.width = width;
			item.clip.height = norm.clip.height + 2*margin.vert;
			norm.top = margin.vert;
			norm.left = margin.horiz;
			hilite.top = margin.vert;
			hilite.left = margin.horiz;
			item.onmouseover = mouseEnteredItem;
			item.onmouseout = mouseExitedItem;
			cover.captureEvents(Event.CLICK | Event.MOUSEDOWN);
			if(navigator.platform.indexOf("Win") >= 0) cover.onclick = invokeItemAction;
			else cover.onmousedown = invokeItemAction;
			item.menu = menu;
			item.action = menu.items[i].action;
			if (menu.items[i].targetwindow) {
				item.targetwindow = menu.items[i].targetwindow;
			}
			cover.clip.width = item.clip.width;
			cover.clip.height = item.clip.height;
			menu.items[i].layer = item;
			h += item.clip.height + menu.itemSpacer;
			y = h;
		}
		mLayer.clip.width = width + menu.border.left + menu.border.right;
		mLayer.clip.height = h + menu.border.bottom - menu.itemSpacer || mLayer.clip.height;
		container.left = menu.pageX;
		container.top = menu.pageY;
		container.clip.width = mLayer.clip.width;
		container.clip.height = mLayer.clip.height;
		if(root) {
			container.left = root.pageX;
			container.top = root.pageY + root.clip.height;
			menu.pageX = container.left;
			menu.pageY = container.top;
		}
		menu.width = mLayer.clip.width;
		menu.height = mLayer.clip.height;
	} else if(document.all) {
		margin = new Object;
		margin.vert = 4;
		margin.horiz = 15;
		mLayer = container.document.all("menu" + menu.index);
		menu.parentLayer = container.style;
		menu.layer = mLayer.style;
		mLayer.style.visibility = "inherit";
		mLayer.onmouseout = menu.mouseExited;
		mLayer.object = menu;
		var width = menu.width + 2*margin.horiz, h = menu.border.top, dh = parseInt(menu.fontSize) + 6;
		for(var i=0; i<menu.items.length; i++) {
			var item = mLayer.all("item"+i);
			item.Menu = menu;
			item.style.pixelLeft = menu.border.left;
			item.style.pixelTop = h;
			item.style.backgroundColor = menu.bgColor;
			norm = item.all("normalText");
			norm.style.pixelTop = margin.vert;
			norm.style.pixelLeft = margin.horiz;
			hilite = item.all("hiliteText");
			itemCover = item.all("cover");
			item.style.pixelWidth = width;
			if(ie4) item.style.pixelHeight = dh + 2*margin.vert;
			else item.style.pixelHeight = norm.offsetHeight + 2*margin.vert;
			hilite.style.pixelTop = margin.vert;
			hilite.style.pixelLeft = margin.horiz;
			item.style.visibility = "inherit";
			item.menu = menu;
			item.action = menu.items[i].action;
			if (menu.items[i].targetwindow) {
				item.targetwindow = menu.items[i].targetwindow;
			}
			norm.style.visibility = "inherit";
			hilite.style.visibility = hide;
			itemCover.style.visibility = "inherit";
			itemCover.style.pixelWidth = width;
			itemCover.style.pixelHeight = item.style.pixelHeight;
			menu.items[i].layer = item.style;
			h = h + parseInt(item.style.pixelHeight) + menu.itemSpacer;
			y = h;
		}
		mLayer.style.pixelWidth = width + menu.border.left + menu.border.right;
		mLayer.style.pixelHeight = h + menu.border.bottom - menu.itemSpacer || mLayer.style.pixelHeight;
		container.style.pixelLeft = menu.pageX;
		container.style.pixelTop = menu.pageY;
		container.style.pixelWidth = mLayer.style.pixelWidth;
		container.style.pixelHeight = mLayer.style.pixelHeight;
		if(menu.borderStyle == "opaque") mLayer.style.backgroundColor = menu.borderColor;
		if(root) {
			/*obj = root;
			var bottom = obj.offsetHeight, left = 0;
			while(obj) {
				bottom += obj.offsetTop;
				left += obj.offsetLeft;
				obj = obj.offsetParent;
			}
			container.style.pixelLeft = left;
			container.style.pixelTop = bottom;
			menu.pageX = container.style.pixelLeft;
			menu.pageY = container.style.pixelTop;*/
		}
		menu.width = mLayer.style.pixelWidth;
		menu.height = mLayer.style.pixelHeight;
		menu.forceHide();
	}
}

function hideMenu(menu) {
	menu = menu || this;
	if(!menu.contains(window.mouseX,window.mouseY)) {
		menu.forceHide();
	}
}

function forceHideMenu(menu) {
	menu = menu || this;
	menu.parentLayer.visibility = hide;
	menu.layer.visibility = hide;
}

function showMenu(menu) {
	menu = menu || this;
	if(activeMenu) {
		activeMenu.forceHide();
	}
	menu.parentLayer.visibility = show;
	menu.layer.visibility = show;
	activeMenu = menu;
}

function onLoad() {

//Navigation Menus


window.curr_d = new BasicMenu("Curriculum_Description");

curr_d.addItem("Core Competencies","/curriculum/Description/Core%20Competencies.pdf");
curr_d.addItem("Calendars","/curriculum/currdesc.htm");
curr_d.addItem("Curriculum Details","/curriculum/currdesc.htm");
curr_d.addItem("Description of the Next 4 Years","http://www.med.unc.edu/curriculum/orientation/summary.htm", "_blank");curr_d.setSize(150,100);
curr_d.setLocation(120,79);
curr_d.render();

window.curr_a = new BasicMenu("Curriculum_Administration");
curr_a.addItem("Policies & Procedures","/curriculum/curradm.htm");
curr_a.addItem("Curriculum Committees","/curriculum/curradm.htm");
curr_a.addItem("Governance Structure","/curriculum/Administration/orgcrt_governancefinal_rev032002.pdf");
curr_a.addItem("Current Curriculum Profile Report", "http://www.med.unc.edu/oed/currdocs/2001-2002Profile.pdf", "_blank");
curr_a.addItem("Administration-Related Reports","curradm.htm");
curr_a.setSize(150,100);
curr_a.setLocation(122,128);
curr_a.render();

window.fac_r = new BasicMenu("Faculty_Resources");
fac_r.addItem("Faculty Development","http://www.med.unc.edu/or_facultydevelopment.htm", "_blank");
fac_r.addItem("Teaching Resources","http://www.med.unc.edu/teachingresources.htm", "_blank");
fac_r.addItem("Excellence in Teaching Series","http://www.med.unc.edu/oed/eit/", "_blank");
fac_r.addItem("Nuts & Bolts for Course Directors","http://www.med.unc.edu/oed/eit/eit_nblinks.htm", "_blank");
fac_r.addItem("Educational Technology Group","http://www.med.unc.edu/etg", "_blank");
fac_r.addItem("Health Sciences Library","http://www.hsl.unc.edu/", "_blank");
fac_r.addItem("Office of Curricular Support (MSTL)","http://www.med.unc.edu/ome/mstl", "_blank");

fac_r.setSize(150,100);
fac_r.setLocation(122,175);
fac_r.render();


window.stu_r = new BasicMenu("Student_Resources");
stu_r.addItem("Incoming Student Orientation Information","http://www.med.unc.edu/curriculum/orientation/", "_blank");
stu_r.addItem("Office of Student Affairs","http://www.med.unc.edu/stuaff/", "_blank");
stu_r.addItem("Student Organizations","http://www.med.unc.edu/orgs.htm", "_blank");
stu_r.addItem("Testing & Assessment","/curriculum/stures.htm");
stu_r.addItem("Optional Degree Programs","/curriculum/stures.htm");
stu_r.setSize(150,100);
stu_r.setLocation(122,238);
stu_r.render();



}
