// JavaScript Document
jQuery.noConflict();

jQuery(document).ready(function(){
    initTop();
});

var countdownDiff;

function initTop() {
  jQuery("#logo").fadeIn(250, function(){
    jQuery("#sony-ericsson-wta").fadeIn(250, function(){
      jQuery("#e-boks-wta").fadeIn(250, function(){
        jQuery("#sony-ericsson").fadeIn(250, function(){
          jQuery("#tournament-headline").fadeIn();
          jQuery("#global-menu").fadeIn();
          jQuery("#login-status").fadeIn();
          initCountdown();
        });
      });
    });
  });
}

function initCountdown() {
  countdownDiff = jQuery("#countdown #time-diff").text();
  if(countdownDiff > 0){
    jQuery("#countdown").fadeIn();
    setCountdownValues();
    setInterval('setCountdownValues()', 60000);
  } else {
    jQuery("#live-score").fadeIn();
  }
}

function setCountdownValues() {
  countdownDiff = countdownDiff - 1000*60;
  var localDiff = countdownDiff;

  var days = Math.floor(localDiff/(1000*60*60*24));
  localDiff = localDiff - days*1000*60*60*24;
  var hours = Math.floor(localDiff/(1000*60*60));
  localDiff = localDiff - hours*1000*60*60;
  var minutes = Math.floor(localDiff/(1000*60)); 
  
  jQuery("#countdown #countdown-days").text(days);
  jQuery("#countdown #countdown-hours").text(hours);
  jQuery("#countdown #countdown-mins").text(minutes);
}
