var $j = jQuery.noConflict();

function clearInput(id)
{
  var inputField = document.getElementById(id);
  if (id == "username" && inputField.value == "gebruikersnaam") inputField.value = "";
  else if (id == "password" && inputField.value == "******") inputField.value = "";
}

function setInput(id,txt)
{
  var inputField = document.getElementById(id);
  if (inputField.value == "") inputField.value = txt;
}

function setHeights()
{
  var left = $j("#bottomLeft").height()+380;
  var center = $j("#bottomCenter").height()+80;
  var right = $j("#bottomRight").height()+110;

  var max = left;
  if (center>max) max = center;
  if (right>max) max = right;

  $j("#bottomLeft").height(max-380);
  $j("#bottomCenter").height(max-80);
  $j("#bottomRight").height(max-110);
}

function setHeights2()
{
  var maxDivSize = 0;
  $j(".q").each(function()
  {
	if ($j(this).height() > maxDivSize) maxDivSize = $j(this).height();
  })
	
  var left = $j("#bottomLeft").height()+380;
  var center = $j("#bottomCenter").height()+80+maxDivSize;
  var right = $j("#bottomRight").height()+110;

  var max = left;
  if (center>max) max = center;
  if (right>max) max = right;

  $j("#bottomLeft").height(max-380);
  $j("#bottomCenter").height(max-80);
  $j("#bottomRight").height(max-110);
}

function check_keycode()
{
  var k = window.event.keyCode;
  if ( k >= 48 && k <= 57 || k >= 96 && k <= 105 || k == 8 || k == 9 || k == 46 || k == 27 || k >= 33 && k <= 40 || k == 45 )
    window.event.returnValue = true;
  else
    window.event.returnValue = false;
}

function showSubs(id)
{
  var el = document.getElementById("province"+id);
  if (el.style.display == 'none') el.style.display = '';      
  else el.style.display = 'none';
}

// PhotoAlbum functions

var slideshowDelay = null;

function openAlbum(imgIndex,nrOfImgs)
{
  var previous  = document.getElementById("album_previous");
  var next      = document.getElementById("album_next");
  var slideshow = document.getElementById("album_slideshow");
  var close     = document.getElementById("album_close");

  var el = document.getElementById("albumDiv");
  if (el.style.display == "none")
  {
    el.style.display = "block";
    el.style.top = document.body.scrollTop;
    document.body.style.overflow = "hidden";
    for (var x=0; x<nrOfImgs; ++x)
    {
      if (document.getElementById("showImg"+x).style.display == "block") document.getElementById("showImg"+x).style.display = "none";
      else if (x == imgIndex) document.getElementById("showImg"+x).style.display = "block";
    }
    
    if (imgIndex == 0) previous.style.display = "none";
    else
    {
      previous.style.display = "block";
      previous.onclick       = function() { previousImg(imgIndex,nrOfImgs); };
    }
    
    if (imgIndex == nrOfImgs - 1) document.getElementById("album_next").style.display = "none";
    else
    {
      next.style.display = "block";
      next.onclick       = function() { nextImg(imgIndex,nrOfImgs); };
    }
  }
  else if (el.style.display == "block")
  {
    if (slideshowDelay != null) clearTimeout(slideshowDelay);
    if (document.getElementById("showImg"+imgIndex).style.display == "block") document.getElementById("showImg"+imgIndex).style.display = "none";
    el.style.display = "none";
    document.body.style.overflow = "auto";
  }
  
  slideshow.style.background = "url(images/albumbuttons/slideshow_start.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_start_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_start.jpg)'; };
  slideshow.onclick          = function() { startSlideshow(imgIndex,nrOfImgs); };
  close.onclick              = function() { openAlbum(imgIndex,nrOfImgs); };
}

function nextImg(imgIndex,nrOfImgs)
{
  var previous  = document.getElementById("album_previous");
  var next      = document.getElementById("album_next");
  var slideshow = document.getElementById("album_slideshow");

  if (slideshowDelay != null) clearTimeout(slideshowDelay);
  
  for (var x=0; x<nrOfImgs; ++x) document.getElementById("showImg"+x).style.display = "none";
  document.getElementById("showImg"+(parseInt(imgIndex)+1)).style.display = "block";

  previous.style.display = "block";
  previous.onclick       = function() { previousImg(parseInt(imgIndex)+1,nrOfImgs); };

  if (parseInt(imgIndex) + 1 == parseInt(nrOfImgs) - 1) document.getElementById("album_next").style.display = "none";
  else
  {
    next.style.display = "block";
    next.onclick       = function() { nextImg(parseInt(imgIndex)+1,nrOfImgs); };
  }

  slideshow.style.background = "url(images/albumbuttons/slideshow_start.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_start_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_start.jpg)'; };
  slideshow.onclick          = function() { startSlideshow(parseInt(imgIndex)+1,nrOfImgs); };
}

function previousImg(imgIndex,nrOfImgs)
{
  var previous  = document.getElementById("album_previous");
  var next      = document.getElementById("album_next");
  var slideshow = document.getElementById("album_slideshow");
    
  if (slideshowDelay != null) clearTimeout(slideshowDelay);

  for (var x=0; x<nrOfImgs; ++x) document.getElementById("showImg"+x).style.display = "none";
  document.getElementById("showImg"+(parseInt(imgIndex)-1)).style.display = "block";

  if (parseInt(imgIndex) - 1 == 0) document.getElementById("album_previous").style.display = "none";
  else
  {
    previous.style.display = "block";
    previous.onclick       = function() { previousImg(parseInt(imgIndex)-1,nrOfImgs); };
  }

  next.style.display = "block";
  next.onclick       = function() { nextImg(parseInt(imgIndex)-1,nrOfImgs); };

  slideshow.style.background = "url(images/albumbuttons/slideshow_start.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_start_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_start.jpg)'; };
  slideshow.onclick          = function() { startSlideshow(parseInt(imgIndex)-1,nrOfImgs); };
}

function startSlideshow(imgIndex,nrOfImgs)
{
  var slideshow = document.getElementById("album_slideshow");
  slideshow.style.background = "url(images/albumbuttons/slideshow_stop.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_stop_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_stop.jpg)'; };
  slideshow.onclick          = function() { stopSlideshow(imgIndex,nrOfImgs); };

  slideshowDelay = setTimeout("playSlideshow("+imgIndex+","+nrOfImgs+")",3000);
}

function playSlideshow(imgIndex,nrOfImgs)
{
  var previous  = document.getElementById("album_previous");
  var next      = document.getElementById("album_next");
  var slideshow = document.getElementById("album_slideshow");

  for (var x=0; x<nrOfImgs; ++x) document.getElementById("showImg"+x).style.display = "none";
  var imgID = parseInt(imgIndex)+1;
  if (imgID == nrOfImgs) imgID = 0;
  document.getElementById("showImg"+imgID).style.display = "block";

  if (parseInt(imgIndex)+1 == 0) document.getElementById("album_previous").style.display = "none";
  else
  {
    previous.style.display = "block";
    previous.onclick       = function() { previousImg(parseInt(imgIndex)+1,nrOfImgs); };
  }
  
  if (parseInt(imgIndex)+1 == parseInt(nrOfImgs) - 1) document.getElementById("album_next").style.display = "none";
  else
  {
    next.style.display = "block";
    next.onclick       = function() { nextImg(parseInt(imgIndex)+1,nrOfImgs); };
  }

  slideshow.style.background = "url(images/albumbuttons/slideshow_stop.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_stop_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_stop.jpg)'; };
  slideshow.onclick          = function() { stopSlideshow(imgIndex,nrOfImgs); };
  
  var nextIndex = parseInt(imgIndex)+1;
  if (nextIndex >= parseInt(nrOfImgs)-1) nextIndex = nextIndex - nrOfImgs;
  slideshowDelay = setTimeout("playSlideshow("+nextIndex+","+nrOfImgs+")",3000);
}

function stopSlideshow(imgIndex,nrOfImgs)
{
  var previous  = document.getElementById("album_previous");
  var next      = document.getElementById("album_next");
  var slideshow = document.getElementById("album_slideshow");

  slideshow.style.background = "url(images/albumbuttons/slideshow_start.jpg)";
  slideshow.onmouseover      = function() { this.style.background='url(images/albumbuttons/slideshow_start_over.jpg)'; };
  slideshow.onmouseout       = function() { this.style.background='url(images/albumbuttons/slideshow_start.jpg)'; };
  slideshow.onclick          = function() { startSlideshow(imgIndex,nrOfImgs); };

  if (parseInt(imgIndex)+1 == 0) document.getElementById("album_previous").style.display = "none";
  else
  {
    previous.style.display = "block";
    previous.onclick       = function() { previousImg(parseInt(imgIndex)+1,nrOfImgs); };
  }
  
  if (parseInt(imgIndex)+1 == parseInt(nrOfImgs) - 1) document.getElementById("album_next").style.display = "none";
  else
  {
    next.style.display = "block";
    next.onclick       = function() { nextImg(parseInt(imgIndex)+1,nrOfImgs); };
  }

  if (slideshowDelay != null) clearTimeout(slideshowDelay);
}