window.onerror = null;

  var clues;
 
  // Check browser type
  var bName = navigator.userAgent;
  var bVer = parseInt(navigator.appVersion);
  var is_netscape = ((bName.indexOf("Mozilla") != -1) && (bName.indexOf("compatible") == -1));
  var is_mac = (bName.indexOf("Mac") != -1);

  var browser;
  if (is_netscape && bVer >= 5) browser = "n5";
    else if (is_netscape && bVer >= 4) browser = "n4";
    else if (is_netscape && bVer >= 3) browser = "n3";
    else if ((bName.indexOf("MSIE") != -1) && bVer >= 4 && document.all) browser = "e4";
    else browser = "other";

  function start() { };

  var started;
  started = 0;


clues = new Array();

// Test cookie support
var hasCookies;

document.cookie = "test-cookie=1";
cookie = document.cookie;
hasCookies = (cookie.indexOf("test-cookie", 0) != -1);


function getkey() {
  var key = "@hint" + location.href.substring(location.href.lastIndexOf("/") + 1);
  if (key.indexOf("?", 1) != -1) {
    key = key.substring(0, key.indexOf("?", 1));
  }
  return key + "=";
}


function gethint() {
  cookie = document.cookie;
  cookiekey = getkey();

  if (cookie != "" && cookie.indexOf(cookiekey) != -1 && hasCookies) {
    wherehint = (cookie.indexOf(cookiekey) + cookiekey.length);
    if (cookie.indexOf(";", wherehint) != -1) {
      cookie = cookie.substring(0, cookie.indexOf(";", wherehint));
    }
    line = cookie.substring(wherehint);

    thishint = new Number(line);

  }

  return thishint;
}


function sethint() {
  if (browser == "o3") {
    newhint = 1 * gethint() + 1;
  }
  else {
    newhint = Number(gethint()) + 1;
  }

  document.cookie = getkey() + newhint;
}


function start() {
  if (started == 0) {

    if (pagehint > 0) {
	thishint = new Number(pagehint);
        document.cookie = getkey() + thishint;
    }
    else {
        thishint = 1;
    }

    showhint();

    started = 1;
  }
}


function scrollToEnd() {
  if (browser == "e4") {
    scrollto = 0;
    oparent = document.getElementById("uponelevelbox");

    while (oparent != document.body) {
      scrollto += oparent.offsetTop;
      oparent = oparent.offsetParent;
    }

    var nexthintbox = document.getElementById("nexthintbox");

    scrollto += nexthintbox.offsetHeight - document.documentElement.clientHeight + 20;

    window.scroll(0, scrollto);
  }

    if (browser == "n4") {
      scrollto = document.layers.outerhints.pageY - window.innerHeight + 50;
      window.scroll(0, scrollto);
    }

    if (browser == "n5") {
      var d = document.getElementById("uponelevelbox");
      scrollto = d.offsetTop - window.innerHeight + d.offsetHeight + 20;
      window.scroll(0, scrollto);
    }

}

function showhint() {
  var thishint = gethint();

  output = "";

  for (i = 0; i < thishint && i < maxhint; i++) {
      document.getElementById("clue" + i).style.display = "block";
  }

  document.getElementById("currenthint").innerHTML = thishint;
  if (thishint >= maxhint) {
	document.getElementById("morehints").style.display = "none";
	document.getElementById("nomorehints").style.display = "block";
  }
  
  scrollToEnd();

}


function nexthint() {
  sethint();

  if (!hasCookies) {
    newurl = "" + location.href;
    if (newurl.indexOf("?", 1) != -1) {
      newurl = newurl.substring(0, newurl.indexOf("?", 1));
    }
    location.replace(newurl + "?hint=" + (gethint() + 1));
  }
  else {
    showhint();
  }
}
