var MyMenus = new Array();
var MenuVisCount = 0;
var MyTimer;          // timer for menu
var MyTTimer;         // timer for ticker
var FswfOK = 0;       // can we 'do' Flash??
var isPageReady = 0;  // some browsers with no Flash don't seem to finish the page load.
var keepMenuOn = 0;   // a variable which resets Viscounter if true.

/* execute this first (thnx2mm) */

if (!document.all && navigator.plugins && navigator.plugins.length > 0) {
  // Mozilla
  if (navigator.plugins["Shockwave Flash"]) {
    var plugin_version = 0;
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");

    for (var i = 0; i < words.length; ++i) {
      if (isNaN(parseInt(words[i]))) {
	continue;
      }
      plugin_version = words[i];
    }
    if (plugin_version >= 6) {
      FswfOK = 0;
    }
//    alert("Version: " + plugin_version);
  }
}else {
  // IE
  FswfOK = 1;
}

function SetMenus(ndivs) {
  /*    browser specifics -- try to cope with older browsers   */
  for (i=0;i<ndivs;i++) {
    var objName = "sm" + i;
    var MyObject = new Object();
    if (document.all) {
      //alert("using all");
      MyObject = document.all[objName].style;
    } else if (document.layers) {
      MyObject = document.layers[objName];
      // NS only: shunt the object down to a reasonable place!
      MyObject.moveBy(0,160);
    } else if (document.getElementById) {
      //alert("using getbyid");
      MyObject = document.getElementById(objName).style;
    } else {
      // Arrrgh, can't do, or will have to suck it and see.
      alert("Your browser cannot be recognised. \nThe menus may not function correctly. ");
    }
    MyMenus[i] = MyObject;
  }
  isPageReady = 1;
}

function MenuOn(menu) {
  if (isPageReady == 1) {
    MyMenus[menu].visibility = "visible";
    MenuVisCount = 4;
    ToZero();
  }else {
    /* this is a fudge to get around that non-loading "feature"
    seen when you have  IE with no Flash plugin. The non-loading
    means my page never fires the onLoad event, so we'll try calling 
    it again here, but we'll have a delay as well in case it goes into a loop. */
    // show this notice if you want to alert users. // alert("Page not yet loaded.\nSetting up menus anyway ...");
    setTimeout('Dummy()',500);
    SetMenus(numDivs);
  }
}

function MenuPreserve() {
  keepMenuOn = 1;
}

function MenuFragile() {
  keepMenuOn = 0;
}

function MenusOff() {
  // all menus off
  if (isPageReady == 1) {
    for (var i=0;i<MyMenus.length;i++) {
      MyMenus[i].visibility = "hidden";
    }
    // logically, clear any outstanding timeouts here
    keepMenuOn = 0;
    clearTimeout(MyTimer);
  }
}

function ToZero() {
  if (isPageReady == 1) {
    if (keepMenuOn == 1) {
      MenuVisCount = 4;
    }
    if (MenuVisCount > 0) {
      MenuVisCount--;
      MyTimer = setTimeout('ToZero()',500);
    }else {
      MenusOff();
    }
  }
}

function AddToCounter(a) {
  if (isPageReady == 1) {
    if (MenuVisCount < 3) {
      MenuVisCount += a;
    }
  }
}

function Dummy() {
  return true;
}

function TickerTapeRun(f) {
  // fix MOzilla reload feature (i.e. form does not reset if changed by JavaScript)
  f.reset(); 
  var TTstr = f.ttbox.value;

  // first, pad the field to 50 characters if it is not already.
  // if its greater, thats OK.
  if (TTstr.length < 60) {
    for (var i=TTstr.length;i<=50;i++) {
      TTstr += " .";
    }
  }else {
      TTstr += " . . . . . . . . ";
  }
  f.ttbox.value = TTstr;

  setTimeout('AdvTicker()',200);
}


function AdvTicker(a) {
  var Myttstr = document.ttnoform.ttbox.value;
  var l = Myttstr.length;
  Myttstr = Myttstr.substring(1,l) + Myttstr.substring(0,1);
  document.ttnoform.ttbox.value = Myttstr;
  if (a != 1) {
    MyTTimer = setTimeout('AdvTicker()',180);
  }
}

function EndTicker() {
  clearTimeout(MyTTimer);
}




