var menuLeft = 133;
var menuTop = 26;
var menuHeight = 18;

var domSMenu = null;
var oldDomSMenu = null;
var t = 0; // 1=menu cloesd, 2=menu open
var lDelay = 1; //menu open delay multiplier
var lCount = 0; //how long the menu has waited befor closing
var pause = 0; //miliseconds befor closing menu

var old_menu_num = default_menu_num;

function popMenu(menuNum){
	if (isDHTML) {
///// Sets the previous menu's visibility to hidden
		t = 2;
		if (oldDomSMenu) {

			if( old_menu_num != default_menu_num ) { 
            switch_img('menu' + old_menu_num, 'nav_images[' + old_menu_num + '].out');
            //alert('1 menu' + old_menu_num + ' nav_images[' + old_menu_num + '].out');
         }
         oldDomSMenu.visibility = 'hidden'; 
			oldDomSMenu.zIndex = '0'; 
			t = 2; 
			lCount = 0;

		}

///// Defines the DOMs	of the menu objects
		var idSMenu = 'img' + menuNum;
		var domSMenu = findDOM(idSMenu,1);
      
///// Positions and shows the menu
		if ( (oldDomSMenu != domSMenu) ) {
         
         if( default_menu_num == null || menuNum != default_menu_num) {
            old_menu_num = menuNum;
         }         
         
         domSMenu.left = menuLeft; 
			domSMenu.top = menuTop; // + (menuNum * menuHeight);
			//switch_img('sub_nav_bg', 'nav_images[' + menuNum + '].bg'  );
         switch_img('menu' + menuNum ,'nav_images[' + menuNum + '].over');
         //alert('2 menu' + menuNum + ' nav_images[' + menuNum + '].over');
         domSMenu.visibility = 'visible';
			domSMenu.zIndex = '100';
			oldDomSMenu = domSMenu;
        

		}

///// Resets oldDom if it is the same as the current DOM
		else { 
         //oldDomSMenu = null;
         domSMenu.visibility = 'visible';
         switch_img('menu' + menuNum ,'nav_images[' + menuNum + '].over');
      }
	}

////// Returns a 'null' value for non-DHTML Browsers 
	else { return null; }
}

function hideMenu(on_off) {
   if(on_off == null) { on_off = 1; }
   set_visibility(on_off); 
   delayHide();
   return;
}

function set_visibility(on_off) {
   t = on_off;
   return;
}

function delayHide() {
///// Checks to see if there is a menu showing and whether 
///// the global variable 't' has been set to 0
    if ((oldDomSMenu) && (t == 0)) {

///// Hides the old menu, resets menu conditions, 
///// and stops the function running
        oldDomSMenu.visibility = 'hidden';
        oldDomSMenu.zIndex = '0';
        oldDomSMenu = null;
        lCount = 0; 
         
        if( default_menu_num != null){
           show_default_menu();
        }
        else {
           switch_img('menu' + old_menu_num,'nav_images[' + old_menu_num + '].out');
           //switch_img('sub_nav_bg', 'nav_bg'  );      
        } 
       
         
        return false;
    }

///// Interupts the function if another menu is opened
    if (t == 2) { lCount = 0; return false; }

///// Repeats the function adding 1 to lCount each time until 
///// lCount is equal to lDelay and then sets 't' to 0 so that 
///// the menu will hide when it runs again
    if (t == 1) { 
        lCount = lCount + 1;
        if (lDelay <= lCount) { t = 0; }
        if (lDelay >= lCount) { setTimeout('delayHide(' + t + ')',pause); }
    }
}


function show_default_menu(){

    switch_img('menu' + old_menu_num,'nav_images[' + old_menu_num + '].out');
    //switch_img('sub_nav_bg', 'nav_images[' + default_menu_num + '].bg'  );
    
    popMenu(default_menu_num);
    //if(old_menu_num != default_menu_num) {}
    
    
    return;
}
