1 | var temp, temp2, cookieArray, cookieArray2, cookieCount; |
---|
2 | |
---|
3 | function initiate() { |
---|
4 | cookieCount=0; |
---|
5 | |
---|
6 | if (document.cookie) { |
---|
7 | cookieArray = document.cookie.split(";"); |
---|
8 | cookieArray2 = new Array(); |
---|
9 | |
---|
10 | for (i in cookieArray) { |
---|
11 | cookieArray2[cookieArray[i].split("=")[0].replace(/ /g, "")] |
---|
12 | = cookieArray[i].split("=")[1].replace(/ /g, ""); |
---|
13 | } |
---|
14 | } |
---|
15 | |
---|
16 | cookieArray = (document.cookie.indexOf("state=") >= 0) |
---|
17 | ? cookieArray2["state"].split(",") |
---|
18 | : new Array(); |
---|
19 | |
---|
20 | temp = document.getElementById("tree"); |
---|
21 | |
---|
22 | for (var o=0; o<temp.getElementsByTagName("li").length; o++) { |
---|
23 | if (temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length > 0) { |
---|
24 | temp2 = document.createElement("span"); |
---|
25 | temp2.className = "symbols"; |
---|
26 | temp2.style.backgroundImage = (cookieArray.length > 0) |
---|
27 | ? ((cookieArray[cookieCount]=="true") |
---|
28 | ? "url(minus.png)" |
---|
29 | : "url(plus.png)") |
---|
30 | : "url(plus.png)"; |
---|
31 | temp2.onclick=function(){ |
---|
32 | showhide(this.parentNode); |
---|
33 | writeCookie(); |
---|
34 | } |
---|
35 | |
---|
36 | temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild) |
---|
37 | temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none"; |
---|
38 | |
---|
39 | if (cookieArray[cookieCount]=="true") { |
---|
40 | showhide(temp.getElementsByTagName("li")[o]); |
---|
41 | } |
---|
42 | cookieCount++; |
---|
43 | } else { |
---|
44 | |
---|
45 | temp2 = document.createElement("span"); |
---|
46 | temp2.className = "symbols"; |
---|
47 | temp2.style.backgroundImage = "url(page.png)"; |
---|
48 | |
---|
49 | temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild); |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | function showhide(el) { |
---|
57 | el.getElementsByTagName("ul")[0].style.display = (el.getElementsByTagName("ul")[0].style.display == "block") |
---|
58 | ? "none" |
---|
59 | : "block"; |
---|
60 | el.getElementsByTagName("span")[0].style.backgroundImage = (el.getElementsByTagName("ul")[0].style.display == "block") |
---|
61 | ? "url(minus.png)" |
---|
62 | : "url(plus.png)"; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | // Runs through the menu and puts the "states" of each nested list into an |
---|
68 | // array, the array is then joined together and assigned to a cookie. |
---|
69 | function writeCookie() { |
---|
70 | cookieArray = new Array() |
---|
71 | |
---|
72 | for (var q=0; q < temp.getElementsByTagName("li").length; q++) { |
---|
73 | if (temp.getElementsByTagName("li")[q].childNodes.length > 0) { |
---|
74 | if (temp.getElementsByTagName("li")[q].childNodes[0].nodeName == "SPAN" |
---|
75 | && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length > 0) { |
---|
76 | cookieArray[cookieArray.length] |
---|
77 | = (temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display == "block"); |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | document.cookie = "state=" + cookieArray.join(",") + ";expires=" |
---|
83 | + new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString(); |
---|
84 | |
---|
85 | } |
---|