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