$(document).ready(function() {
  var nr  = 1;
  var cnt = $('#portfolio img').length;
  
	$('#portfolio a#next, #portfolio img').click(function() {
    if (nr < cnt) {
	    $('#portfolio img:eq(' + (cnt-nr) + ')').fadeOut();
      nr++;
      $('#nr').text(nr);
      pftoggle();
    }
	});
	$('#portfolio a#prev').click(function() {
	  if (nr > 1) {
      nr--; 
  	  $('#portfolio img:eq(' + (cnt-nr) + ')').fadeIn();
      $('#nr').text(nr);
      pftoggle();
    }
	});
  function pftoggle() {
    $('#portfolio a#next').toggle(nr < cnt);
    $('#portfolio a#prev').toggle(nr > 1);
    $('#description').html($('#portfolio img:eq(' + (cnt-nr) + ')').attr('description'));
  }
  pftoggle();

	$('#portfolio img').each(function(i) {
	  $('#portfolio img').eq(cnt-i-1).show();
	});
	
	$('div.slideshow').slideshow({
    intervalTime: 7500, 
    fadingTime  : 1000,
    bullets: false,
    arrows: false  
  });
  
  // $('a#back').toggle(history.length > 0);
  $('a#back').click(function() { history.back(); return false; });
  
  $('div.portfolio a').each(function() {
    var id = $(this).text();
    $(this).attr('id', id);
    if (id.match(/leeg/)) {
      $(this).css('cursor', 'default').click(function() { return false });
    }
  });
});


