
$(document).ready(function()
{
  loadFancyboxHandler();

});

// Handler ------------------------------------------------------------------- 

function loadFancyboxHandler() {
  // copy the rel-attr from <img> into <a>, because impossible in TypoScript
  jQuery('img[rel=image]').parent().parent('a').attr('rel', 'image');
  
  jQuery('a[rel=image]').fancybox({
    'transitionIn'	: 'fade',  // 'elastic', 'fade' or 'none'
		'transitionOut'	: 'fade',
		//'easingIn'      : 'swing',
		//'easingOut'     : 'swing',
    'title'         : this.title,
    'titlePosition' : 'inside',
    // inside titlePosition
    'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
      // empty strings, if no title-attr
      if(title == undefined) {
        title = "";
      }
      if(currentArray.length < 2) {
        // no wrap, if no title
        if(title != "") {
          return title;
        }
      } else {
        // wrap Image numbers, if title exists
        return 'Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + ': ' + title;
      }
    }
  });
}
