/*
Copyright (c) 2006 Ylab, http://www.ylab.nl
2006-07-06; adapted for Annemarike.com
*/

//trap error
window.xonerror = function(msg, url, line){
  window.status = "Er is een fout opgetreden. Meld dit a.u.b. aan de webmaster. " + line + ": " + msg;
  return true;
}

var debugging = false;
var isOpera = (navigator.userAgent.indexOf("Opera") > -1);
var isNav = ((!isOpera) && (navigator.appName == "Netscape"));
var isIE  = ((!isOpera) && (navigator.appName.indexOf("Explorer") > -1 ));
//var isMac = ((isIE) && navigator.userAgent.indexOf("Mac") > -1));

var paneL;
var loadFunctions = new Array();
function addLoadFunction(f)  {loadFunctions[loadFunctions.length] = new Function(f);}
window.onload   = function() {for (var i=0; i<loadFunctions.length; i++){loadFunctions[i]();}}
addLoadFunction('initDocument();');

//init document
function initDocument(){
  window.status = document.title;
  paneL = id2object('paneL');
  resize();
}
window.onresize = function (){
  resize();
}
function resize(){
  if(!paneL){return;}
  var viewport = new Viewport();
  paneL.style.height = viewport.y - 20 + 'px';
}
//display mailto link
function printMail(username, linktext){
  username = username.toLowerCase() + "@annemarike.com";
  if (!linktext) {linktext = username;}
  document.write(linktext.link("mailto:" + username));
}

//Convert id into object
function id2object(el){
  if (typeof(el)=="string"){el = document.getElementById(el);}
  return el;
}

function Viewport(){
  this.x = 0;
  this.y = 0;
  if (self.innerHeight) {
    // all except Explorer
  	this.x = self.innerWidth;
  	this.y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight){
    // Explorer 6 Strict Mode
  	this.x = document.documentElement.clientWidth;
  	this.y = document.documentElement.clientHeight;
  }
  else if (document.body){
    // other Explorers
  	this.x = document.body.clientWidth;
  	this.y = document.body.clientHeight;
  }
}

function Page(){
  var x,y;
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight;
  if (test1 > test2) {
    // all but Explorer Mac
  	x = document.body.scrollWidth;
  	y = document.body.scrollHeight;
  }
  else  {
     // Explorer Mac;
       //would also work in Explorer 6 Strict, Mozilla and Safari
  	x = document.body.offsetWidth;
  	y = document.body.offsetHeight;
  }
  this.x = x;
  this.y = y;
}

//preload hover images when document is loaded
var hoverImages = new Array();
addLoadFunction("if (hoverImages.length==0){return;} for (var i=0; i<hoverImages.length; i++){(new Image()).src = hoverImages[i];}");

/*Prepare image for hover effect
  Sample use:
  <img onload="imgHover('img01')">
  <img onload="imgHover(this)">
  <img onload="imgHover(this, 'hover.gif')">
  <img onload="imgHover(this, 'text=image')">

  img: image object or image id;
  srcHover: url of hover image [optional]
           : when omitted, the postfix "-hover" is added to the original image path
           : when containing an is-character (=) a part of the original url is altered (e.g. 'text=image')
*/
function imgHover(img, srcHover, hotspot){
  //Initialize only once
  img = id2object(img);
  if (img.initialized){return;}

  //Set properties
  img.initialized = true;//been here
  img.srcNormal = img.src;
  if (srcHover){
    if (srcHover.indexOf("=") != -1){
      //replace part of original url
      var pair = srcHover.split("=");
      img.srcHover=img.src.replace(pair[0],pair[1])
    }
    else{img.srcHover = srcHover;}
  }
  else{
    //add -hover by default
    var extpos = img.src.lastIndexOf(".");
    img.srcHover = img.src.substring(0,extpos) + "-hover" + img.src.substring(extpos);
  }
  hoverImages[hoverImages.length] = img.srcHover;
  //Assign hotspot events
  if (arguments.length < 3){var el=img;}
  else {var el = id2object(hotspot)}
  el.onmouseover = function() {img.src = img.srcHover;}
  el.onmouseout  = function() {img.src = img.srcNormal;}

}

//DEBUGGING
function devAlert(){
  if (!debugging){return;}
  var code = "Deze functie is nog niet ge"+String.fromCharCode(239)+"mplementeerd.\n";
  for(var i=0; i < arguments.length; i++) {
    code += arguments[i] + "\n";
  }
  alert(code);
}

function debugAlert(){
  if (!debugging){return;}
  var code = "";
  for(var i=0; i < arguments.length; i++) {
    code += arguments[i] + "\n";
  }
  window.status = code;
  alert(code);
}
function debugConfirm(){
  if (!debugging){return;}
  var code = "";
  for(var i=0; i < arguments.length; i++) {
    code += arguments[i] + "\n";
  }
  window.status = code;
  return confirm(code);
}