/* Alzenheimer Suckerfish Dropdowns by Kim Steinhaug, http://kim.steinhaug.no/

   Son of Suckerfish Dropdowns, inspired by Suckerfish Dropdowns at ALA then 
   vastly improved by Patrick Griffiths (http://www.htmldog.com/ptg/) and 
   Dan Webb (http://www.danwebb.net/). Original article here : 
   http://www.alistapart.com/articles/dropdowns/
   
   Script then customized by Kim Steinhaug (http://kim.steinhaug.no/) so that 
   we can remember the :hover state of the menu we are popping from.
   Script also buildt into OO for code seperation.
                                                                        */
function Alzenheimer_Suckerfish_Dropdowns() {
  this.version          = 'v1.0';
  this.author           = 'Kim Steinhaug';
  this.info             = 'This version is only setup for 1 alzenheimer level';
  this.SuckerFishClass  = 'sfhover';
  this.AlzenheimerClass = 'Alzenheimer';
}
Alzenheimer_Suckerfish_Dropdowns.prototype = {
  init : function() {
    var sfEls = document.getElementById("navlist").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
      if (window.attachEvent){
        if(sfEls[i].parentNode.id == 'navlist'){
          sfEls[i].onmouseover=function() {
            this.className+=" " + AlzSF.SuckerFishClass;
            AlzSF.Flush();
            AlzSF.Set(this);
          }
          sfEls[i].onmouseout=function() {
            AlzSF.removeCSSClass(this,AlzSF.SuckerFishClass);
            AlzSF.Flush();
          }
        }
      } else {
        if(sfEls[i].parentNode.id == 'navlist'){
          sfEls[i].onmouseover=function() {
            AlzSF.Flush();
            AlzSF.Set(this);
          }
          sfEls[i].onmouseout=function() {
            AlzSF.Flush();
          }
        }
      }
    }
  },
  Set : function(el) {
    // If we have a popup the el should have more children,
    // [1] should be an UL with correkt markup.
    // Normally we would check for [1], but IE adds an extra object
    // here, so we check for [2] instead. After all we should have 
    // <li><a>..</a></li> lots more objects in here if popup.
    if(el.childNodes[2] != null)
      el.childNodes[0].className+=" " + AlzSF.AlzenheimerClass;
  },
  Flush : function() {
    var sfEls = document.getElementById("navlist").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
      if(sfEls[i].parentNode.id == 'navlist'){
        elm = sfEls[i].childNodes[0];
        if(elm.tagName == 'A'){
          AlzSF.removeCSSClass(elm,AlzSF.AlzenheimerClass);
        }
      }
    }
  },
  removeCSSClass : function(elm, cls) {
    var ar = this.explode(' ', elm.className);
      for (var i=0; i<ar.length; i++) {
        if (ar[i] == cls)
        ar[i] = '';
    }
    elm.className = ar.join(' ');
  },
  explode : function(d, s) {
    var ar = s.split(d);
    var oar = new Array();
    for (var i = 0; i<ar.length; i++) {
      if (ar[i] != "")
      oar[oar.length] = ar[i];
    }
    return oar;
  }
}
AlzSF = new Alzenheimer_Suckerfish_Dropdowns;
addEvent(window,'load',AlzSF.init,false);
//if (window.attachEvent) window.attachEvent("onload", AlzSF.init);

