
var IE4 = (document.all && !document.getElementById) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
var IEmac = ((document.all) && (isMac)) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;
var NS4 = navigator.appName.indexOf("Netscape") != -1 && !NS6;

var twoD = 0;
var xStable = 0;
var prevnum = -1;
var whichAnim = "";
var animName;
var stopped = 0;
var animTime;
var tincTime;

function dragger(x) {
  if (whichAnim != "") {
    if (stopped == 0) {
      stopped = 1;
      animTime = parseFloat(String(vmp.GetProperty("MTSTimeElem." + whichAnim + "1", "time")));
      vmp.StopAnim("sliderAnim");
      vmp.StopAnim("sliderAnim2");
      vmp.StopAnim("sliderAnim3");
      vmp.StopAnim(whichAnim + "1");
      xStable = (parseFloat(String(vmp.GetProperty("MTSInstance.the_slider", "scl_")).split(" ")[1]) - 0.07519) * (-114);
      vmp.SetProperty(animName, "time", animTime, "mts_real");
      x = 0;
      }
    xStable = xStable + Number(x);
    vmp.SetProperty(animName, "tinc", x/tincTime, "mts_real");
    if (xStable > 0) { xStable = -1; }
    if (xStable < -143) { xStable = -142; }
    vmp.SetProperty("MTSInstance.the_slider", "scl_", "0.07519 " + (0.07519 - xStable / 114) + " 0.07519", "mts_pnt3d");
    }
  }


function sbar(num) {
//  if (prevnum != num || animD[num] == "2D") {
    vmp.StopAnim(anims[prevnum] + "1");
    whichAnim = anims[num];
    animName = "MTSTimeElem." + whichAnim;
    xStable = 0;
    vmp.SetProperty("MTSInstance.the_slider", "scl_", "0.07519 0.07519 0.07519", "mts_pnt3d");
    vmp.SetProperty(animName, "time", 0, "mts_real");
    vmp.TriggerAnim(animSlider[num]); 
    tincTime = animTinc[num]; 
    vmp.TriggerAnim(whichAnim + "1");
    stopped = 0;
    prevnum = num;
//    }
  }

function presbar(num) {
  vmp.SetProperty("MTSInstance.sliderbg", "clps", "0", "mts_int");
  vmp.SetProperty("MTSInstance.the_slider", "clps", "0", "mts_int");
  vmp.StopAnim("sliderAnim2");
  vmp.StopAnim("image_slider1");
  if (animD[num] != currD) { currD = animD[num]; vmp.TriggerAnim(animD[num] + "_forward"); setTimeout("sbar(" + num + ")", 1000); }
  else { sbar(num); }
  }


function annotClicked(num) {
  currD = aD[num];
  vmp.StopAnim("sliderAnim2");
  vmp.StopAnim("image_slider1");
  for (i = 0; i < annotArray.length; i++) {
    if (i != num && aD[i] != aD[num]) {
      removeAnnot(num);
      }
    }
  if (aD[num] == "2D") { 
    vmp.SetProperty("MTSInstance.hip","clps","1","mts_int");
    vmp.SetProperty("MTSInstance.image_plane","clps","0","mts_int"); 
    vmp.ResetAnim("image_slider");
    vmp.SetProperty("image_slider", "time", annotTime[num], "mts_real");
    whichAnim = "image_slider";
    animName = "MTSTimeElem." + whichAnim;
    vmp.SetProperty("MTSInstance.the_slider", "scl_", "0.07519 " + annotScale[num] + " 0.07519", "mts_pnt3d");
    xStable = annotXstable[num];
    tincTime = annotTinc[num];
    stopped = 1;
    x = 0;
    vmp.SetProperty("MTSInstance." + annotVisb[num],"visb","1","mts_int");
    vmp.SetProperty("MTSInstance." + annotVisb[num] + "b","visb","1","mts_int");
    vmp.SetProperty("MTSInstance." + annotClps[num],"clps","0","mts_int");      
    setTimeout("removeAnnot(" + num + ")", 5000);
    }
  else {
    vmp.SetProperty("MTSInstance.hip","clps","0","mts_int");
    vmp.SetProperty("MTSInstance." + annotClps[num],"clps","0","mts_int");  
    vmp.SetProperty("MTSInstance." + annotVisb[num],"visb","1","mts_pnt");
    vmp.SetProperty("MTSInstance." + annotVisb[num] + "b","visb","1","mts_pnt");
    setTimeout("removeAnnot(" + num + ")", 5000);
    }
  }

function removeAnnot(num) {
  if (aD[num] == "2D") { 
    vmp.SetProperty("MTSInstance." + annotVisb[num],"visb","0","mts_int");
    vmp.SetProperty("MTSInstance." + annotVisb[num] + "b","visb","0","mts_int");
    vmp.SetProperty("MTSInstance." + annotClps[num],"clps","1","mts_int");      
    }
  else {
    vmp.SetProperty("MTSInstance." + annotVisb[num],"visb","0","mts_int");
    vmp.SetProperty("MTSInstance." + annotVisb[num] + "b","visb","0","mts_int");
    }
  }

function preAnnotClicked(num) {
  if (aD[num] != currD) { vmp.TriggerAnim(aD[num] + "_forward"); setTimeout("annotClicked(" + num + ")", 1000); }
  else { annotClicked(num); }
  }


// Preload the images (for page numbers)
// for(var i=1; i <= max_pages; i++){
//   eval("var pageNum" + i + " = new Image();");
//   eval("pageNum" + i + ".src = '../images/num_" + i + ".jpg'"); 
//   }

// Preload the spacer
// var myspacer = new Image();
// myspacer.src = '../images/spacer.gif';

// function sBack() {
//   if (curr_page > 1) {
//    prev_page = curr_page;
//    curr_page--;
//    setPage();
//    }
//  }

function sForward() {
  if (curr_page < max_pages) {
    prev_page = curr_page;
    curr_page++;
    setPage();
    }
  }

function setPage() {
  eval("document.pagenum.src = pageNum" + curr_page + ".src");
  myFunc(HTMLText[curr_page], "HTML");
  }

function NSinnerHTML() { 
  this.document.open(); 
  this.document.write(arguments[2]); 
  this.document.close(); 
  return arguments[2]; 
  } 

function myFunc(myVar, layer){
  if (NS4) {
    if (layer == "HTML") {
      document.layers["HTML"].innerHTML = ""; 
      document.layers["HTML"].watch("innerHTML",NSinnerHTML); 
      document.layers["HTML"].innerHTML = myVar; 
      }
    else if (layer == "DefLayer") {
      document.layers["DefLayer"].innerHTML = ""; 
      document.layers["DefLayer"].watch("innerHTML",NSinnerHTML); 
      document.layers["DefLayer"].innerHTML = myVar; 
      }
    }
  if (IE4 || IE5) {
    document.all[layer].innerHTML=myVar;
    }
  if (NS6) {
    document.getElementById(layer).innerHTML = myVar;
    }
  }

function showDef(text, top, left, width, height) { 
  if(IE4||IE5) { top = top - 25; }
  if (IEmac) { top = top - 50; height = height + 25; }
  if (!NS4) {
    resizeLayer("DefLayer", top, left, width, height);
    }
  myFunc(DefText[text], "DefLayer"); 
  MTSshowHideLayers("DefLayer"); 
  if (IE5||NS6) {
    document.getElementById("DefLayer").style.border = "0.01cm solid black";
    document.getElementById("DefLayer").style.padding = "0.05cm";
    }
  }
function hideDef() { MTSshowHideLayers('', 'DefLayer'); }

function resizeLayer(layername, top, left, width, height) {
  var doclay, styl;
  if (NS4) { doclay = "document.layers[\'"; styl = "\']"; }
  if (IE4 || IE5) { doclay = ""; styl=".style"; } 
  if (NS6) { doclay = "document.getElementById(\'"; styl = "\').style"; }
  eval(doclay + layername + styl + ".top = " + top);
  eval(doclay + layername + styl + ".left = " + left);
  eval(doclay + layername + styl + ".width = " + width);
  eval(doclay + layername + styl + ".height = " + height);
  }



