var stayFolded=true;
var menuCnt=0;	// Level 1 menus
var topmenuheight = 24;  // Height of a top menu item
var buf="";

var oTop = new Array();	// Array for top menu items
var oSub = new Array(); // Array for submenu items

// Vars for Navigator type
var ie = (document.all) ? true:false;
var n = !ie;

// Make cross-browser objects
function makeMenu(obj, nest){
		this.css=document.getElementById(obj).style;
		this.ref=document.getElementById(obj);    

        if (obj.indexOf("divTop") != -1)  
           // Height of topmenus
	       this.height=topmenuheight;
        else
	       // Height of submenus
	       this.height=this.ref.offsetHeight+10;

       	this.x=0; 
       	this.y=0; 
        this.hideIt=b_hideIt;   
        this.showIt=b_showIt; 
        this.vis=b_vis; 
        this.moveIt=b_moveIt;  
        
        return this;
}
// Helper functions
function b_showIt(){this.css.visibility="visible"}
function b_hideIt(){this.css.visibility="hidden"}
function b_vis(){if(this.css.visibility=="hidden" || this.css.visibility=="hide") return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x; this.css.top=this.y}


function init(){

  buf += '</DIV></DIV>';
  
  document.writeln(buf);

  for(i=1;i<=menuCnt;i++){
	  oTop[i-1]=new makeMenu('divTop'+i,'divCont');
	  if (oSub[i-1] == 1)
	    // Submenus exist
       oSub[i-1]=new makeMenu('divSub'+i,'divCont.document.divTop'+i);
  }
  
  for(i=1;i<oTop.length;i++){ oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height) }
  for(i=0;i<oTop.length;i++){ oTop[i].showIt() }
  for(i=0;i<oSub.length;i++){ if (oSub[i]!=null) oSub[i].hideIt() }
}

// Show "on" image for menu buttons
function switchOn(imgName) {

    if (document.images) {
      imgOn = eval(imgName + "On.src");
      document [imgName].src = imgOn;
    }
} 

// Show "off" image for menu buttons
function switchOff(imgName) {

    if (document.images) {
      imgOff = eval(imgName + "Off.src");
      document [imgName].src = imgOff;
    }
} 

// Switch between folded and unfolded states
function menu(num){
        if(!stayFolded){
                for(i=0;i<oSub.length;i++){
                        if(i!=num)
                                oSub[i].hideIt();
                }
                for(i=1;i<oTop.length;i++){
                        oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
                }
        }

		if (oSub[num]!=null)
		{
                  if(oSub[num].vis())
                        oSub[num].showIt();
                  else
                        oSub[num].hideIt();
		}

       for(i=1;i<oTop.length;i++){ 
                if(oSub[i-1]!=null && !oSub[i-1].vis()) 
			  oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height+oSub[i-1].height) 
                        else 
			  oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
       }
}

// Add a top menu item
function addParent(imgName, imgoffpath, alttxt, ref, targ)
// targ = target
{
  ++menuCnt;
  
  if (menuCnt == 1)
  {
   buf = "";
   buf += '<DIV ID="divCont">';
  }
  else
  {
   // Close previous parent DIV
   buf += '</DIV>';
 
  }

  buf += '<DIV ID="divTop' + menuCnt +'" CLASS="clTop">';
  buf += '<IMG SRC="'+imgSelOff.src+'" NAME="imgA'+ imgName + '" ALIGN="bottom" VSPACE=9 WIDTH=12 HEIGHT=12 ALT="" border="0">';

  if (ref != "")
  {
    buf += '<A HREF="' + ref + '" TARGET="' + targ + '" onMouseOver="switchOn(\'imgB'+ (menuCnt) + '\')" onMouseOut="switchOff(\'imgB'+ (menuCnt) + '\')" CLASS="clMain">';
  }
  else if (alttxt != "")  // If no alternate text specified, image is just a placeholder
  {
    buf += '<A HREF="javascript:menu(' + (menuCnt - 1) + ')" onMouseOver="switchOn(\'imgB'+ (menuCnt) + '\')" onMouseOut="switchOff(\'imgB'+ (menuCnt) + '\')" CLASS="clMain">';
  }

  buf += '<IMG SRC="' + imgoffpath + '" NAME="imgB'+ (menuCnt) + '" ALT="' + alttxt + '" BORDER="0"></A><BR>';  

}

// Add a submenu item
function addChildren(childArr)
// ChildArr = childName, Text, Ref, Target
{
  var i;
  var j=0;

  buf += '<DIV ID="divSub' + menuCnt +'" CLASS="clSub">';

  for (i=0;i<childArr.length;i+=4)
  {
    j++;

    buf += '<IMG SRC="'+imgSelOff.src+'" NAME="imgA'+ childArr[i] + '" WIDTH=12 HEIGHT=12 ALT="" border="0"> ';
    buf += '<A NAME="xdivSub' + menuCnt + '_'+ j +'" HREF="' + childArr[i+2] + '" TARGET="' + childArr[i+3] + '" CLASS="clSubb">'+ childArr[i+1] +'</A><BR>';
  }

  buf += '</DIV><BR>';

  oSub[menuCnt-1]=1;
}

// Unselect all menu items
function unselectOpt() 
{
	for (i=0;i<parent.gauche.document.images.length;i++)
		if (parent.gauche.document.images[i].name.indexOf("imgA") != -1) 
			parent.gauche.document.images[i].src=imgSelOff.src;		
}


// Select (mark) a specific menu item
function selectOpt(imgName) 
{
	parent.gauche.document.images['imgA'+imgName].src=imgSelOn.src;
}
