jQuery(function($) {
  aria.init();
  if ( $('#content .newsTeaser').length ) newsTeaser();  
  helpBubble();
  externalLinks();
});

function helpBubble () {
  var helpBubble = $('#helpBubble'),
      helpLink  = $('#help a')
  ;
  helpBubble = helpBubble.remove().clone().prependTo('#headerCenter');
  helpLink
    .bind('mouseenter focus', function() { 
      helpBubble.fadeTo(0,0).show().animate({top: '60px', opacity: '1'}, {duration: 100});
    })
    .bind('mouseleave blur', function() { 
      helpBubble.animate({top: '70px', opacity: '0'}, {duration: 100}, function() {
        $(this).hide();
      });
    })
    .click(function() {
      return false;
    })
  ;
}

// Wird jetzt nicht gebraucht
function externalLinks () {
  $('#content a.external').attr({'target': '_blank', 'title': 'Link in neuem Fenster'});
}

jQuery(document).ready(function() {
  
  // set active link on metaCenter
  var curr_path = location.href;
  $('#metaCenter a').each(function(){
    var a = $(this);
    if (curr_path.indexOf(a.attr("href")) != -1)
      a.addClass('active');
  });
  
  // fix startseite highlighting
  var home = $('#metaLeftCol li.first a');
  if(location.pathname == '/oear')
    home.addClass('active');
  else
    home.removeClass('active');
  $('#mainNav a').each(function(){
    var a = $(this);
    if (curr_path.indexOf(a.attr("href")) != -1)
      a.addClass('active');
  });
  
  // fix livesearch
  $('#LSResult').hide();
  
  // move random image to headerimage
  var randomImage = $('#headerRandomImage');
  if(randomImage.length > 0) {
    $('#headerImage img').replaceWith(randomImage);
  }
  
  // add classes to links refering to filetypes
  $("a[href*='.pdf']").addClass("pdf");
  $("a[href*='.doc']").addClass("doc");
  $("a[href*='.ppt']").addClass("ppt");
  $("a[href*='.xsl']").addClass("xsl");
  $("a[href*='.jpg'], a[href*='.jpeg'], a[href*='.gif'], a[href*='.png']").addClass("img");
});

