$(document).ready(function(){  
  //add function to menu items for showing related default gallery  
  $(".handle3 img").click(function () {        
    var galID = $(this).parents().filter('li').find(".serielink:first").attr('id');
    if(galID==undefined){
      galID='';
    }      
    showGallery(galID.replace('link_',''));    
  });  

  //add function to all category links for showing related gallery
  $(".serielink").click(function () {                 
    var galID = $(this).attr('id').replace('link_','');        
    showGallery(galID);
  });
 
  //bind prettyPhoto event to galleries
  $("a[rel^='prettyPhoto']").prettyPhoto(); 
  
  //show default gallery for this site and in this case the first gallery in menu "informatie"
  $("#informatie").click();
}); 

function showGallery(id){     
  //first hide all galleries
  $(".galleryholder").hide();
  
  //show given gallery
  if(id.length>0){
    //load images on demand
    loadImagesOndemand(id);
    
    //make gallery visible
    $("#"+id).show();
  }
}

function loadImagesOndemand(id){
  $("#"+id+" .img-ondemand").each(function(){    
    $(this).attr('src',$(this).attr('longdesc')).removeClass('img-ondemand')    
  });  
}
