//v1.0.2b
//Copyright 2006-2007 arcadius@onet.pl

//menu constructor
function menu(thisitem,startstate){ 
  callname = "global"+thisitem;
  divname = "subglobal"+thisitem;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
  this.menuitemid = thisitem;
}

//menu methods
function ehandler(event,theobj){
  resetmenu();
  theobj.thediv.style.visibility = "visible";
  theobj.thediv.style.left = menuitemposleft[theobj.menuitemid];
  theobj.thediv.style.top = menuitempostop[theobj.menuitemid];  
  if (menutype == 1) {
	  theobj.caller.style.backgroundColor = menuonbgclr;	  	  
  } else if ((menutype == 2)||(menutype == 3)) {
	  theobj.caller.style.backgroundImage = "url(" + menuonbgimg + ")";
	  theobj.caller.style.borderLeftColor = menuonborderclr;	  
  }
  theobj.caller.style.color = menuontxtclr;
  subnavvisible = 1;
  subnavactive = 1;	
}

function deactivatemenu(event) {
  subnavactive = 0;
}

function activatemenu(event) {
  subnavactive = 1;
}
				
function closesubnav(event){
  if (menumode == 1) {
    if ((event.clientY < menuactiveybegin)||(event.clientY > menuactiveyend)||(event.clientX < menuactivexbegin)||(event.clientX > menuactivexend)){
	  resetmenu();
	}
  } else if (menumode == 2) {
  	if ((subnavvisible == 1)&&(subnavactive == 0)) {
	  resetmenu();
  	}
	setTimeout("closesubnav()", menuTimeout);
  }  
}

function resetmenu(){	
  for (var i=1; i<= numofmenuitems; i++){
	if (menuitemsub[i-1]==1) {
	  var shutdiv = eval('menuitem'+i+'.thediv');
      shutdiv.style.visibility='hidden';
	  subnavvisible = 0;	
	  var shutcall = eval('menuitem'+i+'.caller');
  	  if (menutype == 1) {
	    shutcall.style.backgroundColor = menuoffbgclr;
	    shutcall.style.color = menuofftxtclr;
  	  } else if (menutype == 2) {
	    shutcall.style.backgroundImage = "url(" + menuoffbgimg + ")";
	    shutcall.style.borderLeftColor = menuoffborderclr;
	    shutcall.style.color = menuofftxtclr;
  	  } else if (menutype == 3) {	
	    if (menuitemsel[i-1]==0) {
	  	  shutcall.style.backgroundImage = "url(" + menuoffbgimg + ")";
	  	  shutcall.style.borderLeftColor = menuoffborderclr;
		  shutcall.style.color = menuofftxtclr;
	    } else {
	  	  shutcall.style.backgroundImage = "url(" + menuselbgimg + ")";
	  	  shutcall.style.borderLeftColor = menuselborderclr;		  
		  shutcall.style.color = menuseltxtclr;
	    }
  	  }
	}
  }
}