﻿/* ---------------------------------------------------------- */
/* ----- Functies Fotoalbum - Pagineering ------------------- */
/* ---------------------------------------------------------- */
var $j = null;
jQuery(document).ready(function() {
  $j = jQuery;
  $.noConflict();
  
});

var noShowName = 'no_show';
var nietActief = 'niet_actief';
function showNextImages() {
  if ($j('.foto_paginering:last:visible').length == 0) {
    $j('.foto_paginering:visible').next().removeClass(noShowName);
    $j('.foto_paginering:visible:first').addClass(noShowName);
    updatePagineering();
  }
}

function showImages(page) {
  $j('.foto_paginering:visible').addClass(noShowName);
  $j('.foto_paginering:eq(' + page + ')').removeClass(noShowName);
  
  //'span' in een 'a' veranderen en andersom.
  updatePagineering();
}

function showPrevImages() {
  if ($j('.foto_paginering:first:visible').length == 0) {
    $j('.foto_paginering:visible').prev().removeClass(noShowName);
    $j('.foto_paginering:visible:last').addClass(noShowName);
    updatePagineering();
  }
}

function updatePagineering() {
  // Eventueel de eerste knop tonen en de laatste op inactief:
  $j('.paginering').each(function () {
    if ($j('.foto_paginering:first:visible').length == 0) {
      $j(this).find('a:first').removeClass(nietActief);
      if ($j('.foto_paginering:visible').next('.foto_paginering').length == 0) {
        $j(this).find('a:last').addClass(nietActief);
      }
    }
    if ($j('.foto_paginering:last:visible').length == 0) {
      $j(this).find('a:last').removeClass(nietActief);
      if ($j('.foto_paginering:visible').prev('.foto_paginering').length == 0) {
        $j(this).find('a:first').addClass(nietActief);
      }
    }
  });
  //Het fotoalbum overzicht is veranderd, de pagineering ook aanpassen.
  $j('.paginering').each(function(){
    // This is de paginering div.
    // 'span' in een 'a' veranderen.
    $j(this).find('span').each(function(){
      // This is de span.
      $j(this).replaceWith("<a onclick='showImages(" + ($j(this).text() - 1) + "); return false;' href='#'>" + $j(this).text() + "</a>");
    });
    // De juiste 'a' in een 'span' veranderen.
    $j(this).children().not('a:first,a:last').filter('a:eq('+(($j('.foto_paginering').length - $j('.foto_paginering:visible').nextAll('.foto_paginering').length)-1)+')').each(function(){
      // This is de 'a'
      $j(this).replaceWith("<span>" + $j(this).text() + "</span>")
    });    
  });
}
