
var fx = new Object;
fx['images'] = new Object;
fx['albums'] = new Object;
fx['navigationPosition'] = 0;
fx['currentPosition'] = 0;
fx['qeue'] = new Object;



function showImage (id)
{
  if (typeof fx['images'][id] == 'undefined' || ! fx['images'][id])
  {
    return false;
  }
  var imageProperties = fx['images'][id]['large'];
  showOverlay ();
  showNavigation (imageProperties);
  showImagebox (imageProperties);
  stretchOverlay();
  for (var i in fx['qeue'])
  {
    if (typeof fx['images'][i] != 'undefined')
    {
      fx['images'][i]['large']['preload'] = new Image;
      fx['images'][i]['large']['preload'].src = fx['images'][i]['large']['src'];
      delete fx['qeue'][i];
    }
  }
}
function stretchOverlay ()
{
  var dimensions = getPageDimensions();
  var imagebox = $('#imagebox').get(0);
  var pageHeight = Math.max(imagebox.offsetHeight + parseInt(imagebox.style.top), dimensions.height);
  $('#imageoverlay').css({position: 'absolute', top: '0px', left: '0px', right: '0px', height: pageHeight + 'px', width: '100%'});
}
function showOverlay ()
{
  var imageoverlay = document.getElementById('imageoverlay');
  if (typeof imageoverlay == 'undefined' || !imageoverlay)
  {
    imageoverlay = document.createElement('div');
    imageoverlay.id = 'imageoverlay';
    $(imageoverlay).click(function(e){ hideImageoverlay() });
    $('body').append(imageoverlay);
  }
  imageoverlay.style.position = 'absolute';
  $(imageoverlay).show();
}
function showImagebox (imageProperties)
{
  var imagebox = document.getElementById('imagebox');
  if (typeof imagebox == 'undefined' || !imagebox)
  {
    imagebox = document.createElement('div');
    imagebox.id = 'imagebox';
//    $(imagebox).click(function(e){ hideImageoverlay() });
    $('body').append(imagebox);
  }
  imagebox.style.position = 'absolute';
  var imageHTML = '<img src="' + imageProperties['src'] 
    + '" width="' + imageProperties['width'] + '" '
    + '" height="' + imageProperties['height'] + '" '
    + '" alt="" class="overlayimage" />';
  if (
    (typeof imageProperties['album'] != 'undefined')
    && (typeof fx['albums'][imageProperties['album']] != 'undefined')
    && (fx['albums'][imageProperties['album']]['images'].length > 1)
  )
  {
    if (imageProperties['num'] == fx['albums'][imageProperties['album']]['images'].length -1)
    {
      var nextId = fx['albums'][imageProperties['album']]['images'][0];
    }
    else
    {

      var nextId = fx['albums'][imageProperties['album']]['images'][imageProperties['num'] + 1];
    }
    var imageHTML = '<a href="'+ fx['link'] + '/showimage=' + nextId + '"'
      + ' onclick="showImage(\'' + nextId + '\'); return false">'
      + imageHTML + '</a>';
  }
  else
  {
    imageHTML = '<a href="'+ fx['link'] +'" onclick="hideImageoverlay(); return false">'
      + imageHTML + '</a>';
  }
  var imageOptions = document.createElement('div');
  imageOptions.id = 'image-options';
  imageOptions.innerHTML = closeButton();
  imagebox.innerHTML = imageHTML;
  imagebox.appendChild(imageOptions);
  imageOptions.style.width = (imageProperties['width'] + 20) + 'px';
  centerImageBox(imageProperties);
}
function centerImageBox (imageProperties)
{
  var windowDimensions = getWindowDimensions();
  if (fx['navigationPosition'] > 0)
  {
    var navigationPosition = Math.max(Math.round((windowDimensions['height'] - 850) / 2), 10);
    var space = Math.min(windowDimensions['height'] - navigationPosition - 40, 750);
    var boxY = Math.max(Math.round((space - imageProperties['height'] - 80) / 2), 0);
    boxY = boxY + 40 + fx['navigationPosition'];
  }
  else
  {
    var boxY = Math.max(Math.round((windowDimensions['height'] - imageProperties['height'] - 50) / 2), 10) + getScrollPosition();
  }
  var imagebox = $('#imagebox').get(0);
  imagebox.style.top = boxY + 'px';
  $(imagebox).show();
}
function hideImageoverlay ()
{
  $('#album-navigation').hide();
  fx['navigationPosition'] = 0;
  $('#imagebox').hide();
  $('#imageoverlay').hide();
}
function showNavigation (imageProperties)
{
  if (
    (typeof imageProperties['album'] == 'undefined')
    || (typeof fx['albums'][imageProperties['album']] == 'undefined')
    || (fx['albums'][imageProperties['album']]['images'].length < 2)
  )
  {
    fx['navigationPosition'] = 0;
    $('#album-navigation').hide();
    return;
  }
  var album = fx['albums'][imageProperties['album']];
  if (fx['navigationPosition'] == 0)
  {
    setNavigationPosition();
  }
  var albumNavigation = document.getElementById('album-navigation');
  if (typeof albumNavigation == 'undefined' || !albumNavigation)
  {
    albumNavigation = document.createElement('div');
    albumNavigation.id = 'album-navigation';
    $('body').append(albumNavigation);
  }
  albumNavigation.style.zIndex = 99;
  albumNavigation.style.top = fx['navigationPosition'] + 'px';
  
  var navHTML = '<div id="album-navigation-box">';
  if (imageProperties['num'] > 0)
  {
    navHTML += navigationLink(album['images'][0], 'first', 'Eerste', true);
    navHTML += navigationLink(album['images'][imageProperties['num'] - 1], 'previous', 'Vorige', true);
  }
  else
  {
    navHTML += navigationLink(0, 'first', 'Eerste', false);
    navHTML += navigationLink(0, 'previous', 'Vorige', false);
  }
  navHTML += ' &nbsp; ';
  if (imageProperties['num'] < album['images'].length - 1)
  {
    navHTML += navigationLink(album['images'][imageProperties['num'] + 1], 'next', 'Volgende', true);
    navHTML += navigationLink(album['images'][album['images'].length - 1], 'last', 'Laatste', true);
  }
  else
  {
    navHTML += navigationLink(0, 'next', 'Volgende', false);
    navHTML += navigationLink(0, 'last', 'Laatste', false);
  }
  navHTML += ' &nbsp; ';
  navHTML += closeButton();
  navHTML += '</div>';
  albumNavigation.innerHTML = navHTML;
  $(albumNavigation).show();
}

function navigationLink (id, type, text, active)
{
  switch (type)
  {
    case 'first':
    case 'last':
      var imageWidth = 9;
      break;
    default:
      var imageWidth = 6;
  }
  var imageSrc = active ? type + '.gif' : type + '-inactive.gif';
  var output = '<img src="/images/common/' + imageSrc + '" id="album-navigation-' + type + '"'
    + ' width="' + imageWidth + '" height="11" title="'+ text +'" alt="' + text + '" />';
  if (!active)
  {
    return output;
  }
  if (typeof fx['images'][id]['large']['preload'] == 'undefined')
  {
    fx['qeue'][id] = true;
  }
  return '<a href="'+ fx['link'] + '/showimage=' + id + '"'
   + ' onclick="showImage(\'' + id + '\'); return false">'
   + output + '</a>';
}

function closeButton ()
{
  return '<a href="'+ fx['link'] +'" onclick="hideImageoverlay(); return false">'
    + '<img title="Sluiten" src="/images/common/close.gif" class="image-close-button" width="11" height="11"  alt="Sluiten" /></a>';
}
function setNavigationPosition ()
{
  var windowDimensions = getWindowDimensions();
  var position = Math.max(Math.round((windowDimensions['height'] - 850) / 2), 10);
  fx['navigationPosition'] = position + getScrollPosition();
}
$(document).ready(function(){
  $('img.picture').each(function (){
    var dropshadowbox = document.createElement('div');
    dropshadowbox.className = 'dropshadowbox';
    if (this.align)
    {
      $(dropshadowbox).css({float: this.align});
      this.align = "";
    }
    if (this.parentNode.tagName == 'A')
    {
      var origNode = this.parentNode;
      var clone = this.parentNode.cloneNode(true);
      var parentNode = this.parentNode.parentNode;
    }
    else
    {
      var origNode = this;
      var clone = this.cloneNode(true);
      var parentNode = this.parentNode;
    }
    var dropshadowcorner = document.createElement('div');
    dropshadowcorner.className = 'dropshadowcorner';
    var dropshadowdrop = document.createElement('div');
    dropshadowdrop.className = 'dropshadowdrop';
    var dropshadowinnerbox = document.createElement('div');
    dropshadowinnerbox.className = 'dropshadowinnerbox';
    dropshadowinnerbox.appendChild(clone);
    dropshadowdrop.appendChild(dropshadowinnerbox);
    dropshadowcorner.appendChild(dropshadowdrop);
    dropshadowbox.appendChild(dropshadowcorner);
    parentNode.replaceChild(dropshadowbox, origNode);
  })
});


function getWindowDimensions ()
{
	var windowWidth, windowHeight;
	if (self.innerHeight)
  {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
  else
  {
    // Explorer 6 Strict Mode
    if (document.documentElement && document.documentElement.clientHeight)
    {
		  windowWidth = document.documentElement.clientWidth;
	  	windowHeight = document.documentElement.clientHeight;
	  }
    // other Explorers
    else if (document.body)
    {
		  windowWidth = document.body.clientWidth;
		  windowHeight = document.body.clientHeight;
    }
	}
  var dimensions = {
    'width': windowWidth,
    'height': windowHeight
  }
  return dimensions;
}

function getContentDimensions ()
{
  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY)
  {	
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
	}
  // all but Explorer Mac
  else if (document.body.scrollHeight > document.body.offsetHeight)
  {
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
	}
  // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  else
  {
    xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
  var dimensions = {
    'width': xScroll,
    'height': yScroll
  }
  return dimensions;
}
function getPageDimensions ()
{
  var windowDimensions = getWindowDimensions();
  var contentDimensions = getContentDimensions();
  var dimensions = {
    'width': Math.max(windowDimensions.width, contentDimensions.width),
    'height': Math.max(windowDimensions.height, contentDimensions.height)
  }
	return dimensions;
}

function getScrollPosition ()
{
  var scrollY = 0;

  if ( document.documentElement && document.documentElement.scrollTop )
  {
    scrollY = document.documentElement.scrollTop;
  }
  else if ( document.body && document.body.scrollTop )
  {
    scrollY = document.body.scrollTop;
  }
  else if ( window.pageYOffset )
  {
    scrollY = window.pageYOffset;
  }
  else if ( window.scrollY )
  {
    scrollY = window.scrollY;
  }
  return scrollY;
}

