//----------------------------------------
// NAME OF SCRIPT:  3LMENU v2.0           |
// AUTHOR        :  Carolyn Brown Ray     |
// CREATED       :  January 9, 2006       |
// LAST MODIFIED :  January 24, 2006       |
// FILENAME      :  cbGenerator.js     |
//--------------------------------------------------------------------
//GLOBAL VARIABLES:




var lastItem, nextItem, currentItem;
var displayArray = new Array();
var displayPtr=0;
var lastBg, lastFg;
var currProcess=null;
var liptr=0;
var lastItemArray= new Array();
var currentItem=null;
var currentId=null;
var currentBg=null;
var currentFg=null;
var lastId=null;
var lastBg=null;
var lastFg=null;
var tableId;
var firstHit=false;
function unHighlightParent(id) {
return;
    if (lastMenu != currentItem) {

	unHighlightLast();
    }
}



function checkOut(id) {
   var anArray = new Array(id.split("Menu"));
   var newstr=anArray[0].toString();
   var len=newstr.length;
   lastMenu= newstr.substr(0, len -1);
}
function getLastMenu(id) {
   var anArray = new Array(id.split("Menu"));
   var newstr=anArray[0].toString();
   var len=newstr.length;
   lastMenu= newstr.substr(0, len -1);
}
function setDelay(timer, action) {
	window.clearTimeout(currProcess);
	currProcess=window.setTimeout(action , timer * 1000);
}


function rollBack(id) {
   var j;
   for (j=0; j < lastItemArray.length; j++) {
	var lid=lastItemArray[j].id;
	var bg=lastItemArray[j].bg;
	var fg=lastItemArray[j].fg;
	if (id != lid){
          if (getParent(id) == getParent(lid))
		changeBg(lid, bg, fg); 
        }
   }

}
function hideAll(n) {
    
    //changeBg(lastItem,  lastBg, lastFg);
    for (var j=0; j<displayArray.length; j++) {

	hide(displayArray[j]);
    }
    displayPtr=0;
   for (j=0; j < lastItemArray.length; j++) {
	var id=lastItemArray[j].id;
	var bg=lastItemArray[j].bg;
	var fg=lastItemArray[j].fg;
    //   if (n != "all") {
     //  if (currentItem != lastItemArray[j].id )
//	changeBg(id, bg, fg);
 //      }
   }
   lastItemArray = new Array();
   liptr=0;

//if (n == "all")
//lastItem=undefined;
currentId=null;
}


function hideLast(id) {

	if (displayArray[displayPtr -1] != (id + "Menu")) {
		hide(displayArray[displayPtr -1]);
		
	}
}


function show(id) {
	
	displayArray[displayPtr++]=id;

	
         if(id == null) return;

	  if (currProcess != null)
	  window.clearTimeout(currProcess);
	  windowIsOpen=true;
	  if (document.all) {
 	     if (document.all[id] != null) 
	        document.all[id].style.visibility="visible"; 
	  }else
	  if (document.getElementById) {
 	     if (document.getElementById(id) != null) 
	       document.getElementById(id).style.visibility="visible"; 
	  }
}

function hide(id) {
          windowIsOpen=false;
	  if (document.all) {
 	     if (document.all[id] != null) 
	        document.all[id].style.visibility="hidden"; 
	  }else
	  if (document.getElementById) {
 	     if (document.getElementById(id) != null) 
	       document.getElementById(id).style.visibility="hidden"; 
	  }
}


function hideCheck(parent, id) {
   if (parent != "main" && (parent + "Menu" == tableId)) {
	hide(id + "Menu" ); 
   }
}
function changeBg(id, bg, fg) {


if (document.all) {
   if (document.all[id] == null) return;

   if (bg != null){
      document.all[id].style.background=bg;
	  }
   if (document.all[id + "a"] == null) return;
   if (fg != null){
      document.all[id + "a"].style.background=bg;
      document.all[id + "a"].style.color=fg;
	  }
}else
if (document.getElementById) {
   if (document.getElementById(id) == null) return;
   if (bg != null)
   document.getElementById(id).style.background=bg;

if (document.getElementById(id + "a") == null) return;
   if (fg != null)
   document.getElementById(id + "a").style.color=fg;
   document.getElementById(id + "a").style.background=bg;
   }
}



 function setLastItem(id, bg, fg) {
  return;
	//lastItem=id;
	//lastBg=bg;
	//lastFg=fg;
        //lastItemArray[liptr++]= new lastItemStruct(id, bg, fg);
 }
function setCurrent(id, bg, fg) {
    if (currentId == null) {
	lastId=id;
	lastBg=bg;
	lastFg=fg;
      } 

	currentId=id;
	currentBg=bg;
	currentFg=fg;
        lastItemArray[liptr++]= new lastItemStruct(id, bg, fg);
}
function setLast(id) {
    if (currentId == null) return;
	lastId=currentId;
	lastBg=currentBg;
	lastFg=currentFg;
        if (lastId + "Menu" != tableId && getParent(lastId) != "main") {
          changeBg(lastId, lastBg, lastFg);
        }
	if (id != null) 
        if (tableId == "main") resetMenu();

}


function getCurrent() {
	
        if (currentId == null) return;
        return  currentId;
}
function getLast() {
       if (lastId == null) return null;
//alert(getParent(lastId));
       return lastId;
}

function setTable(id) {
    tableId=id;
}
function getTable() {
    return tableId;
}




function checkHightlight(id) {
  if (id != lastItem) {
	unHighlightLast("");
	}

}

 function unHighlightLast(id) {
	currentItem=id;
        if (lastItem == id) return;
	changeBg(lastItem,  lastBg, lastFg);
 }



function resetMenu(n) {

   if (n == "end" && lastId != null ) {
      var lastTouch=getParent(lastId);
      var colors=getColorHashLine(lastTouch).toString();
      var anArray = colors.toString().split(",");
      var fg=anArray[2].toString();
      var bg=anArray[3].toString();

      if (lastTouch != "main" )   {
        changeBg(lastTouch, bg, fg);
      }
   }
   if ( firstHit || n == "end") {

   changeBg(lastId, lastBg, lastFg);
   rollBack(lastId);
   hideAll();
   }
   firstHit=true;

}

function lastItemStruct(id, bg, fg) {
  this.id=id;
  this.bg=bg;
  this.fg=fg;
}
