function menu(section) {
//   _write_main_button(); // old function, used to test in pre-perl dev
//   _write_sub_menu(section); // old function, used to test in pre-perl dev
   var myself = new layerobj("RelatedButton");
   myself.submenu = new layerobj(section);
   myself.showchild = _showchild;
   myself.hidechild = _hidechild;
   myself.togglechild = _togglechild;
   myself.update = _update_position;
   return myself;
}

function _update_position() {
//   if(this.bwis.ie4) {
      this.relocate(10,0);
      _relocate_child(this);
//   } else {
//      var width = width + this.scrollWidth;
//      var height = height + this.scrollHeight;
//      this.relocate(10+width, height);
//      _relocate_child(this);
//   }
}

function _write_sub_menu(section) {
   var browser = new checkBrowser();
   if (browser.ns4) {
      document.write('<layer name="' + section + '">THIS <BR>IS <BR>THE <BR>SUBMENU</layer>');
   } else {
      document.write('<DIV ID="' + section + '" STYLE="POSITION: absolute; Z-INDEX: 20; VISIBILITY: hidden; TOP: 0px; LEFT: 0px;" onMouseOut="menulayer.hidechild();">');
      document.write('THIS <BR>IS <BR>THE <BR>SUBMENU');
      document.write('</div>');
   }
}

function _showchild() {
   _relocate_child(this);
   this.submenu.on();
   return false;
}

function _relocate_child(child) {
   var width = 10;
   var height = 60;
//   if (child.bwis.ie4) {
//      width = width + child.submenu._layer.scrollWidth;
//      height = height + child.submenu._layer.scrollHeight;
//   }
   child.submenu.relocate(width,height);
}


function _hidechild() {
   this.submenu.off();
   return false;
}

function _togglechild() {
   if(debug){alert("toggling child...");}
   if (this.bwis.ns4) {
      if(debug){alert("NS reports that the layer is " + this.submenu._layer.visibility);}
      if(this.submenu._layer.visibility == "show") {
         this.hidechild();
      } else {
         this.showchild();
      }
   } else {
      if(debug){alert("IE reports that the layer is " + this.submenu._layer.style.visibility);}
      if(this.submenu._layer.style.visibility == "visible") {
         this.hidechild();
      } else {
         this.showchild();
      }
   }
   return false;
}

function _write_main_button() {
   var browser = new checkBrowser();
   if (browser.ns4) {
      document.write('<layer name="RelatedButton" visibility="hidden">');
      document.write('<a href="javascript:return false" onClick="return menulayer.togglechild();" onBlur="return menulayer.hidechild();"><img src="images/b_hotlinks.gif" border="0"></a>');
      document.write('</layer>');
   } else {
      document.write('<DIV ID="RelatedButton" STYLE="POSITION: absolute; Z-INDEX: 20; VISIBILITY: hidden; TOP: 0px; LEFT: 0px;">');
      document.write('<a href="javascript:return false" onClick="return menulayer.togglechild();" onBlur="return menulayer.hidechild();"><img src="images/b_hotlinks.gif" border="0"></a>');
      document.write('</div>');
   }
}


function checkBrowser(){
   // borrowed from thomas bratta (bratta.com)
   // in the cool menus script
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
}
