// set the images on the left side of the page
function loadSideImages() {
  // check browser can do this
  if (document.images) {
    // array for the used images
    used = "";
    // loop until we have three
    count = 1;
    while (count <4) {
      // create the random number
      randomNum = Math.round((Math.random()*9));
      // check we have not used this number before
      if (used.indexOf(randomNum)==-1) {
        // tag the number as used
        used += randomNum;
        // set the image
        document.images["side"+count].src = "./image/side_image_"+randomNum+".jpg";
        // move to next image
        count++;
      }
    }
  }
}

// show the name of the page
function getPageName(){
  // path to this page
  var path = location.pathname ;
  // seperator
  var sep = '/' ;
  // change, if viewing locally
  if (path.indexOf('\\')>-1) sep = '\\';
  // get the start and end of the page name
  var pbeg = path.lastIndexOf(sep) ;
  var pend = path.lastIndexOf('.') ;
  pbeg = (pbeg == -1)? 0 : pbeg +1 ;
  var plen = (pend == -1) ? path.length - pbeg : pend - pbeg ;
  // extract the page name
  page = path.substr(pbeg,plen) ;
  // return the result
  return page;
}

// page name
var pageName = getPageName();

// output the menu
function buildMenu(mPage, mTitle, mTip) {
  if (pageName != mPage) {
    // visible link
    document.write("<div class=\"navigation\"><a class=\"navLink\" title=\"");
    document.write(mTip);
    document.write("\" href=\"./");
    document.write(mPage);
    document.write(".html\">");
    document.write(mTitle);
    document.write("</a></div>");
  } else {
    // selected link
    document.write("<div class=\"navigationS\">");
    document.write(mTitle);
    document.write("</div>");
  }
}

// load the page stuff
function setupPage() {
  loadSideImages();
}