var PreloadImgLst = new Array();


function StartZoeken(VormObj, defaulttxt)
{
  ZoekTerm=VormObj.words.value;

  if(ZoekTerm==defaulttxt) ZoekTerm='';

  if(ZoekTerm.length)
  {
    return true;
  }
  else
  {
    return false;
  }

}


function maximizeWindow(WindowObj)
{
  if(parseInt(navigator.appVersion)>3)
  {
    if(navigator.appName=="Netscape")
    {
      if(WindowObj.screenX>0 || WindowObj.screenY>0) WindowObj.moveTo(0,0);
      if(WindowObj.outerWidth < screen.availWidth) WindowObj.outerWidth=screen.availWidth;
      if(WindowObj.outerHeight < screen.availHeight) WindowObj.outerHeight=screen.availHeight;
    }
    else
    {
      WindowObj.moveTo(-4,-4);
      WindowObj.resizeTo(screen.availWidth+8,screen.availHeight+8);
    }
  }
}


function trim(value) {
        value = value.replace(/^\s+/,'');
        value = value.replace(/\s+$/,'');
        return value;
}


function GetViewportPositionOfElement(obj, relClassName)
{
  var curleft = 0;
  var curtop = 0;
  if (obj.offsetParent && obj.className != relClassName)
  {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent)
    {
      if (obj.className == relClassName)
        break;
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return { x: curleft
         , y: curtop};
}
var CurActiviteitPopup = null;
function ShowActiviteitPopup(a, id)
{
  var popup = document.getElementById(id);
  if (CurActiviteitPopup)
  {
    CurActiviteitPopup.style.display = 'none';
    if (CurActiviteitPopup == popup)
    {
      CurActiviteitPopup = null;
      return;
    }
  }
  CurActiviteitPopup = popup;

  if (CurActiviteitPopup)
  {
    var td = a.parentNode;
    var tr = td.parentNode;
    var tds = tr.getElementsByTagName('td');
    for (var i = 0; i < tds.length && tds[i] != td; ++i);
    for (; i > 0 && tds[i-1].className == 'actief'; --i);
    if (tds[i])
    {
      var img_n = document.getElementById(id + '_img_n');
      img_n.style.marginLeft = '0';
      img_n.style.display = '';
      var img_s = document.getElementById(id + '_img_s');
      img_s.style.marginLeft = '0';
      img_s.style.display = 'none';

      var pos = GetViewportPositionOfElement(tds[i], 'blokkenschema');
      CurActiviteitPopup.style.left = '0';
      CurActiviteitPopup.style.top = '0';
      CurActiviteitPopup.style.visibility = 'hidden';
      CurActiviteitPopup.style.display = popup.style.display == 'block' ? '' : 'block';

      // Verplaats het infowindow binnen viewport
      var posx = pos.x + 15;
      var posy = pos.y + 15;
      var viewport = toddGetViewPortDimensions();
      var contentpos = toddGetBodyPos(document.getElementById('contentvlak'));
      if(posx + CurActiviteitPopup.offsetWidth + 20 > viewport.width - contentpos.left)
      {
        var newx = viewport.width - contentpos.left - CurActiviteitPopup.offsetWidth - 20;
        img_n.style.marginLeft = (posx - newx) + 'px';
        img_s.style.marginLeft = (posx - newx) + 'px';
        posx = newx;
      }
      var scrolltop = document.body.scrollTop;
      if (document.documentElement.scrollTop > scrolltop)
        scrolltop = document.documentElement.scrollTop
      if(posy + CurActiviteitPopup.offsetHeight > viewport.height - contentpos.top - 370 + scrolltop)
      {
        var newy = pos.y - CurActiviteitPopup.offsetHeight + 18;
        img_n.style.display = 'none';
        img_s.style.display = '';
        posy = newy;
      }

      CurActiviteitPopup.style.left = posx + 'px';
      CurActiviteitPopup.style.top = posy + 'px';
      CurActiviteitPopup.style.visibility = '';
    }
  }
}
function HideActiviteitPopup()
{
  if (CurActiviteitPopup)
  {
    CurActiviteitPopup.style.display = 'none';
    CurActiviteitPopup = null;
  }
}


var BlokActief = null;
var BlokActiefOver = null;
function BlokMouseEffect(blok, over)
{
  if (!BlokActief)
  {
    BlokActief = document.getElementById("blokactief");
    BlokActiefOver = document.getElementById("blokactiefover");
  }
  blok.src = over ? BlokActiefOver.src : BlokActief.src;
}


function NieuwVenster(waarheen)
{
  DetailVenster = window.open(waarheen,'Detail','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizeable=yes,width=800,height=600');
  DetailVenster.focus();
}


function VideoVenster(waarheen)
{
  DetailVenster = window.open(waarheen,'Detail','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizeable=no,width=350,height=400');
  DetailVenster.focus();
}


function NaarWebsite(waarheen)
{
  DetailVenster = window.open(waarheen,'_blank');
  DetailVenster.focus();
}


function GaNaar(naarurl)
{
  document.location.href=naarurl;
}


function onPreload(aImages, nImages)
{
  if(nImages == aImages.length){
    // BlokeerInteraktie=false;
    return;
  }
}


//Image preload routines staan hieronder
function ImagePreloader(images, callback)
{

  this.callback = callback;// store the callback

  this.nLoaded = 0;
  this.nProcessed = 0;
  this.aImages = new Array;

  this.nImages = images.length;

  for(var i=0; i < images.length; i++){// for each image, call preload()
    this.preload(images[i]);
  }

}

ImagePreloader.prototype.preload = function(image)
{

  // create new Image object and add to array
  //var oImage = new Image;
  var oImage = document.createElement("img"); // met new Image() werkt 't zeker niet!

  this.aImages.push(oImage);

  // set up event handlers for the Image object
  oImage.onload = ImagePreloader.prototype.onload;
  oImage.onerror = ImagePreloader.prototype.onerror;
  oImage.onabort = ImagePreloader.prototype.onabort;

  // assign pointer back to this.
  oImage.oImagePreloader = this;
  oImage.bLoaded = false;

  // assign the .src property of the Image object
  oImage.src = image;
}

ImagePreloader.prototype.onComplete = function()
{
  this.nProcessed++;

  if(this.nProcessed == this.nImages)
    this.callback(this.aImages, this.nLoaded);

}

ImagePreloader.prototype.onload = function()
{
  this.bLoaded = true;
  this.oImagePreloader.nLoaded++;
  this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function()
{
  this.bError = true;
  this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onabort = function()
{
  this.bAbort = true;
  this.oImagePreloader.onComplete();

}


//////////////////////////////////////////////////////////
/// COPIED FROM NEWER VERSION OF /tollium_todd/base.js ///
//////////////////////////////////////////////////////////

/** @short returns the size of the visual area of window
    @return object with width and height
*/
function toddGetViewPortDimensions()
{
  // all except Explorer
  if (window.innerHeight)
    return { width:  window.innerWidth
           , height: window.innerHeight
           };

  // Explorer 6 Strict Mode
  if (document.documentElement && document.documentElement.clientHeight)
    return { width:  document.documentElement.clientWidth
           , height: document.documentElement.clientHeight
           };

  return { width:  document.body.clientWidth
         , height: document.body.clientHeight
         };
}


/** @short returns the full size of the document
    @return size of the document
*/
function toddGetPageDimensions()
{
  var htmlwidth = document.documentElement.scrollWidth;
  var htmlheight = document.documentElement.scrollHeight;

  // IE6-QuirksMode and SF (all versions? tested with 3.2.1) give page height in <BODY>
  // All other browsers give the size in documentElement (<HTML>)
  var bodywidth = document.body.scrollWidth;
  var bodyheight = document.body.scrollHeight;

  // return largest values
  return { width:  htmlwidth  > bodywidth  ? htmlwidth  : bodywidth
         , height: htmlheight > bodyheight ? htmlheight : bodyheight
         };
}


/** @short returns the absolute position an element in <body> would need to have the same position as the given element
    @param obj reference to element
    @return {left:X,top:Y}
*/
function toddGetBodyPos(obj)
{
  // getBoundingClientRect is supported by IE5+, FF3+, OP9.50+, SF4+
  if (obj.getBoundingClientRect)
  {
    var bounds = obj.getBoundingClientRect();

    var xscroll = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
    var yscroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

    return { left: bounds.left + xscroll - document.documentElement.clientLeft - document.body.clientLeft
           , top:  bounds.top + yscroll - document.documentElement.clientTop - document.body.clientTop
           };
  }


  // getBoxObjectFor works in FF2, deprecated in FF3/3.5, removed in FF3.6
  // Only use it for Firefox, since other Gecko based browsers may not correctly implement getBoxObjectFor
  if (toddUserAgentIsFirefox && document.getBoxObjectFor)
  {
    var box   = document.getBoxObjectFor(obj);
    var vpBox = document.getBoxObjectFor(document.documentElement);

    return { left: box.screenX - vpBox.screenX
           , top:  box.screenY - vpBox.screenY
           };
  }


  // the oldskool method of getting positions
  // Safari <4 & Opera 9.25 will use this method
  var elemx = obj.offsetLeft;
  var elemy = obj.offsetTop;
  var parent = obj.offsetParent;

  while (parent)
  {
    // add offset to content part of our offsetParent
    elemx += parent.offsetLeft;
    elemy += parent.offsetTop;

    // Quirks:
    // - Opera already adds clientTop/Left to offsetTop/Left
    // - Firefox <3 (Gecko <1.9) doesn't support clientTop/Left
    if (!toddClientTopIsAddedToOffsetTop && typeof parent.clientLeft != 'undefined')
    {
      // also add the edge size of the offsetParent
      elemx += parent.clientLeft;
      elemy += parent.clientTop;
    }

    // subtract the amount the offsetParent is scrolled, except if it's the scrollposition of the page
    if (parent != document.body && parent != document.documentElement)
    {
      elemx -= parent.scrollLeft;
      elemy -= parent.scrollTop;
    }

    parent = parent.offsetParent;
  }

  return { left: elemx
         , top:  elemy
         };
}
