/* Adapted from menuDropdown.js by Dave Lindquist (dave@gazingus.org) */
var currentMenu = null;
if (!document.getElementById)
  document.getElementById = function() { return null; }
function initializeMenu(menuitem) {
  var actuator = menuitem.getElementsByTagName('a')[0];
  var menu = menuitem.getElementsByTagName('ul')[0];
  var gone = 1;
  var beginner = 0;
  disappear = setTimeout('',100000);
  if (menu == null || actuator == null) return;
  actuator.onmouseover = function() {
    if (currentMenu == null) {
      this.showMenu();
    }
    else {
      currentMenu.style.visibility = "hidden";
      currentMenu = null;
    }
    this.showMenu();
    if (gone == 1) {
      clearInterval(disappear);
    }
    gone = 0;
    return false;
  }
  actuator.onmouseout = function() {
    gone = 1;
    disappear = setTimeout(hide,50);
  }
  hide = function() {
    currentMenu.style.visibility = "hidden";
    currentMenu = null;
  }
  actuator.showMenu = function() {
//    menu.style.left = this.offsetLeft + "px";
//    menu.style.top = this.offsetTop + this.offsetHeight + "px";
    menu.style.visibility = "visible";
    currentMenu = menu;
  }
  menu.onmouseover = function() {
    if (gone == 1) {
      clearInterval(disappear);
      gone = 0;
    }
  }
  menu.onmouseout = function() {
    gone = 1;
    disappear = setTimeout(hide,500);
  }
}

function initMenu() {
  //if this is an English page, the menu is here
  if (document.getElementById('block-menu-26')) {
    //this allows us to drill through the DOM to the actuators and menus
    //the path through the DOM to the menu
    var pt1 = document.getElementById('block-menu-26').getElementsByTagName('ul')[0];
    //the first actuator
    var actuator1 = 0;
    initializeMenu(pt1.getElementsByTagName('li')[actuator1]);
    //to find the second actuator, we need to know the number of items in the first submenu
    var subitems1 = pt1.getElementsByTagName('li')[actuator1].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator2 = actuator1 + subitems1 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator2]);
    //to find the third actuator, we need to know the number of items in the second submenu
    var subitems2 = pt1.getElementsByTagName('li')[actuator2].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator3 = actuator1 + subitems1 + 1 + subitems2 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator3]);
    //to find the fourth actuator, we need to know the number of items in the third submenu
    var subitems3 = pt1.getElementsByTagName('li')[actuator3].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator4 = actuator1 + subitems1 + 1 + subitems2 + 1 + subitems3 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator4]);
  }
  // on the French pages it's here
  else if (document.getElementById('block-menu-52')) {
    //this allows us to drill through the DOM to the actuators and menus
    //the path through the DOM to the menu
    var pt1 = document.getElementById('block-menu-52').getElementsByTagName('ul')[0];
    //the first actuator
    var actuator1 = 0;
    initializeMenu(pt1.getElementsByTagName('li')[actuator1]);
    //to find the second actuator, we need to know the number of items in the first submenu
    var subitems1 = pt1.getElementsByTagName('li')[actuator1].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator2 = actuator1 + subitems1 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator2]);
    //to find the third actuator, we need to know the number of items in the second submenu
    var subitems2 = pt1.getElementsByTagName('li')[actuator2].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator3 = actuator1 + subitems1 + 1 + subitems2 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator3]);
    //to find the fourth actuator, we need to know the number of items in the third submenu
    var subitems3 = pt1.getElementsByTagName('li')[actuator3].getElementsByTagName('li').length;
    //the actuator is after the submenu
    var actuator4 = actuator1 + subitems1 + 1 + subitems2 + 1 + subitems3 + 1;
    initializeMenu(pt1.getElementsByTagName('li')[actuator4]);
  }
}

addEvent(window,'load',initMenu);

function initMenuSwap() {
  if (document.getElementById) {
    if (document.getElementById('block-menu-26')) var x = document.getElementById('block-menu-26').getElementsByTagName('IMG');
    else if (document.getElementById('block-menu-52')) var x = document.getElementById('block-menu-52').getElementsByTagName('IMG');
  }
  else return;
  var preloads = new Object();
  for (var i=0;i<x.length;i++) {
    preloads['off'+x[i].id] = new Image;
    preloads['off'+x[i].id].src = '/themes/transformix/'+ x[i].id + '-off.gif';
    preloads['on'+x[i].id] = new Image;
    preloads['on'+x[i].id].src = '/themes/transformix/'+ x[i].id + '-on.gif';
    x[i].onmouseover = function () {this.src=preloads['on'+this.id].src;}
    x[i].onmouseout = function () {this.src=preloads['off'+this.id].src;}
  }
}

addEvent(window,'load',initMenuSwap);
