home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Sponsors / Xara / webstyle / examples / working / navbars / nbexample8.js < prev    next >
Encoding:
Text File  |  2002-06-10  |  2.2 KB  |  74 lines

  1. var clicked=""
  2. var gtype=".gif"
  3. var selstate="_over"
  4. if (typeof(loc)=="undefined" || loc==""){
  5.     var loc=""
  6.     if (document.body&&document.body.innerHTML){
  7.         var tt = document.body.innerHTML.toLowerCase();
  8.         var last = tt.indexOf("nbexample8.js\"");
  9.         if (last>0){
  10.             var first = tt.lastIndexOf("\"", last);
  11.             if (first>0 && first<last) loc = document.body.innerHTML.substr(first+1,last-first-1);
  12.         }
  13.     }
  14. }
  15.  
  16. document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
  17. tr(false);
  18. writeButton("","javascript:;","nbexample8_b1",117,27,"Products","",0);
  19. writeButton("","javascript:;","nbexample8_b2",117,27,"Links","",0);
  20. writeButton("","javascript:;","nbexample8_b3",117,27,"Downloads","",0);
  21. tr(true);
  22. document.write("</tr></table>")
  23. loc="";
  24.  
  25. function tr(b){}
  26.  
  27. function turn_over(name) {
  28.     if (document.images != null && clicked != name) {
  29.         document[name].src = document[name+"_over"].src;
  30.     }
  31. }
  32.  
  33. function turn_off(name) {
  34.     if (document.images != null && clicked != name) {
  35.         document[name].src = document[name+"_off"].src;
  36.     }
  37. }
  38.  
  39. function reg(gname,name)
  40. {
  41. if (document.images)
  42.     {
  43.     document[name+"_off"] = new Image();
  44.     document[name+"_off"].src = loc+gname+gtype;
  45.     document[name+"_over"] = new Image();
  46.     document[name+"_over"].src = loc+gname+"_over"+gtype;
  47.     }
  48. }
  49.  
  50. function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}
  51.  
  52. function writeButton(urld, url, name, w, h, alt, target, hsp)
  53. {
  54.     gname = name;
  55.     while(typeof(document[name])!="undefined") name += "x";
  56.     reg(gname, name);
  57.     tr(true);
  58.     document.write("<td>");
  59.     if (alt != "") alt = " alt=\"" + alt + "\"";
  60.     if (target != "") target = " target=\"" + target + "\"";
  61.     if (w > 0) w = " width=\""+w+"\""; else w = "";
  62.     if (h > 0) h = " height=\""+h+"\""; else h = "";    
  63.     if (url != "") url = " href=\"" + urld + url + "\"";
  64.     
  65.     document.write("<a " + url + evs(name) + target + ">");    
  66.     
  67.     if (hsp == -1) hsp =" align=\"right\"";
  68.     else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";
  69.     else hsp = "";
  70.     
  71.     document.write("<img src=\""+loc+gname+gtype+"\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" /></a></td>");
  72.     tr(false);
  73. }
  74.