/*
Generic functions for www.kindermonument.nl
Copyright (c) 2003 Ylab, Utrecht, NL
Author: Yohan Creemers
version 1.6
1.1: Added event handling
1.2: Added propertie handling (style, top and height)
1.3: Set document title in status bar
1.4: Hide horizontal scrollbar in msie 5.5+
     Added printMail()
1.5: Added generic relativeRoot() function
1.6: Added printAge() function
*/

//generic event handling
window.onerror = reportError;
function reportError(msg, url, line){
  window.status = "Er is een fout opgetreden. Meld dit a.u.b. aan de webmaster. | " + line + ": " + msg;
  return true;
}



var scrollFunctions = new Array();
function addScrollFunction(f){scrollFunctions[scrollFunctions.length] = new Function(f);}
window.onscroll = function() {for (var i=0; i<scrollFunctions.length; i++){scrollFunctions[i]();}}  

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("window.status = document.title;");


var isOpera = (navigator.userAgent.indexOf("Opera") > -1);
var isNav = ((!isOpera) && (navigator.appName == "Netscape"));
var isIE  = ((!isOpera) && (navigator.appName.indexOf("Explorer") > -1 ));
var versionMajor = parseInt(navigator.appVersion);
if (isOpera){ var versionMinor = parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")+6));}
else if (isIE){ var versionMinor = parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5));}
else{ var versionMinor = parseFloat(navigator.appVersion);}
//test for not supported browsers
if ((isIE) && (versionMinor < 5) || (isNav) && (versionMinor < 5) || (isOpera) && (versionMinor <= 6)){
  location.replace("/default.htm");
}



//hide horizontal scrollbar
if ((isIE) && (versionMinor > 5)){addLoadFunction("document.body.style.overflowX = 'hidden';");}



/*display mailto link
  Sample use:
  printMail("dick");
  printMail("dick", "Beheerder");
  
  username: the username part of the email address
  linktext: the visible text of the hyperlink [optional]
*/
function printMail(username, linktext){
  username = username.toLowerCase() + "@vakantiehuis-az25.nl";
  if (!linktext) {linktext = username;}
  document.write(linktext.link("mailto:" + username));
}

function relativeRoot(){
  //determine directory level (count slashes) 
  if (!window.location.pathname) return "/";
  var curPath = (new String(window.location.pathname)).split("\\").join("/");
  /*
  var relPath = "";
  var n = (window.location.protocol == "file:") ? -4 :  -2;
  if (isOpera && window.location.protocol == "file:"){n++}
  for (var i=0; i<curPath.length; i++){
    if (curPath.substring(i,i+1) == "/"){n++;}
  }
  for (var i=0; i<n; i++){relPath += "../";}*/
  var relPath = "/";
  var pos = curPath.indexOf("/dev/");
  if (pos > -1){relPath = curPath.substring(0, pos + 5);}
  return relPath;
}


/*Define Slideshow object
  Sample use:
  var show1 = new Slideshow("show1",2,4);
  show1.addItem("../images/logo.gif", "Ylab, Design for new media");
  <img onload="show1.initialize(this)">
  
  objectName: name of the object
  delay: initial delay in seconds [optional, defaults to 3 seconds]
  interval: seconds between two slides [optional, defaults to 3 seconds]
*/
function Slideshow(objectName, delay, interval){
  //Define properties
  this.name = objectName;
  this.delay = (!delay ? 3 : delay);
  this.interval = (!interval ? 3 : interval);
  this.init = false;
  this.img_sources = new Array();
  this.img_decriptions = new Array();
  this.imagearray = new Array();
  this.nLoadedImages = -1;
  this.nDefinedImages = -1;
  this.counter = 0;

  //Define methods
  this.addItem = method_AddItem;
  this.initialize = method_Initialize;
  this.preloadImage = method_PreloadImage;
  this.slideNext = method_Slidenext;
  this.showPicture = method_ShowPicture;

  //METHODS
  //Add a slide to the show
  //image_src: path to the image
  //image_alt: descriptive text 
  function method_AddItem(image_src, image_alt) { 
    this.nDefinedImages++;
    this.img_sources[this.nDefinedImages]=image_src;
    this.img_decriptions[this.nDefinedImages]=image_alt;
  }
  
  //initialization
  //img: image object in the html page <img>
  function method_Initialize(img){
    //run only once
    if (this.init || !document.images) {return;}
    this.init = true; //been here
    
    this.slide=img;
    //put current images at the end of the image-array 
    this.addItem(this.slide.src,this.slide.alt);
    //try to set filter
    if (this.slide.filters){this.slide.style.filter="blendTrans(duration=1)";}
    
    //Cache next slide
    this.preloadImage();
    //Set time for first transition
    var code = this.name + ".slideNext()";
    setTimeout(code, this.delay*1000);
  }
  
  //Cache images
  function method_PreloadImage() { 
    if (!document.images) {return;}
    this.nLoadedImages++;
    this.imagearray[this.nLoadedImages] = new Image; 
    this.imagearray[this.nLoadedImages].src = this.img_sources[this.nLoadedImages];
  }
  
  //Define what's the next image
  function method_Slidenext(){
    if (!document.images) {return;}
    if (this.counter < this.nLoadedImages) {this.counter++;}
    else {this.counter = 0;}
    this.showPicture();
  }
  
  //Replace picture by the next one
  function method_ShowPicture(){
    if (!document.images) {return;}
    if (this.slide.filters){this.slide.filters.blendTrans.apply();}
    this.slide.src=eval("this.imagearray["+this.counter+"].src");
    if (this.slide.filters) {this.slide.filters.blendTrans.play();}
    this.slide.alt=this.img_decriptions[this.counter];

    //Cache next slide (if neccessary)
    if (this.nLoadedImages < this.nDefinedImages){this.preloadImage();}
    //Schedule next transition
    var code = this.name + ".slideNext()";
    setTimeout(code,this.interval*1000);
  }
}

