$(document).ready(function() {
  // don't throw an error on finnterm page where fancybox is not loaded
  //  since it is provided by finnterm
  if($.fancybox) {
    $("a.zoomable").fancybox({
      'transitionIn'	:	'elastic',
      'transitionOut'	:	'elastic',
      'speedIn'	        :	600, 
      'speedOut'	        :	200,
      'titleShow'          :      true,
      'showNavArrows'      :      true,
      'titlePosition'      :     'over',
      'titleFormat'         :     function(title, currentArray, currentIndex, currentOpts) {
                                      return '<span id="fancybox-title-over"><span class="center-with-background">Slide ' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + empty_unless_exsists(title) + '</span></span>';
                                  }
    });
  }
  $("img.zoomable").each(function(index, img){
    var $img = $(img);
    $span = $('<span />');
    $span.css({
      'display': 'block',
      'overflow': 'auto',
      'position': 'relative',
      'float': 'left'
    });

    $img.wrap($span);

    $icon = $('<img src="/assets/87/magnify.png" alt="Zoom" class="zoom" />');
    $img.after($icon); 

    var right = '' + (parseInt($img.css('margin-right')) + 
                   + parseInt($img.css('border-right-width'))
                   + parseInt($img.css('padding-right')))
                   + 'px';
    var bottom = '' + (parseInt($img.css('margin-bottom')) + 
                  + parseInt($img.css('border-bottom-width'))
                  + parseInt($img.css('padding-bottom')))
                  + 'px';

    $icon.css({
      'bottom' : bottom,
      'right' : right, 
      'position' : 'absolute'
    });
    
  })
});
var empty_unless_exsists = function(obj){
  if (obj) {
    return obj;
  } else {
    return ""
  }
}
    jQuery(document).ready(function($){
      var txt_info = '2 clicks for more privacy: If you click here, the button is activated and you can send your recommendation.';
      if($('.socialshareprivacy').length > 0){
        $('.socialshareprivacy').socialSharePrivacy({
          uri: function(context) {
            if(context.parents('.blog').length > 0) {
              var base = document.location.protocol + "//" + document.location.host;
              var uri = context.parents('.entry').find('.entrytitle a').attr('href');
              if(uri.slice(0,4) != 'http') {
                uri = base + uri;
              }
              return uri;
            }
            return document.location.href;
          },
            'services' : {
                'facebook' : {
                    'dummy_img'         : '/assets/218/dummy_facebook_en.png',
                    'txt_info'          : txt_info,
                    'txt_fb_off'        : 'Facebook button is disabled',
                    'txt_fb_on'         : 'Facebook button is enabled',
                    'perma_option'      : 'off',
                    'language'          : 'en_US',
                    'action'            : 'recommend'
                }, 
                'twitter' : {
                    'dummy_img'         : '/assets/220/dummy_twitter.png',
                    'txt_info'          : txt_info,
                    'txt_twitter_off'   : 'Twitter button is disabled',
                    'txt_twitter_on'    : 'Twitter button is enabled',
                    'perma_option'      : 'off',
                    'language'          : 'en'
                },
                'gplus' : {
                    'dummy_img'         : '/assets/219/dummy_gplus.png',
                    'txt_info'          : txt_info,
                    'txt_gplus_off'     : 'Google+ button is disabled',
                    'txt_gplus_on'      : 'Google+ button is enabled',
                    'perma_option'      : 'off',
                    'language'          : 'en'
                }
            },
            'txt_help'          : 'Wenn Sie diese Felder durch einen Klick aktivieren, werden Informationen an Facebook, Twitter oder Google in die USA &uuml;bertragen und unter Umst&auml;nden auch dort gespeichert. N&auml;heres erfahren Sie durch einen Klick auf das <em>i</em>.',
            'css_path'          : '/stylesheets/socialshareprivacy.css',
}); 
      }
    });
