jQuery(document).ready(function($) {
  //  Suchfeld fokussieren, falls auf Fehlerseite.
  if ($('body').hasClass('error')) {
    $('#s').focus();
  }
  
  //  JavaScript Bilder-Preload
  var preload_images = new Array();
  $('#navigation .top_category a').each(function(intNum) {
    var category_slug = $(this).attr('id');
    preload_images[intNum] = new Image();
    preload_images[intNum].src = gfx_directory+'/category_buttons/'+category_slug+'.jpg';
  });
  
  //  Ausgaben-Navigator (linke Seitenleiste unten)
  function showIssue(aktuelle_ausgabe) {
    var preview_caption = '';
    if (aktuelle_ausgabe == 0) {
      previewCaption = '<span id="frische_ausgabe">Frische<br />Ausgabe:</span>';
    }
    else {
      previewCaption = '<br />Ausgabe:';
    }
    $('#previewImage').animate(
      {
        opacity: 0
      },
      200,
      function() {
        $('#previewImage').attr('src', content_url+'/gallery/freihafen-ausgaben/' + ausgaben[aktuelle_ausgabe]['preview']).animate(
          {
            opacity: 1
          },
          200,
          function() {
            $('#previewCaption').html(previewCaption + '<br /><br /><strong>&quot;' + ausgaben[aktuelle_ausgabe]['titel'] + '&quot;</strong>');
            $('#pdf_link').attr('href', ausgaben[aktuelle_ausgabe]['pdf_link']);
          }
        );
      }
    );
  }
  
  $('#ausgaben_widget a#ausgabe_vor').click(function(event) {
    aktuelle_ausgabe = (aktuelle_ausgabe+1 == ausgaben.length) ? 0 : aktuelle_ausgabe+1;
    showIssue(aktuelle_ausgabe);
    
    event.preventDefault();
  });
  
  $('#ausgaben_widget a#ausgabe_zurueck').click(function(event) {
    aktuelle_ausgabe = (aktuelle_ausgabe-1 == -1) ? ausgaben.length-1 : aktuelle_ausgabe-1;
    showIssue(aktuelle_ausgabe);
    
    event.preventDefault();
  });
});
