// LabAPI
var currPage;
var currPageContainer;
var previousPage;
var vispage;
var globalPage;
var appName = "index";
var ext = ".htm";
var ie = document.all ? true : false;
function versionChecker() {
  var check = true;
  var ver = parseFloat(navigator.appVersion);
  var app = navigator.appName;
  if ((ie) && (navigator.appVersion.indexOf("MSIE 5"))) { ver = 5; }
  if ((ie) || (app = "Netscape")) {
    if (ver < 5) { check = false; }
  }
  else {
    check = false;
  }  
  if (!check) {
    document.location.href = "../../../../../../PROGRAM/MULTIMEDIA LAB V/OldBrowser.htm";
  }
  if (navigator.platform.indexOf("Mac") != -1) { ie = false; }
}
function initPage() {
  versionChecker();
  if (ie) { document.body.scroll = "yes"; }
  currPage = document.getElementById("page");
  globalPage = document.getElementById("page");
  vispage = document.getElementById("page");
  if (currPage.childNodes.length > 0) {
    if ((ie) && (currPage.filters.length > 0)) {
      for (var i=0; i < currPage.filters.length; i++) {
        currPage.filters[i].apply();
        currPage.style.visibility = "visible";
        currPage.filters[i].play();
      }
    }
    else {
      currPage.style.visibility = "visible";
    }
  }
  var child = ie ? currPage.children : currPage.childNodes;
  for (var i = 0; i < child.length; i++) {
    child[i].oldStyle = new oldStyle(child[i]);
    child[i].resetStyle = getOldStyle;
    if (isMediaObject(child[i])) {
      setMediaObjectData(child[i]);
      if (child[i].AutoPlay == "true") {
        child[i].play();
      }
    }
  }
  for (var i=0; i < vispage.childNodes.length; i++) {
    if (vispage.childNodes[i].id) {
      setObjectMethods(vispage.childNodes[i]);
      if (ie) {
        if (vispage.childNodes[i].className == "group") {
          var group = vispage.childNodes[i];
          for (var j=0; j < group.childNodes.length; j++) {
            playTransition(group.childNodes[j].id);
          }
        }
        else {
          playTransition(vispage.childNodes[i].id);
        }
      }
      else {
        vispage.childNodes[i].style.visibility = "visible";
      }
    }
  }
  currPage.autoStart.run();
}
function getObject(object) {
  var ref = document.getElementById(object);
  if (ref) {
    if (ref.id == object) {
      return ref;
    }
  }
  else {
    return document;
  }
}
function visObj(object) {
  var ref;
  var ret = false;
  try {
    ref = document.getElementById(object);
    if (ref) {
      ret = true;
    }
  }
  catch (e) {
    ret = false;
  }
  return ret;
}
function isSoundObject(obj) {
  if (obj.className == "media") {
    var cobs = ie ? obj.children : obj.childNodes;
    return (cobs[0].className == "soundObject");
  }
  return false;
}
function isMediaObject(obj) {
  return (obj.className == "media");
}
function setMediaObjectData(obj) {
  if ((obj.className == "media") && (ie)) {
    var mObj;
    for (var i=0; i < obj.childNodes.length; i++) {
      if (obj.childNodes[i].tagName == "OBJECT") {
        mObj = obj.childNodes[i];
      }
    }
    obj.AutoRewind   = mObj.AutoRewind;
    obj.PlayCount    = mObj.PlayCount;
    obj.ShowControls = mObj.ShowControls;
    obj.obj   = mObj;
    obj.play  = function Play() {
      try {
        if (ie ? (obj.obj.PlayState != 6) : (obj.obj.GetPlayState() != 6)) {
         obj.obj.Play();
        }
      } catch (e) {}
    }
    obj.pause = function Pause() {
      try {
        if (ie ? (obj.obj.PlayState == 2) : (obj.obj.GetPlayState() == 2)) {
          obj.obj.Pause();
        }
      } catch (e) {}
    }
    obj.stop  = function Stop() {
      try {
        obj.obj.Stop(); obj.obj.SelectionStart = 0
      } catch (e) {}
    }
  }
  else {
    obj.play = function nofunc() {}
    obj.pause = function nofunc() {}
    obj.stop = function nofunc() {}
  }
}
function renderHtmlOnPage(page,src) {
  var re = /ID=\W(\w{1,})\W/g;
  var res = re.exec(src);
  var flag = false;
  if ((res == null) || (!vispage[res[1]])) {
    if (ie) {
      vispage.insertAdjacentHTML("beforeEnd",src);
    }
    else {
      var range = document.createRange();
      range.setStartAfter(vispage.lastChild);
      var docFrag = range.createContextualFragment(src);
      vispage.appendChild(docFrag);
    }
    if (ie) {
      playTransition(vispage.lastChild.id);
    }
    else {
      vispage.lastChild.style.visibility = "visible";
    }
    flag = true;
  }
  return flag;
}
function playTransition(obj) {
  var transObj;
  try {
    transObj = getObject(obj);
    var vis;
    if ((transObj.style.visibility == "visible") && (transObj.filters.length > 0)) {
      vis = "hidden";
    }
    else {
      vis = "visible";
    }
    for (var i=0; i < transObj.filters.length; i++) {
      transObj.filters[i].apply();
      transObj.style.visibility = vis;
      transObj.filters[i].play();
    }
  }
  catch (e) {
    // ignore
  }
}
function jumpToPage(page) {
  if (page == "Agderbotaniskeforening") {
    document.location.href = appName + ext;
  }
  else {
    document.location.href = appName + page + ext;
  }
}
function historyBack() {
  history.go(-1);
}
function previousPage() {
  jumpToPage(appPreviousPage);
}
function nextPage() {
  jumpToPage(appNextPage);
}
function oldStyle(obj) {
  if (ie) {
    style = obj.style;
    this.cssText = style.cssText;
  }
}
function getOldStyle() {
  if (ie) {
    this.style.cssText = this.oldStyle.cssText;
  }
}
function autoStartObject() {
  this.lines = new Array();
  this.add = autoStartAdd;
  this.run = autoStartRun;
}
function autoStartRun() {
  for (var i=0; i < this.lines.length; i++) {
    eval(this.lines[i]);
  }
}
function autoStartAdd(line) {
  this.lines[this.lines.length] = line;
}
function setObjectMethods(obj) {
  if (obj.id) {
    obj.incWidth = methodIncWidth;
    obj.incHeight = methodIncHeight;
    obj.incLeft = methodIncLeft;
    obj.incTop = methodIncTop;
    obj.rescale = methodRescale;
    obj.getAttr = methodGetAttr;
    obj.setAttr = methodSetAttr;
  }
}
function methodIncWidth(w) {
  var w2 = parseInt(this.style.width) + w;
  if (w2 >= 0) { this.style.width =  w2 + "px"; }
}
function methodIncHeight(h) {
  var h2 = parseInt(this.style.height) + h;
  if (h2 >= 0) { this.style.height = h2 + "px"; }
}
function methodIncLeft(l) {
  var l2 = parseInt(this.style.left) + l;
  if (l2 >= -32768) { this.style.left = l2 + "px"; }
}
function methodIncTop(t) {
  t2 = parseInt(this.style.top) + t;
  if (t2 >= -32768) { this.style.top = t2 + "px"; }
}
function methodRescale(wh) {
  this.incWidth(wh*2);
  this.incHeight(wh*2);
  this.incLeft(-wh);
  this.incTop(-wh);
}
function methodGetAttr(attrName) {
  var attrVal;
  if (visObj(this.id)) {
    try {
      attrVal = eval("this.style."+attrName);
    } catch (e) {}
  }
  return attrVal;
}
function methodSetAttr(attrName, attrVal) {
  if (visObj(this.id)) {
    try {
      eval("this.style."+attrName+" = '"+attrVal+"';");
    } catch (e) {}
  }
}
function incWidth(Obj, w) {
  var w2 = parseInt(getObject(Obj).style.width) + w;
  if (w2 >= 0) { getObject(Obj).style.width =  w2 + "px"; }
}
function incHeight(Obj, h) {
  var h2 = parseInt(getObject(Obj).style.height) + h;
  if (h2 >= 0) { getObject(Obj).style.height = h2 + "px"; }
}
function incLeft(Obj, l) {
  var l2 = parseInt(getObject(Obj).style.left) + l;
  if (l2 >= -32768) { getObject(Obj).style.left = l2 + "px"; }
}
function incTop(Obj, t) {
  t2 = parseInt(getObject(Obj).style.top) + t;
  if (t2 >= -32768) { getObject(Obj).style.top = t2 + "px"; }
}
function rescale(Obj, wh) {
  incWidth(Obj, wh*2);
  incHeight(Obj, wh*2);
  incLeft(Obj, -wh);
  incTop(Obj, -wh);
}
function getAttr(obj, attrName) {
  var attrVal;
  if (visObj(obj)) {
    try {
      attrVal = eval("getObject(obj).style."+attrName);
    } catch (e) {}
  }
  return attrVal;
}
function setAttr(obj, attrName, attrVal) {
  if (visObj(obj)) {
    try {
      eval("getObject(obj).style."+attrName+" = '"+attrVal+"';");
    } catch (e) {}
  }
}
function getSender() {
  try {
    return (ie ? window.event.srcElement : getObject(event.target));
  } catch (e) {  return null; }
}
