var timer;
var curMenu=null;
function Menus(){
 this.menus = new Array();
}
Menus.prototype.addMenu=function(objMenu){
 this.menus[this.menus.length]=objMenu;
}
Menus.prototype.display=function(containerid){
 var objContainer = document.getElementById(containerid);
 var menuWidth = 680 / (this.menus.length-1);
 for(var i=0;i<this.menus.length;i++)
 {
  objContainer.appendChild(this.menus[i].div);
  objContainer.appendChild(this.menus[i].menudivcontainer);
  if(menuWidth > 154){
	//just default to 154
	menuWidth=154;
  }
  //this.menus[i].iframemask.style.left=(menuWidth * i);
  this.menus[i].menudivcontainer.style.left=(menuWidth * i);
  if(document.all){
  	//this.menus[i].iframemask.style.top=24;
	this.menus[i].menudivcontainer.style.top=0;
  }else{
  	//this.menus[i].iframemask.style.top=14;
	this.menus[i].menudivcontainer.style.top=0;
  }
 // objContainer.appendChild(this.menus[i].iframemask);
  if(this.menus[i].button.value=='Logout' || this.menus[i].button.value=='Login'){
  	this.menus[i].button.style.width=60;
	this.menus[i].div.style.position = 'absolute';
	this.menus[i].div.style.left=680;
	//set the focus to the login button
	this.menus[i].button.focus();
  }else{
  	this.menus[i].button.style.width=menuWidth;
  }
 }
}
function Menu(id,text,onclickcode,width){
 this.menuitems = new Array();
 this.id = id;
 this.div = document.createElement('div');
 this.div.id = 'menucontainer'+id;
 this.div.container = this;
 this.div.className = 'mainmenus';
 this.div.style.position = 'relative';
 this.div.style.zIndex = 1002;
 this.menudivcontainer = document.createElement('div');
 this.menudivcontainer.id = 'menudivcontainer'+id;
 this.menudivcontainer.container = this;
 this.menudivcontainer.style.width = 150;
 this.menudivcontainer.className = 'mainmenus';
 this.menudivcontainer.style.position = 'absolute';
 this.menudivcontainer.style.zIndex = 1002;
 //iframe mask
 //this.iframemask = document.createElement('iframe');
 //this.iframemask.style.position = 'absolute';
 //this.iframemask.id = 'iframemask'+id;
 //this.iframemask.container = this;
 //this.iframemask.style.width = 150;
 //this.iframemask.style.zIndex = 1001;
 //this.iframemask.style.frameborder = 0;
 //this.iframemask.style.display = 'none';
 this.menudiv = document.createElement('div');
 this.menudiv.id = 'menuitemcontainer'+id;
 this.menudiv.container = this.menudivcontainer;
 this.menudiv.style.display = 'none';
 this.menudiv.className = 'mainmenuitemscontainer';
 this.menudiv.style.position = 'absolute';
 this.menudiv.style.top = 24;
 this.menudiv.style.left = 0;
 this.menudiv.style.zIndex = 1003;
 this.button = document.createElement('input');
 this.button.container = this.div;
 this.button.type = 'button';
 this.button.id = 'menubutton'+id;
 this.button.className = 'menubuttons';
 if(onclickcode!=''){
 	this.button.onclick = function(){
		window.location.href=onclickcode;
 	}
 }
 this.button.value = text;
 this.button.style.width = width;
 this.button.onmouseover = function(){
 	var objDiv = document.getElementById('menuitemcontainer'+this.container.container.id);
	//var objIFrameMask = document.getElementById('iframemask'+objDiv.container.container.id);
	this.className='menubuttonshover';
	if(objDiv.childNodes.length > 0){
	objDiv.style.display = 'block';
	//objIFrameMask.style.display = 'block';
	if(curMenu!=null){
	if(objDiv.id!=curMenu.id)
	{
		HideMenu(curMenu);
	}
	}
	curMenu = objDiv;
  	clearTimeout(timer);
	}
  	return true;
 }
 this.menudiv.onmouseover = function(){
 	var objDiv = document.getElementById('menuitemcontainer'+this.container.container.id);
	//var objIFrameMask = document.getElementById('iframemask'+objDiv.container.container.id);
	objDiv.style.display = 'block';
	//objIFrameMask.style.display = 'block';
	if(curMenu!='undefined'){
	if(curMenu!=null){
	if(objDiv.id!=curMenu.id)
	{
		HideMenu(curMenu);
	}
	}
	}
	curMenu = objDiv;
  	clearTimeout(timer);
  	return true;
 }
 this.button.onmouseout = function(){
  	timer = setTimeout('HideMenu('+'menuitemcontainer'+this.container.container.id+');',100);
	this.className='menubuttons';
  	return true;
 }
 this.menudiv.onmouseout = function(){
  	timer = setTimeout('HideMenu('+'menuitemcontainer'+this.container.container.id+');',100);
  	return true;
 }	
 this.div.appendChild(this.button);
 this.menudivcontainer.appendChild(this.menudiv);
}
Menu.prototype.addMenuItem=function(objMenuItem){
 objMenuItem.container = this.menudiv;
 this.menuitems[this.menuitems.length]=objMenuItem;
 this.menudiv.appendChild(objMenuItem.div);
}
Menu.prototype.adjustHeight=function(newHeight){
	if(this.iframemask){
	var height = this.iframemask.style.height;
	if(height==''){
		height=0;
	}else{
		height=parseInt(height);
	}		
	this.iframemask.style.height=height + 17;
	}
}
function MenuItem(id,link,linktext){
 this.id=id;
 this.div = document.createElement('div');
 this.div.id = 'menuitem'+id;
 this.div.container = this;
 this.div.style.display = 'block';
 this.div.className = 'menuitem';
 this.div.style.width = 150;
 this.div.onmouseover = function(){
	this.style.cursor='pointer';
	this.className = 'menuitemhover';
	this.container.link.className = 'menulinkhover';
	return true;
 }
 this.div.onmouseout = function(){
	//this.container.link.style.fontWeight = 'normal';
	this.className = 'menuitem';
	this.container.link.className = 'menulink';
	return true;
 }
 this.div.onclick = function(){
	window.location.href = this.container.link.href;
 }
 this.link = document.createElement('a');
 if(link.indexOf("www.") > -1 || link.indexOf("http://") > -1){
	this.link.setAttribute('href',"#");
	this.link.onclick = function(){
		window.open(link,"mywindow","menubar=1,resizable=1,scrollbars=1,status=1,location=1,width=640,height=480");
	}
 }else{
	this.link.setAttribute('href',link);
 }
 this.link.className = 'menulink';
 linktext = linktext.replace('\\','');
 linktext = linktext.replace('\\','');
 this.link.appendChild(document.createTextNode(linktext));
 this.link.id = 'menuitemlink'+id;
 this.div.appendChild(this.link);
}
function HideMenu(objDiv){
 //var objIFrameMask = document.getElementById('iframemask'+objDiv.container.container.id);
 //objIFrameMask.style.display='none';
 objDiv.style.display='none';
}
//below is used for any menu links that need to load in new window
function newWindow(url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

