var accordion = {
   h3s: null,
   uls: null,
   init: function () {
      accordion.h3s = nouFw.get("accordion").getElementsByTagName("H3");
      accordion.uls = nouFw.get("accordion").getElementsByTagName("UL");
      // work out the natural height off each UL and then set it to 0
      var i;
      for (i = 0; i < accordion.uls.length; i++) {
         accordion.uls[i].id = accordion.uls[i].offsetHeight;
         accordion.uls[i].style.height = "0px"
      }	  
      // attach event listeners on the H3s
      var j;
      for (j = 0; j < accordion.h3s.length; j++) {
         accordion.h3s[j].onclick = function () {
            // close the one which is open (if any)
            accordion.killThemAll(this);
            // open the one you clicked on ...
            if (!this.parentNode.className || this.parentNode.className === "off") {
               this.parentNode.className = "on";
               var thisUlHeight = parseInt(this.parentNode.getElementsByTagName("UL")[0].id);
               var showSect = {
                  id: thisUlHeight,
                  cssProp: "height",
                  vals: [0,thisUlHeight],
                  totTime: 200,
                  uom: "px"   
               }
               nouFw.anim(showSect, function () {
               })(); 
            }
            // ... or close it. Depending on the className
            else if (this.parentNode.className === "on") {
               this.parentNode.className = "off";
               var thisUlHeight = parseInt(this.parentNode.getElementsByTagName("UL")[0].id);
               var hideSect = {
                  id: thisUlHeight,
                  cssProp: "height",
                  vals: [thisUlHeight,0],
                  totTime: 200,
                  uom: "px"   
               }
               nouFw.anim(hideSect, function () {
                  // empty callback
               })(); 
            }
         }
      }
   },
   killThemAll: function (currentEl) {
      var i;
      for (i = 0; i < accordion.h3s.length; i++) {
         if (accordion.h3s[i] !== currentEl) { 
            if (accordion.h3s[i].parentNode.className === "on") {
               accordion.h3s[i].parentNode.className = "off";
               var thisUlHeight = parseInt(accordion.h3s[i].parentNode.getElementsByTagName("UL")[0].id);
               var hideSect = {
                  id: thisUlHeight,
                  cssProp: "height",
                  vals: [thisUlHeight,0],
                  totTime: 200,
                  uom: "px"   
               }
               nouFw.anim(hideSect, function () {
                  // empty callback
               })();
            }
         }
      }
   }
}

// initialization of the accordion (if the DOM element is available AKA I am in index.php)
if (nouFw.get("accordion")) {
   accordion.init();
}