
/*
  - Dropmenu Module for Joomla! ----------------------------------------------------------

  Filename:       mod_dropmenu/mod_dropmenu.js
  Version:        1.4
  Release Date:   10/17/06
  Developer:      David Hunt
  Copyright:      2006 Byrgius Technologies
  License:        GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
  Source:         http://software.byrgius.com/

  - Dependants ---------------------------------------------------------------------------

  none

  ----------------------------------------------------------------------------------------
*/

/* -------------------------------- */
function wbDropMenu(){

  this.rowHeight       = 21;
  this.rowMargin       = 34;
  this.toggleInit      = 0;
  this.toggleDropObj   = null;
  this.toggleDropTimer = null;

  // ===================================================================
  this.toggleIsMe = function(o,k){
    if(!o||!k)return false;
    if(o==k)return true;
    // for(var i=0;i<o.childNodes;i++)
    //   if(toggleDropIsChild(o.childNodes[i],k))
    //     return true;
    return false;
  }

  // ===================================================================
  this.toggleDrop = function(t,o){
    clearTimeout(this.toggleDropTimer);
    if(this.toggleDropObj){
      if(this.toggleIsMe(this.toggleDropObj,o)){
        this.toggleDropObj = null;
      } else {
        if(this.toggleDropObj.className=='sub_hov')
          this.toggleDropObj.className='sub';
        else if(this.toggleDropObj.className=='main_hov')
          this.toggleDropObj.className='main';
      }
    }
    if(t==0 && o){
      this.toggleDropObj = o;
      this.toggleDropTimer=setTimeout("document.wbdmenu.toggleDrop(0,null);",300);
    } else if(o) {
      if(o.className=='main')
        o.className='main_hov';
      else if(o.className=='sub')
        o.className='sub_hov';
    } else if(this.toggleDropObj) {
      if(this.toggleDropObj.className=='main_hov')
        this.toggleDropObj.className='main';
      else if(this.toggleDropObj.className=='sub_hov')
        this.toggleDropObj.className='sub';
    }
  }

  // ===================================================================
  this.init = function(nodes){
    if(nodes){
      var childCount = 0;
      for(var i=0;i<nodes.length;i++){
        if( nodes[i].nodeName == 'LI' ){
          childCount++;
          if( nodes[i].childNodes[0].id != 'active_menu' ){
            nodes[i].wbdmenu = this;
            this._ae('onmouseover','this.wbdmenu.toggleDrop(1,this);',nodes[i]);
            this._ae('onmouseout','this.wbdmenu.toggleDrop(0,this);',nodes[i]);
          }
        }
        if( nodes[i].childNodes.length ){
          var myChildCount = this.init(nodes[i].childNodes);
          if( nodes[i].nodeName == 'UL' ){
            nodes[i].childCount = myChildCount;
            if( myChildCount && nodes[i].id.match(/_up/) )
              nodes[i].style.marginTop = '-'+((myChildCount*this.rowHeight)+this.rowMargin)+'px';
          }
        }
      }
      return childCount;
    } else {
      if( this.toggleInit )return null;
      var domElm = 0;
      do {
        var name = 'wbDropMenu'+domElm.toString();
        var menu = document.getElementById(name);
        if( menu )
          menu.childCount = this.init(menu.childNodes);
        domElm = domElm + 1;
      } while((menu !== null) || (typeof menu !== 'object'));
    }
  }

  // ===================================================================
  this._ae=function(oN,eF,cO){
    if(typeof oN!='string')return false;
    if(typeof eF=='function')eF=("'"+eF+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    if(eval('typeof '+(cO?'cO.'+oN:oN))!='function')return eval((cO?'cO.'+oN:oN)+'= function(e){ '+eF+' }');
    var oF=("'"+eval((cO?'cO.'+oN:oN))+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    return eval((cO?'cO.'+oN:oN)+'=function(e){'+oF+' '+eF+'}');
  };

  // ===================================================================
  this._de=function(oN,eF,cO){
    if(typeof oN != 'string')return false;if(eval('typeof '+(cO?cO.call(oN):oN)) != 'function')return true;
    if(typeof eF=='function')eF=("'"+eF+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    var oD=("'"+eval((cO?cO.call(oN):oN))+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'').replace(eF,'');
    if(oD.replace(/\s+/,'').length>0)return eval((cO?cO.call(oN):oN)+'=function(e){'+oD+'}');else return eval((cO?cO.call(oN):oN)+'=function(e){}');
  };

  // ===================================================================
  if(typeof document!='object')return null;
  if(typeof document.wbdmenu!=='undefined')return null;
  document.wbdmenu=this;

}
var wbDropMenuObj = new wbDropMenu();
wbDropMenuObj._ae('window.onload','document.wbdmenu.init();');