$(function() {

  var title = $('title').text();

  $('body').hover(function() {
    $('title').text(title);
  });

  // os / browser specific
  if ($.client.os == 'Windows' || $.client.os == 'Mac')
  {
    // deathwing animation
    var flashvars = {}
    var params = {
      menu: "false",
      base:"/flash/",
      wmode:"opaque"
    };
    var attributes = {
      id: "fdeathwing",
      name: "fdeathwing"
    };
    swfobject.embedSWF("/flash/header-cata.swf", "deathwing", "1000", "290", "8","expressInstall.swf", flashvars  , params, attributes);

    if ($.client.browser == 'Chrome')
    {
      $('nav ul li a').css('text-shadow', 'none');
    }
  }

  // inits
  $('#slider').nivoSlider({
    pauseTime: 10000,
    controlNavThumbs: true,
    controlNavThumbsFromRel: true
  });
  
  $('.tabs').tabs();
  //$('.tabs.rotate').tabs().tabs('rotate', 10000, false);
  $('.tabs.fade').tabs({
    fx: {
      opacity: 'toggle',
      duration: 'fast'
    }
  });

$("#roster").tablesorter({
  textExtraction: function(node) {
    return $(node).find("span.hidden").text()  || node.innerHTML;
  }
});

$('.scrollToTop').click(function() {
  $('html').animate({
    scrollTop:0
  }, 'slow');
});

$('.flash_notice').each(function() {

  var flash = $(this);

  $.timeout(function(){
    flash.slideUp();
  }, 5000);
});

if ($.client.browser == 'Firefox')
{
  $('#judgehype .description').each(
    function() {
      $(this).show();
      $(this).css("height", $(this).height());
      $(this).hide();
    }
    );
}

// ajax
ajaxUpdate('serverStatus', 5 * 60 * 1000);
  //ajaxUpdate('news', 15 * 60 * 1000);
  //ajaxUpdate('judgeHype', 15 * 60 * 1000);
  //ajaxUpdate('stats', 15 * 60 * 1000);
  ajaxUpdate('whoIsOnline', 30 * 1000);
  ajaxUpdate('forum', 60 * 1000);
  ajaxUpdate('teamSpeak', 15 * 1000);
});

showUserInList = function (user_id)
{
  $('#members').tabs('select', 1);
  var member = '#member-' + user_id;
  $.scrollTo(member, 500);
}

toggleJudgehypeDescription = function(id)
{
  var current = $('#judgehype .description.' + id);
  var visible = $('#judgehype .description:visible').not('.' + id);

  if (visible.size() > 0)
  {
    visible.slideUp(function(){
      current.slideToggle();
    });
  }
  else {
    current.slideToggle();
  }
}
