$(document).ready(function() {
  /* Details */
  $('#photo-title').append('<div id="btn-photo-meta"><a href="#photo-meta"><span>Info einblenden</span></a></div>');
  $('#btn-photo-meta a').click( function () {
      if ($('#photo-meta').css('display') == 'none') {
          $('#photo-meta').show();
      } else {
          $('#photo-meta').hide();
          //$('#photo-title #btn-photo-meta a').css('background-position','0 0');
          return false;
      }
      $(this).toggleClass('active');
      
  } );
  /* Facebook */
  $('#photo-title').append('<div id="btn-facebook"><a href="'+$(location).attr('href')+'"><span>Facebook</span></a></div>');
  $('#btn-facebook').click( function () {
      $(this).html('<iframe src="http://www.facebook.com/plugins/like.php?href='+$(location).attr('href')+'&amp;send=false&amp;layout=button_count&amp;width=250&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:21px;" allowTransparency="true"></iframe>');
      $('head').append('<meta property="og:image" content="'+ $('#photo img').attr('src')+'"/>')
      return false;
  } );
  /* Touch */
  if(navigator.platform == 'iPad') {
    $('body').addClass('ipad');
  } else if (navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
    $('body').addClass('iphone');
  } else {
    $('#thumbnails a').tipTip({ maxWidth: 'auto' });
  }
  /* Galerie */
  $('#gallery-nav').pfSmartGallery({ btnPrevText:'<span class="hideme">vorheriges Foto</span>', btnNextText:'<span class="hideme">nächstes Foto</span>' });
  /* Blog */
  var g = $('#photo');
  $('#photo-nav').pfSmartGallery({ galleryObj:g, btnPrevText:'<span class="hideme">vorheriges Foto</span>', btnNextText:'<span class="hideme">nächstes Foto</span>' });
  $('#gallery, #photo').hover( function() { $('#btn').stop().fadeIn('fast'); }, function() { $('#btn').stop().fadeOut('fast'); } );
});
$(document).keydown(function(e) {
  var url = false;
  if (e.which == 37) { url = $('link[rel="prev"]').attr('href'); } else if (e.which == 39) { url = $('link[rel="next"]').attr('href'); }
  if (url) { window.location = url; }
});
