home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 July / PCpro_2004_07.ISO / docs / maxblast / maxblast3_files / nav.js < prev    next >
Encoding:
Text File  |  2004-03-07  |  8.9 KB  |  298 lines

  1. use("thing.mouse.local");
  2.  
  3. var tempfolders = location.pathname.toLowerCase().replace("index.htm", "").split("/");
  4. var folders = new Array();
  5. for( var i=1; i<tempfolders.length; i++ ){
  6.     if( tempfolders[i] != '' ){
  7.         folders[ folders.length ] = tempfolders[i];
  8.     }
  9. }
  10. tempfolders = null;
  11.  
  12. /********************************************************************************
  13.  
  14.     Nav construction
  15.  
  16. ********************************************************************************/
  17. function Nav( name, title, parent, isBig, isUtilNav ){
  18.     this.name = name.toLowerCase();
  19.     this.title = title;
  20.     this.parent = parent;
  21.     this.path = (this.parent) ? this.parent.path + '/' + this.name : name;
  22.     this.kids = new Array();
  23.     this.tier = (this.parent) ? this.parent.tier + 1 : 0;
  24.     this.isBig = isBig;
  25.     this.isUtilNav = isUtilNav;
  26.     
  27.     this.isCurrent = (this.parent) ? this.parent.isCurrent && folders[this.tier] == this.name : true;
  28.     
  29.     if( this.parent ){
  30.         if( this.parent.isCurrent ){
  31.             if( folders[this.tier] == this.name ) this.isCurrent = true;
  32.             else if( folders[this.tier] == null && this.name == '' ) this.isCurrent=true;
  33.             else this.isCurrent = false;
  34.         }
  35.         else{
  36.             this.isCurrent = false;
  37.         }
  38.     }
  39.     else{
  40.         this.isCurrent = true; // root
  41.     }
  42.     if( this.isCurrent ){
  43.         Nav.currentNav = this;
  44.         if( this.parent && ! Nav.currentT1 ){
  45.             Nav.currentT1 = this;
  46.         }
  47.     }
  48. }
  49. Nav.currentNav = null;
  50. Nav.currentT1 = null;
  51. Nav.prototype.add = function( name, title, isBig, isUtilNav ){
  52.     return this.kids[ this.kids.length ] = new Nav( name, title, this, isBig, isUtilNav );
  53. }
  54.  
  55. /********************************************************************************
  56.  
  57.     html writing
  58.  
  59. ********************************************************************************/
  60. Nav.globalNav = function(){
  61.     var htmlDropdowns = '';
  62.     
  63.     for( var i=0; i<Nav.root.kids.length; i++ ){
  64.         htmlDropdowns += Nav.root.kids[i].dropdown();
  65.     }
  66.         
  67.     return htmlDropdowns;
  68. }
  69. Nav.prototype.dropdown = function(){
  70.     if( ! this.isBig ) return '';
  71.     var html = '<div id="navDrop' + this.name + 'Div" class="navDrop">\n';
  72.     
  73.     for( var i=0; i<this.kids.length; i++ ){
  74.         html += this.kids[i].dropdownRow(i);
  75.     }
  76.     html += '</div>\n\n';
  77.     return html;
  78. }
  79. Nav.prototype.dropdownRow = function(index){
  80.     var cssClass = (index == 0) ? 'navDropRow0' : 'navDropRow';
  81.     if( is.ns4 ){
  82.         return '<div class="' + cssClass + '"><a href="' + this.path + '">' + this.title.replace(/\s/gi, ' ') + '</a></div>\n';
  83.     }
  84.     else{
  85.         return '<div href="' + this.path + '" onclick="location.href=\'' + this.path + '\'" onmouseover="navDropOver(this)" onmouseout="navDropOut(this)" class="' + cssClass + '">' + this.title.replace(/\s/gi, ' ') + '</div>\n';
  86.     }
  87. }
  88.  
  89. function leftnavHTML(){
  90.     var html = '';
  91.     if( Nav.currentT1 ){
  92.         html += '<table width="178" border="0" cellpadding="0" cellspacing="0">'
  93.         + Nav.currentT1.leftnav()
  94.         + '</table><img src="/en/images/pixel.gif" width="1" height="40" border="0" alt=""><br>';
  95.     }
  96.     return html;
  97. }
  98.  
  99. function utilnavHTML(){
  100.     var html = '';
  101.     html += '<table width="178" border="0" cellpadding="0" cellspacing="0">'
  102.     + Nav.currentNav.utilnav()
  103.     + '</table>';
  104.     return html;
  105. }
  106.  
  107. Nav.prototype.getLeftnavCssClass = function(){
  108.     return ( this.isCurrent ) 
  109.         ? 'leftnavT' + this.tier + 'on' 
  110.         : 'leftnavT' + this.tier + 'off';
  111. }
  112. Nav.prototype.getLeftnavLineCssClass = function(i){
  113.     return( (i==0 && this.tier == 3)                                         // first of the tier 3's
  114.         ||    (this.tier == 2 && i>0  && this.parent.kids[i-1].isCurrent) )     // first of the tier 2's after the current
  115.         ? this.parent.getLeftnavCssClass() + 'Line'
  116.         : this.getLeftnavCssClass() + 'Line';
  117. }
  118.  
  119. Nav.prototype.leftnav = function(){
  120.     var html = '';
  121.     
  122.     if( this.tier > 1 ){
  123.         html += '<tr><td class="' + this.getLeftnavCssClass() + '" onclick="location.href=\'' + this.path + '\'"> <a href="' + this.path + '">' + this.title + '</a></td></tr>';
  124.     }
  125.     
  126.     if( this.isCurrent && this.tier < 3 ){
  127.         for( var i=0; i<this.kids.length; i++ ){
  128.             if( this.tier + i > 1 || this.isCurrent ){
  129.                 html += '<tr><td class="' + this.kids[i].getLeftnavLineCssClass(i) + '"><img src="/en/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
  130.             }
  131.             html += this.kids[i].leftnav();
  132.             
  133.             //if last & current, draw the line
  134.             if( this.kids[i].isCurrent && (this.kids.length -1 == i) ) html += '<tr><td class="leftnavT2onLine"><img src="/en/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
  135.         }
  136.     }
  137.     return html;
  138. }
  139.  
  140. Nav.prototype.utilnav = function(){
  141.     var tdClass = '';
  142.     var html = '';
  143.     var gotOne = false;    
  144.     
  145.     for( var i=0; i<Nav.root.kids.length; i++ ){
  146.     
  147.         if( Nav.root.kids[i].isUtilNav ){
  148.         
  149.             //if you're the first util nav, write a white line
  150.             if( Nav.root.kids[i].isCurrent && !gotOne  ) html += '<tr><td class="leftnavT2onLine"><img src="/en/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
  151.             
  152.             tdClass = ( Nav.root.kids[i].isCurrent ) ? 'leftnavT2on' :    'leftnavT2off';
  153.             
  154.             //links
  155.             html += '<tr><td class="' + tdClass + '" onclick="location.href=\'' + Nav.root.kids[i].path + '\'"> <a href="' + Nav.root.kids[i].path + '">' + Nav.root.kids[i].title + ' </a></td></tr>';
  156.             
  157.             //draw a line if your aren't last or your are current
  158.             if( i < Nav.root.kids.length-1 || Nav.root.kids[i].isCurrent ){
  159.                 // line is solid if you are current or next is current
  160.                 if( i < Nav.root.kids.length-1 && Nav.root.kids[i+1].isCurrent ) tdClass = 'leftnavT2on'    
  161.                 html += '<tr><td class="' + tdClass + 'Line"><img src="/en/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
  162.  
  163.             }
  164.         gotOne = true;
  165.         }
  166.     }
  167.     return html;
  168. }
  169.  
  170.  
  171. /********************************************************************************
  172.  
  173.     initialization
  174.  
  175. ********************************************************************************/
  176. Nav.init = function(){
  177.     for( var i=0; i<Nav.root.kids.length; i++ ){
  178.         Nav.root.kids[i].initT1();
  179.     }
  180. }
  181. Nav.prototype.initT1 = function(){
  182.  
  183.     this.thing = Thing.all['nav' + this.name];
  184.     if( ! this.thing ) return;
  185.     
  186.     this.thing.nav = this;
  187.  
  188.     if( this.isBig ){    
  189.         this.thing.captureMouseClick( thing_navMouseClick );
  190.         this.thing.captureMouseMove( thing_navMouseMove );
  191.         this.thing.captureMouseOut( thing_navMouseOut );
  192.         this.dropThing = Thing.all['navDrop' + this.name];
  193.         this.dropThing.moveTo( this.thing.position.add(0, 26) );
  194.         this.dropThing.nav = this;
  195.         this.dropThing.captureMouseMove(thing_navMouseMove);
  196.         this.dropThing.captureMouseOut(thing_navMouseOut);
  197.     }
  198.     else{
  199.         this.thing.captureMouseClick( thing_navSmallClick );
  200.         this.thing.captureMouseMove( thing_navSmallMove );
  201.         this.thing.captureMouseOut( thing_navSmallOut );        
  202.     }
  203.     if( this.isCurrent ){
  204.         this.thing.setBackground("#000000");
  205.         if( !this.isBig ) this.thing.div.className = 'navT1smallon';
  206.     }
  207. }
  208. init("Nav.init()");
  209.  
  210. /********************************************************************************
  211.  
  212.     mouse activity
  213.  
  214. ********************************************************************************/
  215. Nav.currDrop = null;
  216. Nav.prototype.setCurr = function(){
  217.     clearTimeout( this.hideTimeout );
  218.     clearTimeout( this.showTimeout );
  219.     if( Nav.currDrop && Nav.currDrop != this ){
  220.         Nav.currDrop.thing.hideNav();
  221.     }
  222.     Nav.currDrop = this;
  223.     this.showTimeout = setTimeout( this.dropThing.name + '.show()' , 100 );
  224.     if( is.ns4 ) this.hideTimeout = setTimeout( this.dropThing.name + '.hide()', 1250 );
  225. }
  226. Thing.prototype.showNav = function(){
  227.     this.setBackground("black");
  228.     this.nav.dropThing.name.show();
  229. }
  230. Thing.prototype.hideNav = function(){
  231.     if( ! this.nav.isCurrent ){
  232.         this.setBackground( "#002c84");
  233.     }
  234.     this.nav.dropThing.hide();
  235. }
  236.  
  237. function thing_navMouseClick(p){
  238.     location.href = this.nav.path;
  239.     return false;
  240. }
  241. function thing_navMouseMove(p){
  242.     this.nav.setCurr();
  243.     if( this.name == "nav" + this.nav.name ){
  244.         setStatusHref( this.nav.path );
  245.     }
  246.     return false;
  247. }
  248. function thing_navMouseOut(p){
  249.     clearTimeout( this.nav.hideTimeout );
  250.     clearTimeout( this.nav.showTimeout );
  251.     this.nav.hideTimeout = setTimeout( this.nav.thing.name + '.hideNav()', 100 );
  252.     return true;
  253. }
  254. function navMouseover(name){
  255.     if( Thing.all[name] ){
  256.         Thing.all[name].mouseMove();
  257.     }
  258. }
  259.  
  260.  
  261.  
  262. function thing_navSmallClick(p){
  263.     location.href = this.nav.path;
  264. }
  265. function thing_navSmallMove(p){
  266.     this.div.className = "navT1smallOn";
  267.     mouseover( this.name + "Img" );
  268.     setStatusHref(this.nav.path);
  269. }
  270. function thing_navSmallOut(p){
  271.     this.div.className = "navT1small";
  272.     mouseout( this.name + "Img" );
  273.     setStatusHref('');
  274. }
  275.  
  276.  
  277.  
  278.  
  279.  
  280. function navDropOver(who){
  281.     setStatusHref(who.href);
  282.     who.style.background = '#002c84';
  283. }
  284. function navDropOut(who){
  285.     setStatusHref('');
  286.     who.style.background = '#8AA8D8';
  287. }
  288.  
  289.  
  290.  
  291. function setStatusHref(url){
  292.     if( url != null && url != '' && url.indexOf("http://") != 0 ){
  293.         url = 'http://' + location.hostname + url;
  294.     }
  295.     status = url;
  296. }
  297.  
  298.