/*
  wbDropMenu v1.4.2-102810
  ** MOOTOOLS VERSION **
  (c)2006-2209 Webuddha <http://www.webuddha.com/?web+development>,
  The Holodyn Corporation <http://www.holodyn.com/?internet+marketing>
  Packed with dean edwards packer <http://dean.edwards.name/packer/>
*/
function wbDropMenu(){
  this.rowHeight  = 21;
  this.rowMargin  = 34;
  this.toggleInit = 0;
  this.dropTimer  = [];
  this.dropCache  = [];
  this.tumbleDry  = [];
  this.options = {
    'dropSpeed'       :250,
    'tumbleDry'       :true,
    'tumbleDrySpeed'  :10,
    'openEffect'      :'BlindDown',
    'closeEffect'     :'Fade'
    };
  /* =================================================================== */
  this.toggleDrop = function(t,o){
    if(t && o){
      if( !o.className.match(/_hov/) ){
        if( o.down('ul') ){
          new Fx.Styles(o.down('ul'), {
            duration : 500, transition : Fx.Transitions.Back.easeIn,
            wait : false, onStart : function (elm){
              var eL=elm.up('li');
              eL.className=eL.className.replace(/(main|sub)/,'$1_hov');
            }, onComplete : function (){}
          }).set({'opacity':0}).start({'opacity':1});
        } else
          o.className=o.className.replace(/(main|sub)/,'$1_hov');
      };
      for(var i=0;i<this.dropCache.length;i++)
        if(o==this.dropCache[i]){
          this.dropCache.splice(i,1);
          clearTimeout(this.dropTimer.splice(i,1));
        }
    } else if(!t && o) {
      this.dropCache.push( o );
      this.dropTimer.push( setTimeout("document.wbdmenu.toggleDrop(0,null);",this.options.dropSpeed) );
    } else if(!t && this.dropCache.length) {
      var dropObj = this.dropCache.shift();
      var dropTim = this.dropTimer.shift();
      this.closeSet(dropObj);
    }
  };
  /* =================================================================== */
  this.closeSet = function(o,t){
    if(!o||!o.tagName){
      if(t&&this.tumbleDry.length){
        var o=$(this.tumbleDry.pop());
        if( o.down('ul') )
          o.className = o.className.replace(/_hov/,'');
        else
          o.className = o.className.replace(/_hov/,'');
        if(this.tumbleDry.length)
          setTimeout('document.wbdmenu.closeSet(null,true);',this.options.tumbleDrySpeed);
      };
      return;
    };
    if(this.options.tumbleDry){
      if( o.className.match(/_hov/) ){
        if(!this.tumbleDry.length)
          setTimeout('document.wbdmenu.closeSet(null,true);',(this.options.tumbleDrySpeed*this.getLevel(o)));
        this.tumbleDry.push(o.identify());
      }
    } else
      o.className = o.className.replace(/_hov/,'');
    for(var i=0;i<o.childNodes.length;i++)
      if(o.childNodes[i].childNodes.length)
        this.closeSet(o.childNodes[i]);
  };
  /* =================================================================== */
  this.getLevel = function(o){
    if(o.parentNode&&o.parentNode.tagName)
      if(o.parentNode.tagName.toLowerCase()=='div')
        return 1;
      else if(o.parentNode.tagName.toLowerCase()=='ul')
        if(o.parentNode.className.match(/level/))
          return (o.parentNode.className.replace(/level/,'')*1)+1;
        else
          return 1;
      else
        return this.getLevel(o.parentNodes[i]);
    return 1;
  };
  /* =================================================================== */
  this.isChildOpen = function(o){
    for(var i=0;i<o.childNodes.length;i++)
      if(o.childNodes[i].tagName)
        if(o.childNodes[i].tagName.toLowerCase()=='li' && o.childNodes[i].className.match(/_hov/))
          return true;
        else if(o.childNodes[i].childNodes.length)
          if(this.isChildOpen(o.childNodes[i]))
            return true;
    return false;
  };
  /* =================================================================== */
  this.init = function(nodes,level){
    if(nodes){
      var level = (level ? level : 0);
      var childCount = 0;
      for(var i=0;i<nodes.length;i++){
        if( nodes[i].nodeName == 'A' )
          nodes[i].title = '';
        if( nodes[i].nodeName == 'LI' ){
          childCount++;
          if( nodes[i].childNodes[0].id != 'active_menu' ){
            nodes[i].wbdmenu = this;
            if(level)$(nodes[i]).addClassName('sub');else $(nodes[i]).addClassName('main');
            $(nodes[i]).addEvent('mouseover',function(){this.wbdmenu.toggleDrop(1,this);});
            $(nodes[i]).addEvent('mouseout',function(){this.wbdmenu.toggleDrop(0,this);});
          }
          if( nodes[i].childNodes.length ){
            for(var cI=0;cI<nodes[i].childNodes.length;cI++){
              if( nodes[i].childNodes[cI].nodeName == 'UL' ){
                var myChildCount = this.init(nodes[i].childNodes[cI].childNodes,level+1);
                nodes[i].childNodes[cI].childCount = myChildCount;
                $(nodes[i].childNodes[cI]).addClassName('level'+(level+1));
              }
            }
          }
        };
      };
      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'));
    }
  };
  /* =================================================================== */
  if(typeof document!='object')return null;
  if(typeof document.wbdmenu!=='undefined')return null;
  document.wbdmenu=this;
};

var wbDropMenuObj = new wbDropMenu();
window.addEvent('load',function(){document.wbdmenu.init();});

