  /* mouseover_formulamazda.js
  /*************************************************************
   *
   * Highlight by Directory
   * 
   * The purpose of this code is to automatically
   * highlight the nav image corresponding to the
   * current top-level directory.
   *
   * To use, include a call to highlightCurrent() in
   * the onload event of the <body> tag.
   *
   * There are 3 customization points (each is marked with
   * "customize:"):
   *
   * 1. myImgs array
   * 2. validIndexPages array
   * 3. which element (maps to directory level) of the urlSplit
   *    array to use.
   *************************************************************/
   

  /*-----------------------------------------------------------* 
   * Create image objects and preload images.
   *
   * customize:
   *
   * Your images must follow the naming convention of
   * [directory]_on.gif and [directory]_off.gif. You
   * will also use [directory] as the name/id of the
   * image in the IMG SRC tag.
   *
   * Create an element in the myImgs array for each directory
   * we need to deal with. Also provide the path to the images
   * for the imagesURL variable.
   *
   *-----------------------------------------------------------*/
   
  var myImgs = new Array("home","site","architects","design","construction","progress","team", "trull_school","contact");
  var imagesURL = "/images/menu/";
  
  for(var x = 0; x<myImgs.length; x++) {
   eval(myImgs[x]+"on = new Image();");
   eval(myImgs[x]+"on.src = imagesURL+myImgs[x]+'_on.gif'");
   eval(myImgs[x]+"off = new Image();");
   eval(myImgs[x]+"off.src = imagesURL+myImgs[x]+'_off.gif'");
  }

  /*-----------------------------------------------------------*   
   * Image Switch Functions
   *-----------------------------------------------------------*/

  var currentlyOn = null;

  function imgOn(imgName) {
    if( document.images ) {
      if( document[imgName] ) {
        document[imgName].src = eval(imgName + "on.src");
      }
    }
  }

  function imgOff(imgName) {
    //var i = new String(document[imgName].src);
    if( document.images ) {
      if( document[imgName] && (imgName != currentlyOn) ) {
        document[imgName].src = eval(imgName + "off.src");
      }
    }
  }
  
  /*-----------------------------------------------------------*
   * highlightCurrent Function
   *-----------------------------------------------------------*/  
 
  /**
   * Valid Index Pages
   *
   * customize:
   *
   * This array holds values for valid index page names.
   * The highlightCurrent() script checks to see if the
   * value it has found for top-level directory matches
   * one of the items in this list. If so, it will
   * highlight the "home" image. Be sure your index page
   * name with its file extention is in there. Ie: if 
   * your home page is index.shtml, you'll need to add a
   * line for that filename in this array.
   */
  var validIndexPages = new Array();
  
  validIndexPages["index.php"]      = 1;
  validIndexPages["index.cgi"]      = 2;
  validIndexPages["index.html"]     = 3;
  validIndexPages["index.htm"]      = 4;
  validIndexPages["template.html"]  = 6;

  
  function highlightCurrent() {
    /** 
     * grab the current url, ie: "http://foo.com/about/index.html"
     */       
    url = document.location.href;
    
    /** 
     * find the "//" in the url, if present.
     */   
    i = ( url.indexOf("//") + 2 );    
    if( i > 1 ) {
    
      /** 
       * get a substring of the url from "//" to
       * the end of the url string, ie: "foo.com/about/index.html"
       */       
      url = url.substr(i,url.length);
      
      /** 
       * the split function returns an array of strings
       * using the "/" to break up the original.
       *
       * Ie: for foo.com/about/index.html
       *    urlSplit[0] = "foo.com"
       *    urlSplit[1] = "about"
       *    urlSplit[2] = "index.html"
       * 
       */ 
      urlSplit = url.split("/");
      
      /** 
       * Attempt to get the top-level directory, ie: "about"
       *
       * customize:
       *
       * If you wish to highlight based on a second or third
       * level directory, modify the element you are looking
       * for in the urlSplit array accordingly below. For 
       * example, if your URLs look like:
       *
       *  http://foo.com/test/company/index.html
       *
       * ...then your urlSplit array will look like:
       *
       *    urlSplit[0] = "foo.com"
       *    urlSplit[1] = "test"
       *    urlSplit[2] = "company"
       *    urlSplit[3] = "index.html"
       *
       * ...so modify the code below to look for urlSplit[2]
       * to return "company" as our image.
       *
       */ 
      if( urlSplit[1] ) {     
        url = urlSplit[1];
        /**
         * It's possible that when we're on the
         * home page, we'll get a return like
         * "index.html" if our original URL looked
         * like: "http://foo.com/index.html". Here, we
         * check to see if our return matches one of 
         * the acceptable index page values defined in
         * the validIndexPages array above. If so, we
         * set url = "home".
         */
         if( validIndexPages[url] ) {
            url = "home";
         } else {
            urlSplit = url.split(".");
            url = urlSplit[0];
         }
      }
      else {
        /** 
         * No top-level directory present in URL,
         * so set url for the home image. This case
         * should only occur when the original URL
         * looks like "http://foo.com/"
         */
        url = "home";
      }

      /**
       * Do the highlight
       */
      currentlyOn = ( url );
      imgOn( url );
      
    // ends check for "//"
    }
  }