/**
 * Need to comment this, too
 */
var tabdropdown={
   //Delay, in milliseconds, before menu disappears after mouseout
   disappeardelay: 500,

   //Disable menu item with dropdown on click
   disablemenuclick: true,

   //Image to place in left-hand corner of drop-down menu items
   downsymbol: '<img src="script/images/dropindicate.gif" style="border: 0; padding-left: 5px" />', //HTML "symbol" to use to indicate this is a dropdown menu item. Enter ('') to disable.

   //
   dropmenuobj: null,

   //
   ie: document.all,

   //
   firefox: document.getElementById&&!document.all,

   //
   previousmenuitem: null,

   /**
    * Function:   getposOffset(what, offsettype)
    * Purpose:
    */
   getposOffset:function(what, offsettype) {
      var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
      var parentEl=what.offsetParent;
      while (parentEl!=null){
         totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
         parentEl=parentEl.offsetParent;
      }
      return totaloffset;
   },

   showhide:function(obj, e, obj2) { //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
      if (this.ie || this.firefox)
         this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
      if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
         if (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
            obj2.parentNode.className="selected"
         obj.visibility="visible"
      }
      else if (e.type=="click")
         obj.visibility="hidden"
   },

   iecompattest:function(){
      return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
   },

   clearbrowseredge:function(obj, whichedge){
      var edgeoffset=0
      if (whichedge=="rightedge"){
         var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
         this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
         if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
            edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
      } else {
         var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
         var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
         this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
         if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
            edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
            if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
               edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
         }
         this.dropmenuobj.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
      }
      return edgeoffset
   },

   togglehiddenobj:function(obj2, visible){
      var revvalue=obj2.getAttribute("rev")
      if (typeof revvalue=="string" && revvalue.length>0 && document.getElementById(revvalue)!=null)
         document.getElementById(revvalue).style.visibility=visible
   },

   contains_firefox:function(a, b) {
      while (b.parentNode)
         if ((b = b.parentNode) == a)
            return true;
      return false;
   },

   dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
      var evtobj=window.event? window.event : e
      if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
         this.delayhidemenu(obj2)
      else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
         this.delayhidemenu(obj2)
   },

   delayhidemenu:function(obj2){
      this.delayhide=setTimeout(function() {
         tabdropdown.dropmenuobj.style.visibility='hidden';
         if (obj2.parentNode.className.indexOf('default')==-1)
            obj2.parentNode.className='';
         tabdropdown.togglehiddenobj(obj2, 'visible')
      },
      this.disappeardelay) //hide menu
   },

   clearhidemenu:function(){
      if (this.delayhide!="undefined")
         clearTimeout(this.delayhide)
   },

   /**
    * Function:   initializetabmenu(menuid, selecteditem)
    *
    * Purpose:    Initialized the tabbed menu for the given menuid, making
    *          the default selection 'selecteitem' if provided. Otherwise
    *          this defaults to the first element in the tabbed menu.
    */
   initializetabmenu:function(menuid, opt_selectedmenuitem) {
      //Get menu items within the menu div section. These are list items
      var menuitems=document.getElementById(menuid).getElementsByTagName("a");

      //Iterate over list items
      for(var i=0; i<menuitems.length; i++){
         //See if the current item is to be the default
         if (parseInt(opt_selectedmenuitem)==i)
            menuitems[i].parentNode.className+=" selected default"

         //See if the menu has a rel attribute
         if(menuitems[i].getAttribute("rel")) {
            //Retrieve the value of the rel attribute (forward ref)
            var relvalue = menuitems[i].getAttribute("rel")

            //Create function for on mouseover for this menu item
            menuitems[i].onmouseover = function(e) {
               //Create event for mouseover
               var event = (typeof e != "undefined") ? e : window.event

               //On mouse over, call dropit, passing this pointer, event,
               // and the rel item of the dropdown menu item which contains
               // the sub-menu name.
               tabdropdown.dropit(this, event, this.getAttribute("rel"))
            }

            //Add drop-down symbol to this element since it has a forward
            // ref to a sub-menu
            if(tabdropdown.downsymbol != "")
               menuitems[i].innerHTML =
                  tabdropdown.downsymbol+menuitems[i].innerHTML;
         }
      }
   },

   /**
    * Function:   dropit(object, event, dropmenuid)
    * Purpose:    Drops down the menu specified by dropmenuid
    */
   dropit:function(obj, e, dropmenuID) {
      //Check to see if there's aleady a menu open, meaning we are moving from
      // one dropdown to another
      if(this.dropmenuobj!=null) {
         //Change the current dropdown menu visibility
         this.dropmenuobj.style.visibility="hidden";

         //Check to see if there's a previous menu and it's not us
         if(this.previousmenuitem != null && this.previousmenuitem != obj) {
            //See if the previous item is the default tab by checking for
            // 'default' in the parent classname
            if(this.previousmenuitem.parentNode.className.indexOf("default")==-1)
               this.previousmenuitem.parentNode.className=""

            //
            tabdropdown.togglehiddenobj(this.previousmenuitem, 'visible')
         }
      }

      //
      this.clearhidemenu()

      //Check browser type
      if(this.ie || this.firefox) {
         //Create a onmousout handler to hide visible menu
         obj.onmouseout=function() {
            tabdropdown.delayhidemenu(obj)
         }

         //Create a onclick handler
         obj.onclick=function(){
            return !tabdropdown.disablemenuclick
         }

         //Get items in the dropdown menu
         this.dropmenuobj=document.getElementById(dropmenuID)

         //Create a mouseover function for submenu
         this.dropmenuobj.onmouseover=function() {
            tabdropdown.clearhidemenu()
         }

         //Create a onmouseout function for the submenu
         this.dropmenuobj.onmouseout=function(e){
            tabdropdown.dynamichide(e, obj)
         }

         //Create an onclick function for the submenu
         this.dropmenuobj.onclick=function(){
            tabdropdown.delayhidemenu(obj)
         }


         this.showhide(this.dropmenuobj.style, e, obj)
         this.dropmenuobj.x=this.getposOffset(obj, "left")
         this.dropmenuobj.y=this.getposOffset(obj, "top")
         this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
         this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
         this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
         tabdropdown.togglehiddenobj(obj, "hidden") //Hide (form) object drop down menu overlaps, if any
      }
   },
   
   sizeframes:function(divid, frameid) {
   	var divsection = document.getElementById(divid);
   	var framesection = document.getElementById(frameid);
   	if(divsection != null && framesection != null) {
   		framesection.style.width = divsection.offsetWidth;
   		framesection.style.height = divsection.offsetHeight;
   		//framesection.style.top = divsection.top;
   		//framesection.style.left = divsection.left;
   	}
   }
      
}