jQuery(function($) {
  
  if ( $('#carousel').length ) carousel();
  if ( $('#contentteaser').length ) contentteaser();
  if ( $('#startteaser').length ) startteaser();
  externalLinks();
  searchBox();
  
  function carousel () {
    $('#carousel li:not(.noLink)')
    .hover(
      function() {
        $(this).addClass('hover');
      },
      
      function() {
        $(this).removeClass('hover');
      }
    )
    .click(function() {
      window.location.href = $(this).find('a').attr('href');
    });
  }
  
  function contentteaser () {
    $('#contentteaser .teaser')
    .hover(
      function() {
        $(this).addClass('hover');
      },
      
      function() {
        $(this).removeClass('hover');
      }
    )
    .click(function() {
      window.location.href = $(this).find('a').attr('href');
    });
  }
  
  function startteaser () {
    $('#startteaser .teaser')
    .hover(
      function() {
        $(this).addClass('hover');
      },
      
      function() {
        $(this).removeClass('hover');
      }
    )
    .click(function() {
      window.location.href = $(this).find('a').attr('href');
    });
  }
  
  function externalLinks () {
    var links = $('.extern');
    
    if (! links.length ) return;
    
    links.attr({'target': '_blank'});
  }
  
  function searchBox () {
    var searchField = $('#searchterm');
    var word = searchField.attr('title');
    
    searchField
    .val(word)
    .hover(
      function() {
        $(this).addClass('hover');
      },
      function() {
        $(this).removeClass('hover');
      }
    )
    .focus(function() {
      $(this).addClass('focus');
      if ( $(this).val() == word ) $(this).val('');
    })
    .blur(function() {
      $(this).removeClass('focus');
      if ( $(this).val() == '' ) $(this).val(word);
    });
  }
});
