/**
 * verschiedene spezial anpassungen 
 * @package         typo3-ext-js
 * @version         0.0.3
 */

jQuery.noConflict();

jQuery(document).ready(function($) { 
  /* Navigation: Auszeichnung der Uebersichts-Buttons, z.B. "alle sonstige Studien" */
  $('.l1_3 .l2_5 ul li').last().addClass('last-child');
  $('.l1_4 .l2_1 ul li').last().addClass('last-child');
  $('.l1_4 .l2_2 ul li').last().addClass('last-child');
  
  

  /* Carousel: listeneintraege in zweier gruppern zusammenfassen */
  $('.tx-jfmulticontent-pi1').each(function() {
    /* ist keine tab navigation */
    if ( $(this).find('.tab').length == 0) {
      $(this).find('li:even').each(function() {
        var $item = $(this);
        $item.append( $item.next().html() );
        $item.next().remove();
      });
    }
  });  
  
  $('.tx-jfmulticontent-pi1 li>div:last-child').addClass('last');
  //$('.tx-jfmulticontent-pi1 li .tx-prpageteaser-pi1:last-child').addClass('last');
  $('.tx-jfmulticontent-pi1 .tab li:first-child').addClass('first');
  
  
  /* Nachrichtenliste: mehr link besser verlinken*/
  $('.linkNews').each(function() {
    var $link = $(this).find('a').attr('href');
    var $link_title = $(this).find('a').attr('title');
    $(this).find('a').remove();

    $(this).wrapInner('<a href="' + $link +'" title="' + $link_title + '" />');
   });
  
  
  /* Linklisten: wenn der Titel verlinkt ist, den ganzen eintrag verlinken */
  $('.linkList li').each( function() {
    if ( $(this).find('strong a').length > 0 ) {   
      var $link = $(this).find('strong a').attr('href');
      var $link_title = $(this).find('strong a').attr('title');
      
      var $text = $(this).find('strong a').text();
      $(this).find('strong a').replaceWith($text);
      
      $(this).wrapInner('<a href="' + $link +'" title="' + $link_title + '" />');
    }
  });
  
  /* IE hat kein trim() funtion */
  if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g, ''); 
    }
  }

  /* zusaetzlichen mehr link entfernen */
  $('.linkList li a').each( function() {
    if ( $(this).text() == 'mehr' ) {
     $(this).remove();
    }
        
    if ( $(this).html().trim() == '<span></span>' || $(this).html().trim() == '<SPAN>' ) {
      $(this).remove();
    }

  });


  /* Medienlisten: beschreibungstext in den link schreiben */
  $('.mediaList li').each( function() {
    var $link_text = '<strong>' + $(this).find('a').text() + '</strong>';
    var $text = $(this).clone();
    $text.find('span').remove();
    $text.find('br').remove();
    $text = $text.text(); 
    
    var $href = $(this).find('a').attr('href');
    var $title = $(this).find('a').attr('title');
    
    var $new_link = '<a href="' + $href + '" title="' + $title + '">' + $link_text + $text + '</a>';
    
    $(this).empty().append($new_link);

  });
  /* PDF-Links in pr_medialist _blank öffnen*/
    $('.linkList li.linkPdf a').attr('target','_blank'); 
  
  /* Suchergebnis pager, wort "seite" vor der nummer entfernen */
 $('.browsebox a').each( function() {
   var $text = $(this).text();
   if( $text.indexOf("Seite") == 0 ) {
     $text = $text.substring(6, $text.length);
     $(this).text($text);
   }
 });

   
  /* Drucken Button per Javascript schreiben. Weil der Drucken Button javascript benoetigt, nur mit javascript sichtbar */
  $('#footer_tools').append ('| <a href="javascript:window.print();" class="print_button">Drucken</a>');
  $('body.english a.print_button').text('Print')

 

});
