
loaded = 0; winx = screen.width/2 - 150; winy = screen.height/2 - 150;

ua   = navigator.userAgent.toLowerCase();
ie6  = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
nnf  = (ua.indexOf("netscape")  != -1 && ua.indexOf("gecko") != -1);
nni  = (ua.indexOf("netscape")  != -1 && ua.indexOf("msie") != -1);
nn6  = (ua.indexOf("netscape")  != -1);
gek  = (ua.indexOf("gecko")     != -1);
ff1  = (ua.indexOf("firefox")   != -1);
opr  = (ua.indexOf("opera")     != -1);
mac  = (ua.indexOf("mac")       != -1);
web  = (ua.indexOf("webtv")     != -1);
saf  = (ua.indexOf("safari")    != -1);
kon  = (ua.indexOf("konqueror") != -1);
nn4  = (document.layers);

function err(mess){
	if(!loaded){ mess = 'Page has not completely loaded, you may need to reload the page'; }
	alert(mess); 
}

function dWin(url, nme){
	dedicatedWin = window.nme;
	
	if(dedicatedWin){
		if(dedicatedWin.closed){
			dedicatedWin = window.open(url, nme, "top=60,left=" + ((screen.availWidth/2) - (390 / 2)) + ",width=780,height=500,resizable=1,toolbar=0,scrollbars=1,location=0,status=1,menubar=0");
			dedicatedWin.focus();
		} else { 
			dedicatedWin.location = url;
			dedicatedWin.focus();
		}
	} else {
		dedicatedWin = window.open(url, nme, "top=60,left=" + ((screen.availWidth/2) - (390 / 2)) + ",width=780,height=500,resizable=1,toolbar=0,scrollbars=1,location=0,status=1,menubar=0");
		dedicatedWin.focus();
	}
}

function showTT(t, event){
	if(document.getElementById("tt")){
		ttScT   = parseInt(document.body.scrollTop, 10);
		if(ie6){
			ttX = event.clientX; ttY = event.clientY + 5 + ttScT;
		} else {
			ttX = event.pageX; ttY = event.pageY + 5;
		}
		document.getElementById("tt").style.top = ttY;
		document.getElementById("tt").style.left = ttX + 10;
		document.getElementById("tt").innerHTML = t;
		document.getElementById("tt").style.visibility = "visible";
	}
}

function hideTT(){
	if(document.getElementById("tt")){
		document.getElementById("tt").style.visibility = "hidden";
	}
}

// start menu code

var activeButton = null;

if(ie6) document.onmouseover = pageMousedown;
else document.addEventListener("mouseover", pageMousedown, true);

function pageMousedown(event){
	var el;
	
	if(activeButton == null) return;
	
	if(ie6) el = window.event.srcElement;
	else el = (event.target.tagName ? event.target : event.target.parentNode);
	
	if(el == activeButton) return;
	
	if(getContainerWith(el, "DIV", "menu") == null){
		resetButton(activeButton);
		activeButton = null;
	}
}

function buttonClick(event, menuId){
	var button;
	
	if(!loaded){return}
	
	if(ie6)button = window.event.srcElement;
	else button = event.currentTarget;
	
	button.blur();
	
	// this will keep menu open even after leaving then returning
	if(button == activeButton){
		return;
	}
	
	if(button.menu == null){
		button.menu = document.getElementById(menuId);
		if(button.menu.isInitialized == null) menuInit(button.menu);
	}
	
	if(activeButton != null) resetButton(activeButton);
	
	if(button != activeButton){
		depressButton(button);
		activeButton = button;
	} else {
		activeButton = null;
	}
	
	return false;
}

function buttonMouseover(event, menuId){
	var button;
	
	if(!loaded){return}
	
	if(ie6) button = window.event.srcElement;
	else button = event.currentTarget;
	
	if(activeButton != null && activeButton != button) buttonClick(event, menuId);
}
	
function depressButton(button){
	var x, y;
	
	button.className += " menuButtonActive";
	
	x = getPageOffsetLeft(button);
	y = getPageOffsetTop(button) + button.offsetHeight;
	
	if(ie6){
		x += button.offsetParent.clientLeft;
		y += button.offsetParent.clientTop;
	}
	
	button.menu.style.left = x - 2 + "px";
	button.menu.style.top  = y - 1 + "px";
	button.menu.style.visibility = "visible";
}

function resetButton(button){
	removeClassName(button, "menuButtonActive");
	
	if(button.menu != null){
		closeSubMenu(button.menu);
		button.menu.style.visibility = "hidden";
	}
}

function menuMouseover(event){
var menu;

	if(ie6) menu = getContainerWith(window.event.srcElement, "DIV", "menu");
	else menu = event.currentTarget;
	
	if(menu.activeItem != null) closeSubMenu(menu);
}

function menuItemMouseover(event, menuId){
	var item, menu, x, y;
	
	if(ie6) item = getContainerWith(window.event.srcElement, "A", "menuItem");
	else item = event.currentTarget;
	
	menu = getContainerWith(item, "DIV", "menu");
	
	if(menu.activeItem != null) closeSubMenu(menu);

	menu.activeItem = item;
	
	item.className += " menuItemHighlight";
	
	if(item.subMenu == null){
		item.subMenu = document.getElementById(menuId);
		if(item.subMenu.isInitialized == null) menuInit(item.subMenu);
	}
	
	x = getPageOffsetLeft(item) + item.offsetWidth;
	y = getPageOffsetTop(item);
	
	var maxX, maxY;
	
	if(ie6){
		maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) + (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
	maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
	}

	if(opr){
		maxX = document.documentElement.scrollLeft + window.innerWidth;
		maxY = document.documentElement.scrollTop  + window.innerHeight;
	}

	if(gek){
		maxX = window.scrollX + window.innerWidth;
		maxY = window.scrollY + window.innerHeight;
	}

	maxX -= item.subMenu.offsetWidth;
	maxY -= item.subMenu.offsetHeight;
	
	if(x > maxX) x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth + (menu.offsetWidth - item.offsetWidth));
	y = Math.max(0, Math.min(y, maxY));
	
	item.subMenu.style.left = x + "px";
	item.subMenu.style.top  = y + "px";
	item.subMenu.style.visibility = "visible";
	
	if(ie6) window.event.cancelBubble = true;
	else event.stopPropagation();
}

function closeSubMenu(menu){
	if(menu == null || menu.activeItem == null) return;
	
	if(menu.activeItem.subMenu != null){
		closeSubMenu(menu.activeItem.subMenu);
		menu.activeItem.subMenu.style.visibility = "hidden";
		menu.activeItem.subMenu = null;
	}
	
	removeClassName(menu.activeItem, "menuItemHighlight");
	menu.activeItem = null;
}

function menuInit(menu){
	var itemList, spanList;
	var textEl, arrowEl;
	var itemWidth;
	var w, dw;
	var i, j;
	
	if(ie6){
		menu.style.lineHeight = "2.5ex";
		spanList = menu.getElementsByTagName("SPAN");
	
		for(i = 0; i < spanList.length; i++){
			if(hasClassName(spanList[i], "menuItemArrow")){
			spanList[i].style.fontFamily = "Webdings";
			spanList[i].firstChild.nodeValue = "4";
			}
		}
	}

	itemList = menu.getElementsByTagName("A");
	
	if(itemList.length > 0) itemWidth = itemList[0].offsetWidth;
	else return;
	
	for(i = 0; i < itemList.length; i++){
		spanList = itemList[i].getElementsByTagName("SPAN");
		textEl  = null;
		arrowEl = null;
		
		for(j = 0; j < spanList.length; j++){
			if(hasClassName(spanList[j], "menuItemText")){
				textEl = spanList[j];
			}
	
			if(hasClassName(spanList[j], "menuItemArrow") || hasClassName(spanList[j], "menuItemRight")){
				arrowEl = spanList[j];
			}
		}
		
		if(textEl != null && arrowEl != null){
			textEl.style.paddingRight = (itemWidth - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
	
			if(opr){
				arrowEl.style.marginRight = "0px";
			}
		}
	}
	
	if(ie6){
		w = itemList[0].offsetWidth;
		itemList[0].style.width = w + "px";
		dw = itemList[0].offsetWidth - w;
		w -= dw;
		itemList[0].style.width = w + "px";
	}
	
	menu.isInitialized = true;
}

function getContainerWith(node, tagName, className){
	while (node != null){
		if(node.tagName != null && node.tagName == tagName && hasClassName(node, className)) return node;
		node = node.parentNode;
	}
	return node;
}

function hasClassName(el, name){
	var i, list;
	
	list = el.className.split(" ");
	for(i = 0; i < list.length; i++) if(list[i] == name) return true;
	
	return false;
}

function removeClassName(el, name){
	var i, curList, newList;
	
	if(el.className == null) return;
	
	newList = new Array();
	curList = el.className.split(" ");
	
	for(i = 0; i < curList.length; i++) if(curList[i] != name) newList.push(curList[i]);
	
	el.className = newList.join(" ");
}

function getPageOffsetLeft(el){
	var x;
	
	x = el.offsetLeft;
	if(el.offsetParent != null) x += getPageOffsetLeft(el.offsetParent);
	
	return x;
}

function getPageOffsetTop(el){
	var y;
	
	y = el.offsetTop;
	if(el.offsetParent != null) y += getPageOffsetTop(el.offsetParent);
	
	return y;
}

// end menu code
