menu.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. var agt=navigator.userAgent.toLowerCase();
  2. var is_major = parseInt(navigator.appVersion);
  3. var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
  4. && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
  5. && (agt.indexOf('webtv')==-1));
  6. var is_ie = (agt.indexOf("msie") != -1);
  7. var is_nav5up = (is_nav && (is_major >= 5));
  8. function createCSS(){
  9. var h=0, w=0, counter =0, layerid, top = 1, left = 1, color, topAbsolute, leftAbsolute;
  10. document.write("<style>");
  11. document.write("#background {position: absolute; top: 90px; left: 0px; width: 100%; height: 400px; clip: rect(0px 1000px 500px 0px);}");
  12. h = calHeight(root);
  13. w = rootW + 2;
  14. writeCSS("rootB", menuTop, menuLeft, w, h, menuBodercolor, 0);
  15. w = w -2;
  16. for (x=0; x<root.length; x+=7){
  17. eval("layerid = 'rootI" + counter + "';");
  18. if (root[x+2]==0)
  19. h = menuHeight;
  20. else
  21. h = root[x+2];
  22. if (root[x+3]==0)
  23. color = menuBGcolor;
  24. else
  25. color = root[x+3];
  26. writeCSS(layerid, top, left, w, h, color, 0);
  27. if (root[x+5] == 1){
  28. topAbsolute = menuTop + top - 1;
  29. leftAbsolute = menuLeft + rootW + menuIndent;
  30. createSubCSS(eval("'roots" + counter + "'"), topAbsolute, leftAbsolute);
  31. }
  32. top += h + 1;
  33. counter++;
  34. }
  35. document.write(".text {font-size:11px; font-family:Verdona, Arial; text-decoration:none; color:navy; layer-background-color:transparent; background-color:transparent;}");
  36. document.write("</style>");
  37. }
  38. function createSubCSS(name, t, l){
  39. var h=0, w=0, counter =0, layerid, top = 1, left = 1, color, topAbsolute, leftAbsolute, arrayLength;
  40. var menuName = eval(name);
  41. w = eval(name + "W") + 2;
  42. h = calHeight(menuName);
  43. writeCSS((name + "B"), t, l, w, h, menuBodercolor, 2);
  44. w = w -2;
  45. eval("arrayLength = " + name + ".length;");
  46. var x1 = 0;
  47. for (x1=0; x1<arrayLength; x1+=7){
  48. eval("layerid = '" + name + "I" + counter + "';");
  49. if (menuName[x1+2]==0)
  50. h = menuHeight;
  51. else
  52. h = menuName[x1+2];
  53. if (menuName[x1+3]==0)
  54. color = menuBGcolor;
  55. else
  56. color = menuName[x1+3];
  57. writeCSS(layerid, top, left, w, h, color, 1);
  58. if (menuName[x1+5] == 1){
  59. topAbsolute = t + top -1;
  60. leftAbsolute = l + w + menuIndent;
  61. createSubCSS(eval("'" + name + "s" + counter + "';"), topAbsolute, leftAbsolute);
  62. }
  63. top += h +1;
  64. counter++;
  65. }
  66. return;
  67. }
  68. function calHeight(menuName){
  69. var total = 0;
  70. for (x2=0; x2<menuName.length; x2+=7){
  71. if (menuName[x2+2] == 0)
  72. total += menuHeight;
  73. else
  74. total += menuName[x2+2];
  75. }
  76. total += menuName.length/7 + 1;
  77. return total;
  78. }
  79. var V = new Array("visible", "inherit", "hidden");
  80. function writeCSS(layerid, top, left, width, height, color, index){
  81. document.write("#" + layerid + " {position: absolute; top:"+ top+ "px; left: "+ left + "px; width:" + width + "px; height:" + height + "px; clip:rect(0px " + width + "px " + height + "px 0px); layer-background-color:" + color + "; background-color: " + color + "; visibility: " + V[index]+ ";}\n");
  82. }
  83. function writeDiv(){
  84. var layerN, link, counter=0, childrenID;
  85. document.write("<div id='background'>&nbsp;</div>");
  86. var Main = new CreateLayer("background", "");
  87. Main.layer.onmouseover = HideAll;
  88. for (x=0; x<rootDiv.length; x++){
  89. document.write("<div id='" + rootDiv[x] + "B'>\n");
  90. makeLayerID(eval("'" + rootDiv[x]+ "B'"), "", "", "", -1);
  91. counter = 0;
  92. var menuName = eval(rootDiv[x]);
  93. for (y=0; y<menuName.length; y+=7){
  94. layerN = rootDiv[x] + "I" + eval("'" + counter + "'");
  95. if (menuName[y+1] != "")
  96. link = "href='" + menuName[y+1] + "'";
  97. document.write("<div id='" + layerN + "'><a "+ link +"class='text'>&nbsp;&nbsp;" + menuName[y] + "</a></div>\n");
  98. makeLayerID(layerN, eval("'" + rootDiv[x] + "B'"), menuName, y, 0);
  99. counter++;
  100. link = "";
  101. }
  102. document.write("</div>\n\n");
  103. }
  104. createLayerInfoID();
  105. }
  106. var layerID;
  107. function makeLayerID(id, rootid, menuName, index, isNotBGlayer) { // -1: no subroot (hasSubroot)
  108. layerID = "L" + id;
  109. eval(layerID + "= new CreateLayer('" + id + "','" + rootid + "');");
  110. if (isNotBGlayer != -1){
  111. var LID = eval(layerID);
  112. LID.id = "L" + id;
  113. LID.layerInfo = menuName[index+6];
  114. if (menuName[index+3] != 0)
  115. LID.BGcolor = menuName[index+3];
  116. else
  117. LID.BGcolor = menuBGcolor;
  118. if (menuName[index+4] != 0)
  119. LID.OBGcolor = menuName[index+4];
  120. else
  121. LID.OBGcolor = menuOBGcolor;
  122. if (menuName[index+5] == 1)
  123. LID.children = "L" + rootid.split("B")[0] + "s" + eval("'"+(index/7)+"'") + "B";
  124. else
  125. LID.children = 0;
  126. var level = LID.id.split("s");
  127. LID.level = level.length - 1;
  128. // 0 => onmouseout 1 => onmouseover
  129. LID.layer.onmouseover = new Function("ChangeColor('" + LID.id + "', 1)");
  130. LID.layer.onmouseout = new Function("ChangeColor('" + LID.id + "', 0)");
  131. }
  132. }
  133. var bgC = ".backgroundColor";
  134. if (is_nav && !is_nav5up)
  135. bgC = ".document.bgColor";
  136. function ChangeColor(id, type){
  137. var layerID = eval(id);
  138. if (type == 1){
  139. eval("layerID.css" + bgC + "='" + layerID.OBGcolor + "';");
  140. HideShowLayer(layerID, 1);
  141. }
  142. else{
  143. eval("layerID.css" + bgC + "='" + layerID.BGcolor + "';");
  144. HideShowLayer(layerID, 0);
  145. }
  146. }
  147. var track = new Array();
  148. for (x= 0; x<menuLevel-1; x++){
  149. track[x] = "";
  150. }
  151. var layerInfo = "";
  152. function HideShowLayer(layerID, l){
  153. hideCondition = false;
  154. if (l == 1)
  155. hidePower = false;
  156. else
  157. hidePower = true;
  158. for (x=menuLevel-2; x>=layerID.level; x--){
  159. if (track[x] != "")
  160. eval(track[x] + ".css.visibility = 'hidden'");
  161. }
  162. if (layerID.children != 0){
  163. eval(layerID.children + ".css.visibility = 'visible'");
  164. track[layerID.level] = layerID.children;
  165. }
  166. if (layerID.layerInfo != 0 && l == 1 && layerID.layerInfo != layerInfo){
  167. if (layerInfo != "")
  168. eval("L" + layerInfo + ".css.visibility = 'hidden'");
  169. eval("L" + layerID.layerInfo + ".css.visibility = 'visible'");
  170. layerInfo = layerID.layerInfo;
  171. }
  172. }
  173. var hideCondition = false;
  174. var hidePower = true;
  175. var IDset = false;
  176. function HideAll(){
  177. if (hidePower == true){
  178. if (hideCondition == true){
  179. for (x=menuLevel-2; x>=0; x--){
  180. if (track[x] != "")
  181. eval(track[x] + ".css.visibility = 'hidden'");
  182. }
  183. if (IDset == true){
  184. clearInterval(hideID);
  185. IDset = false;
  186. }
  187. hideCondition = false;
  188. }
  189. else{
  190. hideCondition = true;
  191. if (IDset == false){
  192. hideID = setInterval("HideAll()", menuHideSpeed);
  193. IDset = true;
  194. }
  195. }
  196. }
  197. }
  198. function CreateLayer(id, rootid) {
  199. if (is_nav5up) {
  200. this.layer = document.getElementById(id);
  201. this.css = this.layer.style;
  202. }
  203. if (is_nav && !is_nav5up){
  204. if (rootid != "")
  205. this.layer = document.layers[rootid].document.layers[id];
  206. else
  207. this.layer = document.layers[id];
  208. this.css = this.layer;
  209. }
  210. if (is_ie) {
  211. this.layer = document.all[id];
  212. this.css = document.all[id].style;
  213. }
  214. }
  215. function writeCSSLayerInfo(name){
  216. document.write("#" + name + "{position: absolute; top:" + LayerInfoTop + "; left:" + LayerInfoLeft + "; visibility: hidden;}");
  217. }
  218. function createLayerInfoID(){
  219. if (LayerInfoDiv[0] != ""){
  220. for (x=0; x<LayerInfoDiv.length; x++)
  221. eval("L" + LayerInfoDiv[x] + "= new CreateLayer('" + LayerInfoDiv[x] + "', '');");
  222. }
  223. }