//popmenu controls menu and hoverbox objects

var domSMenu = null; 	//menu object
var oldDomSMenu = null; //old menu object
var domSubMenu=null; 	//sub menu object
var oldDomSubMenu=null; //old sub menu object
var domSubSubMenu=null; 	//sub menu object
var oldDomSubSubMenu=null; //old sub menu object
var status = 0;		//0. click (hide immediately) 
			//1.roll-off (delay hide) 
			//2.interrupt hide
var subStatus = 0;	//0. click 1.roll-off 2.interrupt-hide 
var subSubStatus=0;	//0. click 1.roll-off 2.interrupt-hide 
var ts = 0;		//sub menu rolover/click status
var MAX_CALL_COUNT = 6; //max number of recursive calls to produce 
				//setTimeout() delay in delayHide()
var callCount = 0;	//counts recursive calls of delayHide()
var callSubCount = 0;	//counts recursive calls of delayHideSub()
var callSubSubCount = 0;//counts recursive calls of delayHideSubSub()
var pause = 250;	//m. sec delay of setTimeout() in delayHide
var menuLeft = 0;	//left position of domMenu	
var menuTop = 0;	//top position of domMenu
var subMenuTop = 0;	//top position of domSubMenu
var subSubMenuTop = 0;	//top position of domSubSubMenu

/*findDOM shortens typing of the getElementById layer reference*/

function findDOM(objectID,styl)
{
   //not a style object
   if(styl==0)
   {
      return (document.getElementById(objectID));
   }
   else
   {
      return (document.getElementById(objectID).style);
   }
}//end findDOM

/////////////////

   /*
     popMenu:
     1. sets the previous menu's visibility to hidden 
     2. moves it to bottom layer
     3. sets new menu's visibility to visible
     4. moves it to top layer
   */
   
function popMenu(menuNum)
{
   status = 2;//menu roll-over
   
   //hide old menu if necessary
   if (oldDomSMenu) 
	{
	oldDomSMenu.visibility = 'hidden';
	oldDomSMenu.zIndex = '0';
	oldDomSMenu = null;
	status = 2;
	callCount = 0;
	}
   //hide old sub menu if necessary
	if (oldDomSubMenu) 
	{
	 oldDomSubMenu.visibility = 'hidden';
	 oldDomSubMenu.zIndex = '0';
	 oldDomSubMenu = null;
	 subStatus = 2;
	 callSubCount = 0;
	}
  
  //Defines the names of the menu objects
   
   var idMenu = 'menuHead';
   var domMenu = findDOM(idMenu,0);//get menu object

   var idMenuOpt = 'menuHead' + menuNum;
   var domMenuOpt = findDOM(idMenuOpt,0);//get menu object

   var idSMenu = 'menu' + menuNum;
   var domSMenu = findDOM(idSMenu,1);//get menu object.style

   /*Defines the position of the menu options layer*/
   menuLeft = (domMenu.offsetLeft) + (domMenuOpt.offsetLeft) + 1;
   menuTop = (domMenu.offsetTop) + (domMenu.offsetHeight);

   /*Positions and shows the menu*/
   //if requested menu is different than
   if (oldDomSMenu != domSMenu)
   {
      domSMenu.left = menuLeft;
      domSMenu.top = menuTop;
      domSMenu.visibility = 'visible';
      domSMenu.zIndex = '200';
      oldDomSMenu = domSMenu;
      //popSub(menuLeft+136, menuTop);
   }

   /*Resets oldDom if it is the same as the current DOM*/
   else { oldDomSMenu = null; }
}//end popMenu

   /*
     popMenu:
     1. sets the previous menu's visibility to hidden 
     2. moves it to bottom layer
     3. sets new menu's visibility to visible
     4. moves it to top layer
   */
   
function popMenu2(menuNum)
{
   status = 2;//menu roll-over
   
   //hide old menu if necessary
   if (oldDomSMenu) 
	{
	oldDomSMenu.visibility = 'hidden';
	oldDomSMenu.zIndex = '0';
	oldDomSMenu = null;
	status = 2;
	callCount = 0;
	}
   //hide old sub menu if necessary
	if (oldDomSubMenu) 
	{
	 oldDomSubMenu.visibility = 'hidden';
	 oldDomSubMenu.zIndex = '0';
	 oldDomSubMenu = null;
	 subStatus = 2;
	 callSubCount = 0;
	}
  
  //Defines the names of the menu objects
   
   var idMenu = 'menuHead_';
   var domMenu = findDOM(idMenu,0);//get menu object

   var idMenuOpt = 'menuHead_' + menuNum;
   var domMenuOpt = findDOM(idMenuOpt,0);//get menu object

   var idSMenu = 'menu' + menuNum;
   var domSMenu = findDOM(idSMenu,1);//get menu object.style

   /*Defines the position of the menu options layer*/
   menuLeft = (domMenu.offsetLeft) + (domMenuOpt.offsetLeft) + 1;
   menuTop = (domMenu.offsetTop) + (domMenu.offsetHeight);

   /*Positions and shows the menu*/
   //if requested menu is different than
   if (oldDomSMenu != domSMenu)
   {
      domSMenu.left = menuLeft;
      domSMenu.top = menuTop;
      domSMenu.visibility = 'visible';
      domSMenu.zIndex = '200';
      oldDomSMenu = domSMenu;
      //popSub(menuLeft+136, menuTop);
   }

   /*Resets oldDom if it is the same as the current DOM*/
   else { oldDomSMenu = null; }
}//end popMenu2

/////////////////

   /*
     popSubMenu:
     1. sets the previous sub menu's visibility to hidden 
     2. moves it to bottom layer
     3. sets new sub menu's visibility to visible
     4. moves it to top layer
   */
   
function popSubMenu(menuNum, subLeft, top)
{
   subStatus = 2;//sub menu roll-over
   
   //hide old sub menu if necessary
   if (oldDomSubMenu) 
   {
      oldDomSubMenu.visibility = 'hidden';
      oldDomSubMenu.zIndex = '0';
      oldDomSubMenu = null;
      subStatus = 2;
      callSubCount = 0;
   }
  
  //Defines the names of the sub menu objects
//alert(menuNum);
   var idSubMenu = 'subMenu3_' + menuNum;
   domSubMenu = findDOM(idSubMenu,1);//get menu object

   //Defines the position of the menu options layer
   subMenuTop = 26 + top;

   //Positions and shows the menu
   //if requested menu is different than old
   if (oldDomSubMenu != domSubMenu)
	
   {

      domSubMenu.left = subLeft;
      domSubMenu.top = subMenuTop;
      domSubMenu.visibility = 'visible';
      domSubMenu.zIndex = '202';
      oldDomSubMenu = domSubMenu;
   }
  //Resets oldDom if it is the same as the current DOM
   else 
   { 
      oldDomSubMenu = null; 
   }

}//end popSubMenu


////////////////////


   /*
     popSubSubMenu:
     1. sets the previous sub sub menu's visibility to hidden 
     2. moves it to bottom layer
     3. sets new subSub menu's visibility to visible
     4. moves it to top layer
   */
   
function popSubSubMenu(menuNum, subLeft, top)
{
   subSubStatus = 2;//subSub menu roll-over
   
   //hide old subSub menu if necessary
   if (oldDomSubSubMenu) 
   {
      oldDomSubSubMenu.visibility = 'hidden';
      oldDomSubSubMenu.zIndex = '0';
      oldDomSubSubMenu = null;
      subSubStatus = 2;
      callSubSubCount = 0;
   }
  
  //Defines the names of the sub menu objects
//alert(menuNum);
   var idSubMenu = 'subMenu3_' + menuNum;
   domSubSubMenu = findDOM(idSubMenu,1);//get menu object

   //Defines the position of the menu options layer
   subSubMenuTop = 26 + top;

   //Positions and shows the menu
   //if requested menu is different than old
   if (oldDomSubSubMenu != domSubSubMenu)
	
   {

      domSubSubMenu.left = subLeft;
      domSubSubMenu.top = subSubMenuTop;
      domSubSubMenu.visibility = 'visible';
      domSubSubMenu.zIndex = '205';
      oldDomSubSubMenu = domSubSubMenu;
   }
  //Resets oldDom if it is the same as the current DOM
   else 
   { 
      oldDomSubSubMenu = null; 
   }

}//end popSubSubMenu


////////////////////


/*
   delayHide:
   1. delayHide is called at menu link roll-off (status 1)
   2. immediate hide (status 0 & delayHide called) occurs 
      at menu link click
   3. break out of delayHide() if status 2, another roll-over 
      occurs (popMenu sets status 2)
   4. if status is 1, recursively call delayHide until 
      callCount = MAX_CALL_COUNT
*/
 
function delayHide()
{
 /*
   if-block description:
   1. Hides the old menu
   2. resets menu conditions,
   3. stops the function's running on click or another roll-over
 */
    if ((oldDomSMenu) && (status == 0))
    {
        oldDomSMenu.visibility = 'hidden';
        oldDomSMenu.zIndex = '0';
        oldDomSMenu = null;
        callCount = 0;
        return false;
    }

   //Interupts the function if another menu is opened
    if (status == 2)
    {
      callCount = 0; return false;
    }

      /*
      1. Repeats the function adding 1 to callCount each time until
      	 callCount is equal to lDelay 
      2. sets 'status' to 0 so that
         the menu will hide when it runs again
      */
    if (status == 1)// roll off link
    {
        callCount = callCount + 1;
        if (MAX_CALL_COUNT <= callCount) 
        { 
        	status = 0; 
        }
        
        //recursive call of delayHide() (self)
        if (MAX_CALL_COUNT >= callCount) 
        { 
        	setTimeout('delayHide(' + status + ')',pause);//pause=300 
        }
    }
}//end delayHide

//////////////////

function delayHideSub()
{
 /*
   delayHideSub:
   if-block description:
   1. Hides the old sub menu
   2. resets sub menu conditions,
   3. stops the function's running on click or another roll-over
 */
    if ((oldDomSubMenu) && (subStatus == 0))
    {
        oldDomSubMenu.visibility = 'hidden';
        oldDomSubMenu.zIndex = '0';
        oldDomSubMenu = null;
        callSubCount = 0;
        return false;
    }

   //Interupts the function if another menu is opened
    if (subStatus == 2)
    {
      callSubCount = 0; return false;
    }

      /*
      1. Repeats the function adding 1 to callCount each time until
      	 callCount is equal to lDelay 
      2. sets 'subStatus' to 0 so that
         the menu will hide when it runs again
      */
    if (subStatus == 1)// roll off link
    {
        callSubCount = callSubCount + 1;
        if (MAX_CALL_COUNT <= callSubCount) 
        { 
        	subStatus = 0;
        }
        
        //recursive call of delayHideSub() (self)
        if (MAX_CALL_COUNT >= callSubCount) 
        { 
           setTimeout('delayHideSub(' + subStatus + ')',pause);//pause=250 
        }
    }
}//end delayHideSub

///////////////////////

function delayHideSubSub()
{
 /*
   delayHideSubSub:
   if-block description:
   1. Hides the old subSub menu
   2. resets subSub menu conditions,
   3. stops the function's running on click or another roll-over
 */
    if ((oldDomSubSubMenu) && (subSubStatus == 0))
    {
        oldDomSubSubMenu.visibility = 'hidden';
        oldDomSubSubMenu.zIndex = '0';
        oldDomSubSubMenu = null;
        callSubSubCount = 0;
        return false;
    }

   //Interupts the function if another menu is opened
    if (subSubStatus == 2)
    {
      callSubSubCount = 0; return false;
    }

      /*
      1. Repeats the function adding 1 to callSubSubCount each time until
      	 callCount is equal to lDelay 
      2. sets 'subSubStatus' to 0 so that
         the menu will hide when it runs again
      */
    if (subSubStatus == 1)// roll off link
    {
        callSubSubCount = callSubSubCount + 1;
        if (MAX_CALL_COUNT <= callSubSubCount) 
        { 
        	subSubStatus = 0;
        }
        
        //recursive call of delayHideSubSub() (self)
        if (MAX_CALL_COUNT >= callSubSubCount) 
        { 
           setTimeout('delayHideSubSub(' + subSubStatus + ')',pause);//pause=250 
        }
    }
}//end delayHideSubSub

///////////////////////

function popDialog(layerName, diaLeft, diaTop)
{
	var popDlg = findDOM(layerName,1);
	popDlg.left=diaLeft;
	popDlg.top=diaTop;
	popDlg.zIndex = '98';
	popDlg.visibility="visible";
}//end popDialog

//////////////

function dialogHide(layerName)
{
	var popDlg=findDOM(layerName,1);
	popDlg.visibility="hidden";
}//end dialogHide

//////////////

