home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Sponsors / Xara / webstyle / examples / working / navbars / nbexample10.js < prev    next >
Encoding:
Text File  |  2002-06-10  |  2.4 KB  |  76 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("nbexample10.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. document.write("<td><img src=\""+loc+"nbexample10_left.gif\" alt=\"\" width=\"33\" height=\"34\"></td>");
  18. tr(false);
  19. writeButton("","javascript:;","nbexample10_b1",118,34,"Products","",0);
  20. writeButton("","javascript:;","nbexample10_b2",118,34,"Links","",0);
  21. writeButton("","javascript:;","nbexample10_b3",118,34,"Downloads","",0);
  22. tr(true);
  23. document.write("<td><img src=\""+loc+"nbexample10_right.gif\" alt=\"\" width=\"37\" height=\"34\"></td>");
  24. document.write("</tr></table>")
  25. loc="";
  26.  
  27. function tr(b){}
  28.  
  29. function turn_over(name) {
  30.     if (document.images != null && clicked != name) {
  31.         document[name].src = document[name+"_over"].src;
  32.     }
  33. }
  34.  
  35. function turn_off(name) {
  36.     if (document.images != null && clicked != name) {
  37.         document[name].src = document[name+"_off"].src;
  38.     }
  39. }
  40.  
  41. function reg(gname,name)
  42. {
  43. if (document.images)
  44.     {
  45.     document[name+"_off"] = new Image();
  46.     document[name+"_off"].src = loc+gname+gtype;
  47.     document[name+"_over"] = new Image();
  48.     document[name+"_over"].src = loc+gname+"_over"+gtype;
  49.     }
  50. }
  51.  
  52. function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}
  53.  
  54. function writeButton(urld, url, name, w, h, alt, target, hsp)
  55. {
  56.     gname = name;
  57.     while(typeof(document[name])!="undefined") name += "x";
  58.     reg(gname, name);
  59.     tr(true);
  60.     document.write("<td>");
  61.     if (alt != "") alt = " alt=\"" + alt + "\"";
  62.     if (target != "") target = " target=\"" + target + "\"";
  63.     if (w > 0) w = " width=\""+w+"\""; else w = "";
  64.     if (h > 0) h = " height=\""+h+"\""; else h = "";    
  65.     if (url != "") url = " href=\"" + urld + url + "\"";
  66.     
  67.     document.write("<a " + url + evs(name) + target + ">");    
  68.     
  69.     if (hsp == -1) hsp =" align=\"right\"";
  70.     else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";
  71.     else hsp = "";
  72.     
  73.     document.write("<img src=\""+loc+gname+gtype+"\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" /></a></td>");
  74.     tr(false);
  75. }
  76.