Fix menu exploding (so that we don't need the id's anymore)
[gigi.git] / static / static / menu.js
1 (function() {
2         function explodeMenu(e) {
3                 if (e.className == 'menu hidden') {
4                         e.className = 'menu';
5                 } else {
6                         e.className = 'menu hidden';
7                 }
8         }
9
10         function initMenu() {
11                 var Nodes = document.getElementsByTagName('ul');
12                 var max = Nodes.length;
13                 for (var i = 0; i < max; i++) {
14                         var nodeObj = Nodes.item(i);
15                         if (nodeObj.className.indexOf("menu") > -1 && nodeObj.id != "recom") {
16                                 nodeObj.previousSibling.previousSibling.onclick = (function(node) {
17                                         return function() {
18                                                 explodeMenu(node);
19                                         };
20                                 })(nodeObj);
21                         }
22                 }
23         }
24         function showExpert(a)
25         {
26           b=document.getElementsByClassName("expert");
27           for(i=0;b.length>i;i++)
28           {
29             if(!a) {b[i].setAttribute("class","expert experthidden"); }
30             else {b[i].setAttribute("class","expert");}
31           }
32           b=document.getElementsByClassName("expertoff");
33           for(i=0;b.length>i;i++)
34           {
35            b[i].setAttribute("class","");
36           }
37
38         }
39         function init(){
40                 initMenu();
41                 showExpert(false);
42                 var expert = document.getElementById("expertbox");
43                 if(expert !== null) {
44                         expert.onchange = (function(expert){return function(){showExpert(expert.checked)}})(expert);
45                 }
46         }
47         (function(oldLoad) {
48                 if (oldLoad == undefined) {
49                         window.onload = init;
50                 } else {
51                         window.onload = function() {
52                                 init();
53                                 oldLoad();
54                         }
55                 }
56         })(window.onload);
57
58 })();