var pop = null;
var curPopId = null;

function showPop(id,coords){
  if (curPopId != null)
    hidePop(curPopId);

  newId = 'y'+id;
  if (document.all(newId)){
    var url = document.all(newId).innerHTML;
    if (url.indexOf('_$intern')!=-1){
      url = url.substring(0,url.length-9);
      document.location.href = url;
    } else window.open(document.all(newId).innerHTML);
  }
  else {
    newId = 'x'+id;
    theImg = document.images["p_"+maps[0]];
    curPopId = newId; 
    topx = getEltTop(theImg);
    var leftBorder = Math.round(parseInt(document.body.clientWidth)/2)-300;   
    if (pop != null) pop.style.display = 'none';  
    pop = document.getElementById(newId); 
    pop.style.display = "block";

    theX=0;
    theY=0;
    
    if (!window.event) {
      var newCoords = eval('new Array('+coords+')');
      for (i=0;i<newCoords.length;i+=2) {
        theX = theX += newCoords[i];
      }
      for (j=1;j<newCoords.length;j+=2) {
        theY = theY += newCoords[j];
      }   
      pop.style.left = leftBorder + Math.round(theX/(newCoords.length/2));
      pop.style.top =  topx + Math.round(theY/(newCoords.length/2));
    }
    else {
      pop.style.top = window.event.clientY + document.body.scrollTop;
      pop.style.left = window.event.clientX;
    }     
  }
}

function showPopKidssite(id, shape,coords){
  if (curPopId != null)
    hidePop(curPopId);

  newId = 'y'+id; 
  if (document.all(newId)){
    window.open(document.all(newId).innerText);
  }
  else {
    newId = 'x'+id;
    theImg = document.images["p_"+maps[0]];
    curPopId = newId;
  topx = get_pos_Y(theImg); 
    var leftBorder = Math.round(parseInt(document.body.clientWidth)/2)-300;   
    if (pop != null) pop.style.display = 'none';  
    pop = document.getElementById(newId); 
    pop.style.display = "block";

    theX=0;
    theY=0;
    
    if (!window.event) {  
      var newCoords = eval('new Array('+coords+')');
    if (shape=="CIRCLE")
    {
    theX = newCoords[0];
        theY = newCoords[1];
      pop.style.left = leftBorder + theX - 50;
        pop.style.top = topx + theY;
    }
    else
    {
    for (i=0;i<newCoords.length;i+=2) {
          theX = theX += newCoords[i];
        }
        for (j=1;j<newCoords.length;j+=2) {
          theY = theY += newCoords[j];
        }   
        pop.style.left = leftBorder + Math.round(theX/(newCoords.length/2)) - 50;   
        pop.style.top =  topx + Math.round(theY/(newCoords.length/2));    
    }
    }
    else {
      pop.style.top = window.event.clientY + document.body.scrollTop;
      pop.style.left = window.event.clientX;
    }     
  }
}

function get_pos_Y(element) {
  var current_top = 0;
  
  if (element.offsetParent) {
    while (element.offsetParent) {
      current_top += element.offsetTop
      element = element.offsetParent;
    }
  } else if (element.y)
    current_top += element.y;
  
  return current_top;
}

var spot = null;

function showSpot(id){
  theImg = document.images["p_"+maps[0]];
  topx = getEltTop(theImg);
  var leftBorder = Math.round(parseInt(document.body.clientWidth)/2)-300;

  pop = document.getElementById(id);
   
  if (spot != null) spot.style.display = 'none';

  spot = document.getElementById("spot");

  spot.innerText = "Klik voor meer informatie over: " + pop.innerText;

  spot.style.display = "block";
  theX=0;
  theY=0;
  if (!window.event) {
    var newCoords = eval('new Array('+coords+')');
    for (i=0;i<newCoords.length;i+=2) {
      theX = theX += newCoords[i];
    }
    for (j=1;j<newCoords.length;j+=2) {
      theY = theY += newCoords[j];
    }
    spot.style.left = leftBorder + Math.round(theX/(newCoords.length/2))+18;
    spot.style.top =  topx + Math.round(theY/(newCoords.length/2))-70;
  }
  else {
    spot.style.top = window.event.clientY + document.body.scrollTop+18;
    spot.style.left = window.event.clientX-70;
  }

}

function hideSpot(){
  spot = document.getElementById("spot");
  spot.style.display = "none";
}

function hidePop(id) {
  document.all(id).style.display = "none";
}

function setPics() {
  for (var x=0;x<maps.length;x++) {
    bigImg = document.images["p_"+maps[x]];
    leftx = getEltLeft(bigImg);
    topx = getEltTop(bigImg);
    num = getElt("d"+maps[x]).title;
    for (y=1;y<=num;y++) {
      img = document.images[maps[x]+y];
      img.style.MozOpacity= .0;
      positie = img.id;
      imgX= positie.substring(1,positie.indexOf('z'));
      imgY= positie.substring(positie.indexOf('z')+1,positie.length);
      setEltLeft(img,parseInt(leftx) + parseInt(imgX));
      setEltTop(img,parseInt(topx) + parseInt(imgY));
      img.style.display = "block";
    }
  }
}

function changeImg(id) {
  obj = getElt(id);
  setOP(obj,0);
}

function resetImg(id) {
  obj = getElt(id);
  setOP(obj,0);
}


