if (!document.easing) {
	document.write('<scr' + 'ipt language="javascript" type="text/javascript" src="/global/js/classes/easing.js"></scr' + 'ipt>');
}

if (!String.pad) {
	document.write('<scr' + 'ipt language="javascript" type="text/javascript" src="/global/js/classes/string_extended.js"></scr' + 'ipt>');
}

var topbarManager = function () {
	
	if (!document.getElementById) {
		return null;
	}

	if (document.all && navigator.userAgent.search(/mac/i) >= 0) {
		return null;
	}
	
	var tools = document.getElementById('topbar-tools');

	if (tools) {

		// we're here... turn it on
		document.css.setStyleValue(tools, 'display', 'block');

		// deal with PNG fade over rest of topbar for IE
		if (tools.filters) {
			if (document.getElementsByTagName) {
				var nodes = tools.getElementsByTagName('IMG');
			} else {
				var nodes = tools.childNodes;
			}
			for (var i = 0; i < nodes.length; i ++) {
				if (nodes[i].id && nodes[i].id == 'fade') {
					nodes[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + nodes[i].src + "', sizingMethod=crop')";
					nodes[i].src = '/images/spacer.gif';
				}
			}
		}
		
		// set default values
		tools.waitTime = 2500;
		tools.isOpen = false;
		tools.isOpening = false;
		tools.isClosing = false;
		tools.backupHidden = false;
		
		tools.hideBackup = function () {
			var toolsBackup = document.getElementById('topbar-help');
			if (toolsBackup) {
				document.css.setStyleValue(toolsBackup, 'display', 'none');
				this.backupHidden = true;
			}
		};

		tools.onmouseover = function () {
			if (!this.backupHidden) {
				this.hideBackup();
			}
			this.show();
		};

		tools.show = function () {
			if (!this.isOpening && !this.isOpen) {
				this.isClosing = false;
				this.isOpening = true;
				if (document.easing) {
					document.easing.begin(this, 'width', '330px',
						function () {
							this.obj.isOpening = false;
							this.obj.isOpen = true;
							document.css.setStyleValue(this.obj, 'overflow', 'visible');
						}, 0.5);
				} else if (document.css) {
					document.css.setStyleValue(this, 'width', '330px');
					this.isOpening = false;
					this.isOpen = true;
					document.css.setStyleValue(this, 'overflow', 'visible');
				}
			}
			this.resetTimer();
		};

		tools.hide = function () {
			if (this.linksObj.content.isClosed && !this.isClosing) {
				document.css.setStyleValue(this, 'overflow', 'hidden');
				this.isOpen = false;
				this.isOpening = false;
				this.isClosing = true;
				if (document.easing) {
					document.easing.begin(this, 'width', '102px',
						function () {
							this.obj.isClosing = false;
							this.obj.linksObj.trigger.hideHover();
							this.obj.searchObj.trigger.hideHover();
						}
					);
				} else if (document.css) {
					document.css.setStyleValue(this, 'width', '102px');
					this.isClosing = false;
				}
			}
		};

		tools.resetTimer = function (resetFactor) {
			if (this.timer) {
				clearTimeout(this.timer);
			}
			this.timer = setTimeout("document.tools.hide()", (this.waitTime * (((factor = parseInt(resetFactor)) > 1)? factor : 1)));
		};

		document.tools = tools;

		var	toolsets = new Array('search', 'links');
		
		for (var i = 0; i < toolsets.length; i ++) {
			var	toolset = toolsets[i],
					trigger = document.getElementById(toolset + '-trigger'),
					content = document.getElementById(toolset + '-content');
			if (trigger && content) {
				trigger.content = content;
				content.trigger = trigger;
				document.css.setStyleValue(content, 'opacity', 0);
				document.css.setStyleValue(trigger.childNodes[0], 'opacity', 0);
				tools[toolset + 'Obj'] = {
					trigger: trigger,
					content: content
				};
				content.show = function () {
					document.css.setStyleValue(this, 'display', 'block');
					this.style.display = 'block';
					if (document.easing) {
						document.easing.begin(this.alt, 'opacity', 0,
							function () {
								document.css.setStyleValue(this.obj, 'display', 'none');
							}, 0.25);
						document.easing.begin(this, 'opacity', 1,
							function () {
								switch (this.obj.id) {
									case 'search-content':
										setTimeout('document.tools.searchObj.content.searchForm.q.focus();document.tools.searchObj.content.searchForm.q.select();', 33);
										break;
									case 'links-content':
										document.tools.linksObj.content.showList();
										break;
								}
							}, 0.5);
					} else {
						document.css.setStyleValue(this.alt, 'display', 'none');
					}
				};
				trigger.showHover = function () {
					document.css.setStyleValue(this.childNodes[0].childNodes[0], 'opacity', 1);
					document.css.setStyleValue(this.childNodes[0], 'opacity', 1);
					document.easing.begin(this.alt.childNodes[0].childNodes[0], 'opacity', 0, null, 0.25);
				};
				trigger.hideHover = function () {
					document.easing.begin(this.childNodes[0], 'opacity', 0, null, 0.5);
				};
				trigger.onmouseover = function () {
					document.tools.show();
					this.content.show();
					this.showHover();
				};
			}
		}

		// cross-reference between objects
		if (tools.searchObj.content && tools.linksObj.content) {
			tools.searchObj.content.alt = tools.linksObj.content;
			tools.linksObj.content.alt = tools.searchObj.content;
		}
		if (tools.searchObj.trigger && tools.linksObj.trigger) {
			tools.searchObj.trigger.alt = tools.linksObj.trigger;
			tools.linksObj.trigger.alt = tools.searchObj.trigger;
		}

		// search-tools content-specific javascript
		searchForm = document.getElementById('search-form');
		if (searchForm) {
			
			document.tools.searchObj.content.searchForm = searchForm;
			
			var	thisPath = unescape(document.URL).replace(/^http:\/\//i, '').replace(/\/[^\/]+$/i, '').split('/'),
					sitePaths = new Array();
			switch (thisPath[1]) {
				case 'admission':
				case 'bookstore':
				case 'cal':
				case 'compasscard':
				case 'internal':
				case 'local':
				case 'mediaguide':
				case 'montag':
				case 'museum_of_art':
				case 'news':
				case 'parents':
				case 'president':
				case 'registar':
				case 'scene':
				case 'stories':
				case 'ur':
				case 'wits':
					sitePath = new Array(thisPath[0], thisPath[1]);
					searchForm.siteSearch = 'inurl:' + sitePath.join('/'); 
					break;
				case 'campaign':
				case 'support':
				case 'telefund':
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'support').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'campaign').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'telefund').join('/');
					break;
				case 'agsm':
				case 'atkinson':
				case 'mba':
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'agsm').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'atkinson').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'mba').join('/');
					break;
				case 'soe':
				case 'mat':
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'soe').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'mat').join('/');
					break;
				case 'wucl':
				case 'law':
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'wucl').join('/');
					sitePaths[sitePaths.length] = 'inurl:' + new Array(thisPath[0], 'law').join('/');
					break;
				case 'athletics':
					sitePath = new Array(thisPath[0], thisPath[1], thisPath[2]);
					if (thisPath[2] == 'teams') {
						sitePath.push(thisPath[3]);
						if (thisPath[4].search(/men/i) >= 0) {
							sitePath.push(thisPath[4]);
						}
					}
					searchForm.siteSearch = 'inurl:' + sitePath.join('/'); 
					break;
				default: 
					sitePath = new Array(thisPath[0], thisPath[1], thisPath[2]);
					searchForm.siteSearch = 'inurl:' + sitePath.join('/'); 
			}
			if (sitePaths.length > 0) {
				searchForm.siteSearch = sitePaths.join(' OR '); 
			}
			
			searchForm.setTarget = function (obj) {
				switch (obj.name) {
					case 'site-all':
						this.action = 'http://www.google.com/u/willametteuniversity';
						this.method = 'get';
						this.hq.disabled = true;
						this.name.disabled = true;
						break;
					case 'site-this':
						this.action = 'http://www.google.com/u/willametteuniversity';
						this.method = 'get';
						this.hq.disabled = false;
						this.hq.value = this.siteSearch;
						this.name.disabled = true;
						break;
					case 'people':
						this.action = 'http://www.willamette.edu/phonebook/dir.cgi';
						this.method = 'post';
						this.hq.disabled = true;
						this.name.disabled = false;
						this.name.value = this.q.value;
						break;
				}
			}
			
			var checks = new Array('site-all', 'site-this', 'people');
			searchForm.checks = new Array();
			for (var i = 0; i < searchForm.childNodes.length; i ++) {
				if (searchForm.childNodes[i].name == 'search') {
					searchForm.childNodes[i].exec = function () {
						if (this.parentNode && this.parentNode.submit) {
							this.parentNode.submit();
						}
						return false;
					};
				} else if (searchForm.childNodes[i].name && searchForm.childNodes[i].name.inArray(checks)) {
					searchForm[searchForm.childNodes[i].name] = searchForm.childNodes[i];
					searchForm.checks[searchForm.checks.length] = searchForm.childNodes[i];
					searchForm.childNodes[i].check = function () {
						this.parentNode.setTarget(this);
						if (this.className.search(/ checked/i) < 0) {
							this.className += ' checked';
						}
						for (var i = 0; i < this.others.length; i ++) {
							this.others[i].className = this.others[i].className.replace(/ checked/i, '');
						}
						return false;
					};
				}
			}
			for (var i = 0; i < searchForm.checks.length; i ++) {
				searchForm.checks[i].others = new Array();
				for (var j = 0; j < searchForm.checks.length; j ++) {
					if (searchForm.checks[i].name != searchForm.checks[j].name) {
						searchForm.checks[i].others[searchForm.checks[i].others.length] = searchForm.checks[j];
					}
				}
			}

		}

		// links-tools content-specific javascript
		if (tools.linksObj.content) {
			
			tools.linksObj.content.isClosed = true;
			tools.linksObj.content.isClosing = false;

			tools.linksObj.content.showList = function () {
				if (this.isClosed) {
					this.isClosed = false;
					if (document.easing) {
						document.easing.begin(this, 'height', '318px', null, 0.75);
					} else {
						document.css.setStyleValue(this, 'height', '318px');
					}
				}
				this.resetTimer();
			};

			tools.linksObj.content.resetTimer = function () {
				if (this.timer) {
					clearTimeout(this.timer);
				}
				this.timer = setTimeout("document.tools.linksObj.content.hideList()", document.tools.waitTime);
			};
	
			tools.linksObj.content.hideList = function () {
				if (!this.isClosing && !this.isClosed) {
					this.isClosing = true;
					if (document.easing) {
						document.easing.begin(this, 'height', '34px', function () { this.obj.isClosing = false; this.obj.isClosed = true; document.tools.hide(); }, 0.5);
					} else {
						document.css.setStyleValue(this, 'height', '34px');
						this.isClosing = false;
						this.isClosed = true;
						document.tools.hide();
					}
				} else {
					this.resetTimer();
				}
			};
			
			tools.linksObj.content.onmouseover = function () {
				this.showList();
			};

			if (document.getElementsByTagName) {
				linksList = tools.linksObj.content.getElementsByTagName('A');
				for (var i = 0; i < linksList.length; i ++) {
					linksList[i].onmouseover = function () {
						document.tools.linksObj.content.showList();
					};
				}
			}

		}

	}

}

if (window.onload) {
	var beforeTopbarToolsFunction = window.onload;
	window.onload = function () {
		beforeTopbarToolsFunction();
		topbarManager();
	};
} else {
	window.onload = topbarManager;
}

