function urlDecodeArray(arr) {//{{{
  var ret = [];
  var i=0;
  for(i=0; i<arr.length; i++) {
    if(arr[i] instanceof Array)
      ret.push(urlDecodeArray(arr[i]));
    else
      ret.push(decodeURIComponent(arr[i]));
  }
  return ret;
}//}}}
$(document).ready(function() {

  $('div.galleryimage').css('visibility','visible');
  $('p.loadingmsg').css('visibility','hidden');


  $('img.button').hover(
    function(e){e.target.src=e.target.src.replace('1.gif','2.gif');},
    function(e){e.target.src=e.target.src.replace('2.gif','1.gif');}
  );
  $('a.pageimg').fancybox();
  $('a.menuimg').fancybox();
  $('div.galleryimage a').fancybox({titlePosition:'over',titleFormat:getAlbumTitle});
  $('div.menurootcontainer').css('height','27px');
  var num = $('div.menurootcontainer > a > div.active').parents('div.menurootcontainer').children('a').length * 30;
  $('div.menurootcontainer > a > div.active').parents('div.menurootcontainer').animate({height:(num+'px')},1000);
  $('div.menurootcontainer div.menurootitem').click(function(e){
    e.preventDefault();
    var currroot = $(e.target).parents('div.menurootcontainer');
    var currh = parseInt($(e.target).parents('div.menurootcontainer').css('height'));

    if(currh < 30) {
      var num = $(e.target).parents('div.menurootcontainer').children('a').length * 30;
      $(e.target).parents('div.menurootcontainer').animate({height:(num+'px')},1000);
    }
    else {
      $(e.target).parents('div.menurootcontainer').animate({height:'27px'},1000);
    }

    $('div.menurootcontainer div.menurootitem').not(e.currentTarget).each( function(index,value) {
      $(value).parents('div.menurootcontainer').animate({height:'27px'},1000);
    });
  });
});
function getAlbumTitle(title,currentArray,currentIndex,currentOpts) {
  var desc = $('div.galleryimage input').eq(currentIndex).val();
  if(desc == "%%%desc%%%") {
    desc = "";
  }
  else {
    desc += "<br/>"
  }
  return "<span id='fancybox-title-over'>"
    +"<span style='font-weight:bold;'>"+title+"</span><br/>"
    +"<span>"+desc+"</span>"
    +"<span style='font-size:11px;font-style:italic;'>"
    +"Afbeelding "+(currentIndex+1)+" van "+currentArray.length
    +"</span>"
    +"</span>";
}
