$(function() {


  // Decorate teasers, remove empty links, add play button to the teasers if it is a video teaser.
  
  $('.teaser').each(function() {
    
    var span = $(this).find('span');
    var a = span.find('a');
    var img = span.find('img');

    if ($.trim(a.attr('href')) == "") {
      a.remove();
      span.removeClass('is-video-1');
      span.append(img);
    }
    
  });
  
  $('.is-video-1').each(function() {
      
    var $this = $(this);
    var a = $this.find('a');
    if ($.trim(a.attr('href')) == "")
      return;
    
    $this.append('<div class="play-button"></div>');
    var img = $this.find('img');
    
    var playButton = $this.find('.play-button');
       
    img.mouseover(function () {
      playButton.css('background','url("/images/play-button-active.png")');
    });

    img.mouseout(function () {
      playButton.css('background','url("/images/play-button-1.png")');
    });

    playButton.mouseover(function () {
      $(this).css('background','url("/images/play-button-active.png")');
    });

    playButton.mouseout(function () {
      $(this).css('background','url("/images/play-button-1.png")');
    });

    playButton.click(function () {
      var href = img.parent().attr('href');
      window.location = href;
    });

  });

  $('.new-window-1').each(function() {
      
    var $this = $(this);
    var a = $this.find('a');
    if ($.trim(a.attr('href')) == "")
      return;
    
    a.attr('target', '_blank');

  });

  
  // Remove header from teasers if the header is empty.
  
  $('.block').each(function() {
    var $this = $(this);
    var boxHeaders = $this.find('.box-header');
    if (boxHeaders.length == 0)
      return;
    var boxHeader = boxHeaders.first();
    if ($.trim(boxHeader.text()) == '')
      boxHeader.addClass('hidden');
  });
  
  
  // Remove the border on the last news item on the teaser.
  
  $('.news').each(function() {
    $(this).find('.news-feed').last().addClass('last-child');
  });
    
  // Remove empty h1 tags.
  
  $('h1').each(function() {
    var $this = $(this);
    if ($.trim($this.html()) == '')
      $this.remove();
  });
  
});
