(function()
{
  jQuery(function($) {
    aria.init();        
    
    enabledPrint();                 // Enables the print button.
    externalLinks();                // Handle external Links. 
		pdfLinks();                     // Handle PDF Links. 
    newsClickable();                // Adding the click-event to the whole news-block (.newsitem).
    rollOvers();                    // Button rollover.

		
  });
       
  /**
   * Enables the print button.
   * */
  function enabledPrint()
  {
    $('#print')
    .removeClass('none')
    .click(function(){
      window.print();
      return false;
    });
  }
  
  /**
   * Handle external Links and set target "_blank".
   * */
  function externalLinks ()
  {
    $('#cols a.external').attr({
      'target': '_blank', 
      'title': 'Link in neuem Fenster'
    });
  } 
	
	function pdfLinks ()
  {
    $('#cols a.pdf').attr({
      'target': '_blank', 
      'title': 'PDF in neuem Fenster'
    });
  }  
  
  /**
   * Adding the click-event to the whole news-block (.newsteaser).
   * */
  function newsClickable()
  {
    var $news = $('.newsteaser, .eventteaser, .jobteaser, .eventlist');
    
    $news
    .bind('click.clickable', function() {
      var news_link = $(this).find('a').attr('href');
      if( news_link ) {
	// get base href
	var base_href = $('base').attr('href');
        window.location.href = base_href + news_link;
      }
    })
    .hover(function() {
      $(this).toggleClass('news-hover');
    })
    .focus(function() {
      $(this).toggleClass('news-focus');
    });
  }
  

  /**
   * Button rollover.
   * */
  function rollOvers ()
  {
    // Preload all rollovers
    $("#marginalsright img").each(function() {
      // Set the original src
      rollsrc = $(this).attr("src");
      rollON = rollsrc.replace(/.png$/ig,"_aktiv.png");
      $("<img>").attr("src", rollON);
    });
    
    // Navigation rollovers
    $("#marginalsright a").mouseover(function() {
      imgsrc = $(this).children("img").attr("src");
      matches = imgsrc.match(/_aktiv/);
      
      // don't do the rollover if state is already ON
      if (!matches)
      {
        imgsrcON = imgsrc.replace(/.png$/ig,"_aktiv.png"); // strip off extension
        $(this).children("img").attr("src", imgsrcON);
      }
    });
    $("#marginalsright a").mouseout(function(){
      $(this).children("img").attr("src", imgsrc);
    });
  }
})();

