var popupImages;
var popupOpen = false;

function uitklap(id)
{
  var curDisplay = $(id).getStyle("display");
  $(id).setStyle("display",(curDisplay == "none"?"":"none"));
}

function fullimage(url, width, height)
{
  if (typeof(popupImages) == "undefined") {
    popupImages = $(document.body).getElements("img.clickable");
  }
  
  var current = false;
  var next = false;
  var prev = false;
  popupImages.each( function (img, key) {
    
    var cl = img.getAttribute("onclick");
    if (typeof(cl) == "function") cl = cl.toString();
    if (cl.toString().indexOf(url) >= 0) {
      current = key;
    }
  });
  if (current === false) return;
  if (current === 0) {
    prev = popupImages.length-1;
  } else {
    prev = current-1;
  }
  if (typeof(popupImages[current+1]) == "undefined") {
    next = 0;
  } else {
    next = current+1;
  }
  
  var nev = popupImages[next].getAttribute("onclick");
  var pev = popupImages[prev].getAttribute("onclick");
  if (typeof(nev) == "function") {
    nev = nev.toString();
    var ar = nev.split("\n");
    ar.each(function (cu) { if (cu.indexOf('fullimage') >= 0) nev = cu; });
  }
  if (typeof(pev) == "function") {
    pev = pev.toString();
    var ar = pev.split("\n");
    ar.each(function (cu) { if (cu.indexOf('fullimage') >= 0) pev = cu; });
  }
  var html = "<img src='"+url+"' onclick=\""+nev+"\" />";
  if (popupImages.length > 1) {
    var html = "<img src='"+url+"' onclick=\""+nev+"\" />";
    html += "<table width='100%'><tr><td width='50%'>";
    html += "<a href='#' onclick=\""+pev+"\">&laquo; Vorige foto</a>";
    html += "</td><td align='right'>";
    html += "<a href='#' onclick=\""+nev+"\">Volgende foto &raquo;</a>";
    html += "</td></tr></table>";
  }
  base.components["fullimagePopup"].resizePopup(width, height);
  if (!popupOpen) {
    base.components["fullimagePopup"].initializeContainer();
  }

  base.components["fullimagePopup"].setContent(html);
  base.components["fullimagePopup"].show();
  popupOpen = true;
}

function video(url)
{
  var width = 400;
  var height = 300;

  var html = "<div id='flashMovie'>Loading...</div>";
  base.components["fullimagePopup"].resizePopup(width, height);

  base.components["fullimagePopup"].setContent(html);
  base.components["fullimagePopup"].initializeContainer();

  var s1 = new SWFObject('/skins/stalling31/flash/player.swf','player',width,height,'9');
  s1.addParam('allowfullscreen','true');
  s1.addParam('allowscriptaccess','always');
  s1.addParam('flashvars','autostart=true&file='+url);
  s1.write('flashMovie');
  
  base.components["fullimagePopup"].show();
}
