// Simple open window script
function OpenWindow(theURL,winName,features) { 
  openWindow = window.open(theURL,winName,features);
  window.open(theURL,winName,features);
  openWindow.focus();
}

// Script to resize the image pop-up window
function fitImage(elem) {
  var image = document.getElementById(elem);
  var iWidth = image.width + 50;
  var iHeight = image.height + 60;
  window.resizeTo(iWidth, iHeight);
  self.focus();
}

function getMousePosition(e) {
  //retourneert muispositie in document
  var posx = 0;
  var posy = 0;
  var mousepos = new Array();
  if (!e) var e = window.event;
  if (e.pageX || e.pageY) {
    //mozilla
    posx = e.pageX;
    posy = e.pageY;
  } else if (e.clientX || e.clientY) {
    //IE
    if (document.documentElement && document.documentElement.scrollTop) {
      posx = e.clientX + document.documentElement.scrollLeft;
      posy = e.clientY + document.documentElement.scrollTop;
    } else {
      posx = e.clientX + document.body.scrollLeft;
      posy = e.clientY + document.body.scrollTop;
    }
  }
  mousepos[0] = posx;
  mousepos[1] = posy;
  return mousepos;
}

/* The cursor position based on an event */
function cursorPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } else {    // MSIE
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


function getWindowSize() {
  //uitgebreide functie nodig omdat o.a. safari clientHeight niet kent
  var windowSize = new Array();
  var windowHeight = 0;
  var windowWidth = 0;
  if (typeof(window.innerHeight) == 'number') {
    windowHeight=window.innerHeight;
    windowWidth=window.innerWidth;
  } else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
      windowWidth = document.documentElement.clientWidth;
    } else if (document.body&&document.body.clientHeight) {
      windowHeight=document.body.clientHeight;
      windowWidth=document.body.clientWidth;
    }
  }
  windowSize[0] = windowWidth;
  windowSize[1] = windowHeight;
  return windowSize;
}

/* timer voor sluiten van 'popup' divs */
hideTimer = setTimeout('',0);

function getScrollTop() {
  if (document.documentElement && document.documentElement.scrollTop)
    return document.documentElement.scrollTop;
  else if (document.body)
    return document.body.scrollTop;
  else 
    return 0;
}

function getScrollLeft() {
  if (document.documentElement && document.documentElement.scrollLeft)
    return document.documentElement.scrollLeft;
  else if (document.body)
    return document.body.scrollLeft;
  else 
    return 0;
}

function initHideTimeout(el) {
    hideTimer = setTimeout('toggle(\'' + el + '\')', 5000);
}

/* special smaller window to open mp3's */
function openMP3(link) {
  var features = "noresize,noscroll,status=no,menubar=no,toolbar=no,width=400,height=100,left=100,top=100";
  OpenWindow(link,'MP3',features);
  return false;
}

/* help */
function showElement(e, elem) {
  var el = document.getElementById(elem);
  var xpos = 0;
  var ypos = 0;
  var mousepos = new Array();
  var winSize = getWindowSize();
  var winWidth = winSize[0];
  var winHeight = winSize[1];
  var scrollTop = getScrollTop();
  var scrollLeft = getScrollLeft();
  var pickerWidth = parseInt(el.offsetWidth);
  var pickerHeight = parseInt(el.offsetHeight);
  var xpadding = 20;//vrije ruimte vanaf vensterrand; moet voor FF altijd groter zijn dan breedte scrollbar
  var ypadding = 20;//vrije ruimte vanaf vensterrand; moet voor FF altijd groter zijn dan hoogte scrollbar
	
  clearTimeout(hideTimer);
  mousepos = cursorPosition(e);
  xpos = mousepos.x-(pickerWidth/2);
  ypos = mousepos.y-10;
  el.style.left = xpos + 'px';
  el.style.top = ypos + 'px';
  el.style.visibility = "visible";
  return false;
}

function hideElement(elem){
  document.getElementById(elem).style.visibility="hidden";
}

function initHide(elem) {
  hideTimer = setTimeout('hideElement(\''+elem+'\')', 50)
}

