jQuery(function($)
{
  aria.init();
  externalLinks();
  initClickable();
});


function externalLinks ()
{
  $('#content a.external').attr({'target': '_blank', 'title': 'Link in neuem Fenster'});
}

(function()
{
  // The DOM is ready
  jQuery(function()
  {
    $('#content-inner div.structuredlist.pressreports ul li, #content-inner div.structuredlist.downloads ul li').enlargeClickarea();
  });

  $.fn.enlargeClickarea = function()
  {
    var baseurl = $('base').attr('href') || '';

    return this.each(function(){
      var link = $(this).find('a').eq(0),
          item = $(this);
      if ( !link.length ) return;

      item
        .hover(function(){
          $(this).toggleClass('hover');
        })
        .click(function(event) {
          if ( $(event.target).is('a') )
          {
            return true;
          }
          var href = link.attr('href');
          window.location = href.indexOf('http') == 0 ? href : baseurl + href;
      });

      link
        .focus(function(){
          item.addClass('hover');
        })
        .blur(function(){
          item.removeClass('hover');
        });
    });
  };
})(jQuery);


/**
 * This function makes blocks containing a link clickable.
 */
function initClickable()
{
  if (! $('.clickable').length ) return;

  $('.clickable')
  .hover(
    function()
    {
      $(this).addClass('clickableHover');
    },

    function()
    {
      $(this).removeClass('clickableHover');
    }
  )
  .click(function()
  {
    var newlocation = $('a', this).attr('href');
    if (newlocation.length === 0)
    {
      return false;
    }
    window.location = newlocation;
  });
}

