//window.onscroll = moveScrollMenus;

var scrollMenus = new Array();

function addScrollMenu(rowHeight,mName,parentMenu,orgLeft,orgTop,orgVisibility,hoverBG,hoverCol,offBG,offCol,tableDec){
	scrollMenus[scrollMenus.length] = new ScrollMenu(rowHeight,mName,parentMenu,orgLeft,orgTop,orgVisibility,hoverBG,hoverCol,offBG,offCol,tableDec);
}

function getScrollMenu(mn){
	for(var i=0;i<scrollMenus.length;i++){
		if(scrollMenus[i].menuName==mn){
			return scrollMenus[i];
		}
	}
	alert("The menu " + mn + " was not found");
	return null;
}	

function addMenuItem(mn,opHTML,clickMeth,subMen){
	getScrollMenu(mn).addMenuItem(opHTML,clickMeth,subMen);
}

function drawScrollMenus(){
	for(var i=0;i<scrollMenus.length;i++){
		scrollMenus[i].drawMenu();
	}
}

function moveScrollMenus(){
	var offsetTop = document.body.scrollTop;
	var offsetLeft = document.body.scrollLeft;
	for(var i=0;i<scrollMenus.length;i++){
		var m = document.getElementById(scrollMenus[i].menuName);
		m.style.left = scrollMenus[i].originalLeft + offsetLeft;
		m.style.top = scrollMenus[i].originalTop + offsetTop;
	}	
}

var visibleMenuCount = 0;

function mouseOverScrollMenu(mn){
	while(mn != ""){
		var m = getScrollMenu(mn);
		m.shouldDisplay = 1;
		document.getElementById(m.menuName).style.visibility = "visible";
		hideOrShowSelects();
		mn = m.parentMenuName;
	}
}

function mouseOffScrollMenu(mn){
	while(mn != ""){
		var m = getScrollMenu(mn);
		m.shouldDisplay = 0;
		setTimeout("hideMenu('" + mn + "')",500);
		mn = m.parentMenuName;
	}
}

function hideMenu(mn){
	var m = getScrollMenu(mn);
	if(m.shouldDisplay==0 && m.originalVisibility=="hidden"){
		document.getElementById(m.menuName).style.visibility = "hidden";
		hideOrShowSelects();
	}
}

function hideOrShowSelects(){
	var show = true;
	for(var i=0;i<scrollMenus.length;i++){
		var currentVisibility = document.getElementById(scrollMenus[i].menuName).style.visibility;
		if(currentVisibility != scrollMenus[i].originalVisibility){
			show = false;
			break;					
		}
	}
	if(show){
		showSelects();
	}else{
		hideSelects();
	}
}

function hideSelects(){
	try{
		for(var i=0;i<10;i++){
			document.getElementById("selectDiv_"+i).style.visibility = "hidden";
		}
	}catch(e){}
}

function showSelects(){
	try{
		for(var i=0;i<10;i++){
			document.getElementById("selectDiv_"+i).style.visibility = "visible";
		}
	}catch(e){}
}

function mouseOverScrollMenuItem(tableData,sm,mn){
	var m = getScrollMenu(mn);
	tableData.style.backgroundColor = m.hoverBackground;
	tableData.style.color = m.hoverColor;
	tableData.style.fontWeight = "bold";
	tableData.style.cursor = 'pointer';
	tableData.style.cursor = 'hand';
	if(sm != ""){
		mouseOverScrollMenu(sm);
	}
}

function mouseOffScrollMenuItem(tableData,sm,mn){
	var m = getScrollMenu(mn);
	tableData.style.backgroundColor = m.offBackground;
	tableData.style.color = m.offColor;
	tableData.style.fontWeight = "normal";
	if(sm != ""){
		mouseOffScrollMenu(sm);
	}
}

function ScrollMenu(rowHeight,mName,parentMenu,orgLeft,orgTop,orgVisibility,hoverBG,hoverCol,offBG,offCol,tableDec){

	this.menuName = mName;
	this.parentMenuName = parentMenu;
	this.menuItems = new Array();
	this.tableDeclaration = tableDec;
	this.originalLeft = orgLeft;
	this.originalTop = orgTop;
	this.originalVisibility = orgVisibility;
	this.shouldDisplay = 0;
	this.rowHeight = rowHeight;
	
	this.hoverBackground = hoverBG;
	this.hoverColor = hoverCol;
	this.offBackground = offBG;
	this.offColor = offCol;
	
	this.addMenuItem = addMenuItem;
	this.drawMenu = drawMenu;
	
	function addMenuItem(opHTML,clickMeth,subMen){
		this.menuItems[this.menuItems.length] = new MenuItem(opHTML,clickMeth,subMen);
	}
	
	function MenuItem(opHTML,clickMeth,subMen){
		this.optionHTML = opHTML;
		this.onclickMethod = clickMeth;
		this.subMenu = subMen;
	}
	
	function drawMenu(){
		html =  "<div id='" + this.menuName + "' style='position:absolute;z-index:150;left:"+this.originalLeft+";top:"+this.originalTop+";visibility:" + this.originalVisibility + ";' onmouseover=\"mouseOverScrollMenu('" + this.menuName + "')\" onmouseout=\"mouseOffScrollMenu('" + this.menuName + "')\">";
		html += this.tableDeclaration;
		var mItems = this.menuItems;
		for(var i=0;i<mItems.length;i++){
			var menuItem = mItems[i];
			html += "<tr height='"+this.rowHeight+"'>";
			html += "<td style='background-color:" + this.offBackground + ";color:" + this.offColor + ";'";
			if(menuItem.onclickMethod!=""){
				html += " onclick=\"" + menuItem.onclickMethod + "\"";
			}
			html += " onmouseover=\"mouseOverScrollMenuItem(this,'" + menuItem.subMenu + "','" + this.menuName + "')\" onmouseout=\"mouseOffScrollMenuItem(this,'" + menuItem.subMenu + "','" + this.menuName + "')\" >";
			html += menuItem.optionHTML;
			html += "</td>";
			html += "</tr>";
		}
		html += "</table>";
		html += "</div>";
		document.write(html);
	}

}