$(document).ready(function()
{

  // Init flipboxes
  $('.flipside').hide();
  $('p.forward, .flipside p.revert, .flipside h2').show();

  function do_flip(target)
  {
    target.flip({
      color: '#ffffff',
      content: target.children('.flipside').html(),
      direction: 'lr',
      speed: 'fast',
      onEnd: function(){ reset_revert(); },
    });
  }

  // Update 'revert' function every time a box is flipped
  function reset_revert()
  {
    $('.flip p.revert a').click(function()
    {
      $(this).parent().parent().revertFlip({
        onEnd: function(){ reset_flip(); }
      });
      return false;
    });
  }

  // Update 'flip' function every time a box is reverted
  function reset_flip()
  {
    $('.flip img').click(function()
    {
      do_flip( $(this).parent() );
      return false;
    });
    $('.flip p.forward a').click(function()
    {
      do_flip( $(this).parent().parent() );
      return false;
    });
  }

  // Init flipboxes
  reset_revert();
  reset_flip();

  // Blog: hide search button and change label text
  $('#blog #searchform label').text('Enter the query to search and press Enter.');
  $('#blog #searchform input.submit').hide();

  // Newsroom: make client jump automatic
  $('#newsroom #redirector input').hide();
  $('#newsroom #redirector select').change(function()
  {
    document.location = $(this).attr('value');
  });

  // Header slideshows
  var count = $('div#slides ul li').length;
  if( count > 1 )
  {
    $('div#slides ul').css('width',parseInt(count*1080)+'px').jcarousel({
      animation: 1000,
      auto: 5,
      scroll: 1,
      size: count,
      wrap: 'last'
    });
  }

});
