function my_replace_image_name(src, from, to) {
  return src.replace(new RegExp("_" + from + "\."), "_" + to + ".");
}
function my_swap_image(o, from, to) {
  return function() {
    o.src = my_replace_image_name(o.src, from, to);
  }
}
window.onload = function() {
  var lists = document.getElementById("globalNav").getElementsByTagName("li");
  var pool = new Array();          // a pool of preload images
  var static_menu_on = document.getElementById('static_menu_on_item');
  if (static_menu_on) {
    static_menu_on = new RegExp(static_menu_on.value);
  }
  for (var i = 0; i < lists.length; i++) {
    var item = lists[i].getElementsByTagName("img")[0];

    if (static_menu_on && static_menu_on.test(item.src)) {
      item.src = my_replace_image_name(item.src, "off", "on");
    }
    else {
      // preload
      var img = new Image();
      img.src = my_replace_image_name(item.src, "off", "on");
      pool.push(img);

      item.onmouseover = my_swap_image(item, "off", "on");
      item.onmouseout = my_swap_image(item, "on", "off");
    }
  }
}

