/* event-countdown.js -- Copyright (c) 2011 Andrew Leung */

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

var endTime;

function initEventCountdown()
{
	endTime = new Date("July 18, 2011 09:00:00");
	
	updateCountdown();
}

function calculateTimeLeft()
{
	var currentTime = new Date();
	return Math.round((endTime.getTime() - currentTime.getTime()) / 1000);
}

function updateCountdown()
{
  var timeLeft = calculateTimeLeft();
  
  if(timeLeft <= 0)
  {
    endCoutdown();
    return;
  }
  
  var seconds, minutes, hours, days;
  seconds = 0;
  minutes = 0;
  hours = 0;
  days = 0;
  
  // do the calculations for each unit if necessary
  if(timeLeft >= 1) {seconds = timeLeft % 60;}
  if(timeLeft >= 60) {minutes = Math.floor(timeLeft % 3600 / 60);}
  if(timeLeft >= 3600) {hours = Math.floor(timeLeft % 86400 / 3600);}
  if(timeLeft >= 86400) {days = Math.floor(timeLeft / 86400);}
  
  // add leading zero if necessary (to make the display two digits long
  if(seconds < 10) {seconds = "0" + seconds;}
  if(minutes < 10) {minutes = "0" + minutes;}
  if(hours < 10) {hours = "0" + hours;}
  if(days < 10) {days = "0" + days;}
  
  // update the display
  jQuery("#event-countdown-seconds").text(seconds);
  jQuery("#event-countdown-minutes").text(minutes);
  jQuery("#event-countdown-hours").text(hours);
  jQuery("#event-countdown-days").text(days);
  
  // call the update again in 1 second
  setTimeout("updateCountdown()", 1000);
}

function endCoutdown()
{
  jQuery("#event-countdown").text("The tournament is here");
};
/* external-link-modifier.js -- Copyright (c) 2011 Andrew Leung */

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

function initExternalLinkModifier()
{
  //jQuery("a[rel='external']").each(addExternalLinkBehavior);
  jQuery("a[href^='http://'], a[href^='https://']").each(addExternalLinkBehavior);
}

function addExternalLinkBehavior()
{
  jQuery(this).attr("target", "_blank");
};

