<!--

// showlinks.js
// This enables a long list of links to be broken up into different categories.

// (c)2004 Mark Hennessy - http://www.mhennessy.f9.co.uk/


//    Version 0.4 - highly experimental! Copying this is allowed as long as
//    it is unmodified (including these comments). Of course, you should
//    change the links/text at the end of the page to suit your needs...

// The arrays are set up in a seperate .js file. A 'please wait'
// message is displayed in the normal html. OnLoad="ShowLinks(0)" in the
// html head causes the 'Please choose...' message to be displayed. Also, a
// flag is set to tell the function that the page has loaded. This stops
// users clicking on the category links before the page has loaded...


lnk = new Array()  //Link name. This text is within the <a> tags
txt = new Array()  //Optional text to describe the link (appears in normal text colour)
url = new Array()  //URL of link, *** defines last entry
img = new Array()  //Optional picture to go with a link

maxlinks=100            //Max no. of links - used to catch a missing *** entry
max_cats=25             //Number of categories

OpenTxt   = "Preview";  //Text that appears next to site
CloseTxt  = "Close";    //Text that appears when site preview is active
WinHeight = "200";      //Height of preview window
WinWidth  = "93%";      //Width of preview window

Pv_flag   = 0           //Flag - set to enable previewing.
if (document.all)
  Pv_flag = 1;          //Unbelievably crude browser check!


for (i=0; i<=max_cats; i++) {  //define 3D arrays
  lnk[i]=new Array()
  txt[i]=new Array()
  url[i]=new Array()
  img[i]=new Array()
  for (j=0; j<=maxlinks; j++) {  //define array elements
    lnk[i][j]=""
    txt[i][j]=""
    url[i][j]=""
    img[i][j]=""
    }
 }
page_loaded = 0 //Flag - prevents ShowLinks() from trying to display anything
                //until ShowLinks(0) has been called (by onLoad event)

function ShowLinks(cat) {
  if (cat == 0) page_loaded=1;  // Set flag
  if (cat <= max_cats) {
    if (page_loaded != 0) {
      var num = 1;
      var num_txt = "";
      var onscreen = "";

      while ( url[cat][num] != "***" ) {

        if (url[cat][num] != "-" ) {
          onscreen += "<li><a href=" + url[cat][num] + " target=\"_blank\">";
          if (img[cat][num] != "") {
            onscreen += "<img src=\"img/links/" + img[cat][num] + "\"  border=\"0\">"; //Image
            }
          onscreen += "<b>" + lnk[cat][num] + "</b></a>"
          
          if (Pv_flag == 1) {  //Are we allowing a "preview" link?
            onscreen += " - <font size=\"-2\"><a id=\"" + cat + num + "\" onclick=\"parent.Preview(this);return false\" href=\"" + url[cat][num];
            onscreen += "\">" + OpenTxt + "</a></font>";
            }

          if (txt[cat][num] != "") {  //Is there a comment for this site?
            onscreen += "<br>" + txt[cat][num] + "<br>&nbsp;";  //Yes
            }
            else {
              onscreen += "<br>&nbsp;"; //Space to ensure a blank line
              }
          onscreen += "</li>";   //Finish the list item
          }
        else {
          onscreen += "</ul><p><b>" + txt[cat][num] + "</b></p><ul>"; //Deal with category divider
          }

        num += 1;
        if (num > maxlinks)
          url[cat][num]="***";  //Catch missing ***
        }
   document.getElementById("link_title").innerHTML = "<b>" + num_txt + txt[cat][0] + "</b>";
   document.getElementById("link_list").innerHTML  = "<ul>" + onscreen + "</ul>";
   }
  }
 }

// This deals with the "preview" option:

function Preview(url){
    var preview = document.all['pv'+url.id];

    if (url.innerText == OpenTxt) {      //Open preview
        url.innerText = CloseTxt;        //Change text
        if (!preview) {                      //"preview" not defined first time
          url.insertAdjacentHTML("AfterEnd", "<IFRAME id=pv" + url.id + " width=" + WinWidth + " height=" + WinHeight + " SRC='" + url.href + "'></IFRAME>");
          }
        else {                           //Use once "preview" is defined
          preview.style.height = WinHeight;
          preview.style.visibility = "visible";
          preview.src = url.href;
          }
        }
    else {                               //Close preview
      if (preview) {
        preview.style.visibility = "hidden";
        preview.style.height = 0;
        preview.src = "about:blank";
        url.innerText = OpenTxt;
        }
      }
    }

// -->

