


	
		
		
		
		
		
	 
	
	
	
	
	
	
	










	


		
		
		
	









	
	
	
		
	
	
	
	
	





/*
	NDE css-js menu script:
		modified 11092003 by Ethan Marcotte (emarcotte@vertua.com), from code
		originally available at http://devedge.netscape.com/lib/js/theme-menu-2.js
*/

function elementContains(elmOuter, elmInner) {
	while (elmInner && elmInner != elmOuter) {
		elmInner = elmInner.parentNode;
	}
	if (elmInner == elmOuter) {
		return true;
	}
	return false;
}

function getPageXY(elm) {
	var point = { x: 0, y: 0 };
	while (elm) {
		point.x += elm.offsetLeft;
		point.y += elm.offsetTop;
		elm = elm.offsetParent;
	}
	return point;
}

function setPageXY(elm, x, y) {
	var parentXY = {x: 0, y: 0 };

	if (elm.offsetParent) {
		parentXY = getPageXY(elm.offsetParent);
	}

	elm.style.left = (x - parentXY.x) + 'px';
	elm.style.top  = (y - parentXY.y) + 'px';
}

function cssjsmenu(menuid) {
	var i;
	var j;
	var node;
	var child;
	var parent;
	var currentPage = document.getElementsByTagName('body')[0].className;

	// require proper DOM support
	if (!document.getElementById) {
		return true;
	}

	var version;
	var offset;

	offset = navigator.userAgent.indexOf('AppleWebKit');
	if (offset != -1) {
		return true;
	}

	offset = navigator.userAgent.indexOf('Opera');
	if (offset != -1) {
		version = parseInt('0' + navigator.userAgent.substr(offset + 6), 10);
		if (version < 7) {
			return true;
		}
	}

	offset = navigator.userAgent.indexOf('MSIE');
	if (offset != -1) {
		if (navigator.userAgent.indexOf('Mac') != -1) {
			return true;
		}
	}

	var menudiv = document.getElementById(menuid);

	// ul
	var ul = new Array();

	for (i = 0; i < menudiv.childNodes.length; i++)
	{
		node = menudiv.childNodes[i];
		if (node.nodeName.toUpperCase() == 'UL')
		{
			ul[ul.length] = node;
		}
	}

	// ul > li
	var ul_gt_li = new Array();

	for (i = 0; i < ul.length; i++) {
		node = ul[i];
		for (j = 0; j < node.childNodes.length; j++) {
			child = node.childNodes[j];
			if (child.nodeName.toUpperCase() == 'LI')
			{
				ul_gt_li[ul_gt_li.length] = child;
				child.style.listStyle = 'none';
				child.style.position = 'static';
			}
		}
	}

	// ul > li > ul
	var ul_gt_li_gt_ul = new Array();

	for (i = 0; i < ul_gt_li.length; i++) {
		node = ul_gt_li[i];
		for (j = 0; j < node.childNodes.length; j++) {
			child = node.childNodes[j];
			if (child.nodeName.toUpperCase() == 'UL') {
				ul_gt_li_gt_ul[ul_gt_li_gt_ul.length] = child;
				child.style.position = 'absolute';
				child.style.left = '-13em';
				child.style.visibility = 'hidden';

				// attach hover to parent li
				parent = child.parentNode;
				parent.onmouseover = function(e) {
					var isWinIE = (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Mac') == -1) ? 1 : 0;
					var i;
					var child;
					var point;
					var itemId = this.getAttribute('id').split("-")[1];

					for (i = 0; i < this.childNodes.length; i++) {
						child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {
							/* position and show the child */
							point = getPageXY(this);
							deltaX = (isWinIE) ? 5 : 0;
							deltaY = (isWinIE) ? 4 : 0;

							setPageXY(child, point.x + deltaX, point.y + this.offsetHeight - deltaY);
							child.style.visibility = 'visible';

							/* add a 15px cut to the right-hand side of the tab */
							if (child.offsetWidth < this.offsetWidth + 15) {
								child.style.width = this.offsetWidth + 15 + 'px';
							}
						} else if (child.nodeName.toUpperCase() == "A" && itemId != currentPage) {
							child.style.color = "#666";
							child.style.backgroundImage = "url(\"http://learnweb.harvard.edu/wide/_share/imgs/nav_right.gif\")";
							child.style.backgroundRepeat = "no-repeat";
							child.style.backgroundPosition = "top right";

							for (j = 0; j < child.childNodes.length; j++) {
								if (child.childNodes[j].nodeName.toUpperCase() == "SPAN") {
									child.childNodes[j].style.backgroundImage = "url(\"http://learnweb.harvard.edu/wide/_share/imgs/nav_left.gif\")";
									child.childNodes[j].style.backgroundRepeat = "no-repeat";
									child.childNodes[j].style.backgroundPosition = "top left";
								}
							}
						}
					}
					return false;
				};

				parent.onmouseout = function(e) {
					var itemId = this.getAttribute('id').split("-")[1];
					var relatedTarget = null;
					if (e) {
						relatedTarget = e.relatedTarget;
						// work around Gecko Linux only bug where related target is null
						// when clicking on menu links or when right clicking and moving
						// into a context menu.
						if (navigator.product == 'Gecko' && navigator.platform.indexOf('Linux') != -1 && !relatedTarget) {
							relatedTarget = e.originalTarget;
						}
					} else if (window.event) {
						relatedTarget = window.event.toElement;
					}

					if (elementContains(this, relatedTarget)) {
						return false;
					}

					var i;
					var child;
					for (i = 0; i < this.childNodes.length; i++) {
						child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {
							  child.style.visibility = 'hidden';
						} else if (child.nodeName.toUpperCase() == "A" && itemId != currentPage) {
							child.style.color = "#000";
							child.style.backgroundImage = "none";

							grandchildren = child.childNodes;
							for (j = 0; j < grandchildren.length; j++) {
								if (grandchildren[j].nodeName.toUpperCase() == "SPAN") {
									grandchildren[j].style.backgroundImage = "none";
								}
							}
						}
					}
					return false;
				};
			}
		}
	}
	return true;
}

/*
	function: Scott Andrew LePera's addEvent()
	arguments:
		obj = element to which event will be attached
		evType = type of event ("click","mouseout", etc.)
		fn = event handler function
*/
function addEvent(obj, evType, fn){
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, false); 
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		return false;
	}
}

// ATTACH ATTRIBUTES TO ANCHORS
function createExternals() {
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('href')) {
			switch (anchor.getAttribute('rel')) {
				case "external":
					anchor.target = "_extlink";
					break;
				case "frame":
					anchor.target = "_top";
					break;
			}
		}
	}
}
// end ATTACH ATTRIBUTES TO ANCHORS

// POPUP WINDOW OBJECT
function popup(URL, w, h, scr, name, adj) {
	var adj = (adj) ? adj : '0';
	
	if(adj != '0'){
		var w = screen.width - 100;
		var h = screen.height - 100;
	}
	else{
		var w = (w) ? w : '675';
		var h = (h) ? h : '500';
	}
	var tmp = (scr) ? (scr == 0) ? 'no' : 'yes' : 'yes';
	var name = (name) ? name : 'winObj';

	winProps = 'height=' + h + ',width=' + w + ',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=' + tmp + ',resizable=yes';
	winObj = window.open(URL,name,winProps);
	winObj.focus();
}
// end POPUP WINDOW OBJECT

/*
	Stupid proprietary PNG hack for IE/Win
*/
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "http://learnweb.harvard.edu/wide/_share/imgs/spacer.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

// IE needs to be smacked in the head for proper PNG support
function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "http://learnweb.harvard.edu/wide/_share/imgs/spacer.gif";
}

// cookie functions
function getCookie(name) {
    var start = document.cookie.indexOf(name + '=');
    var len = start + name.length + 1;

    if (!start && (name != document.cookie.substring(0,name.length))) {
    	return null;
    }

    if (start == -1) {
    	return null;
    }

    var end = document.cookie.indexOf(";",len);
    if (end == -1) {
    	end = document.cookie.length;
    }
    return unescape(document.cookie.substring(len,end));
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + '=' +escape(value) +
		((expires) ? ';expires=' + expires.toGMTString() : '') +
		((path) ? ';path=' + path : '') + 
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
}

// RUN ALL SCRIPTS
window.onload = function(e) {
	createExternals();
	cssjsmenu('nav');
	setCookie('JAVASCRIPTENABLED','yes','','/','.harvard.edu');
}
