
/**
 * Player Variable
 *
 * Set a variable for controlling the player.
 */
var player;

function playerReady(obj) {
	player = document.getElementById(obj['id']);
};

/**
 * Document Ready
 *
 * This is fired off as soon as possible on browser load.
 * Not all page elements may be ready yet.
 */
$(document).ready(function(){

	// Hide the countdown text in the right sidebar because the image has the text.
	$('#sidebar-right .countdown').css('text-indent', '-9999px');
	$('#sidebar-right .countdown .countdown-date').css('text-indent', '0px');
	
	/* Hide the embed form. */
	$('#embed-dropdown').hide();
	
	/* Get the countdown dates for every countdown and begin counting down. */
	$('.countdown').each(function(){
		var cd_date = $(this).children('.countdown-date').html(); // Date must be in military format.
		var year = cd_date.substr(0, 4);
		var month = cd_date.substr(5, 2);
		var day = cd_date.substr(8, 2);
		var hour = cd_date.substr(11, 2);
		var minute = cd_date.substr(14, 2);
		var second = cd_date.substr(17, 2);
		// Substract 1 month to make it the right date for the function.
		month--;
		var c_date = new Date(year, month, day, hour, minute, second); 
		var html = $(this).html();
		html = html.replace('on:', 'in:'); // Change the text to reflect the countdown.
		$(this).html(html);
		$(this).children('.countdown-date').countdown({
			until: c_date,
			layout: '<span class="countdown-days">{dnn}</span> &nbsp;<span class="countdown-hours">{hnn}</span> &nbsp;<span class="countdown-minutes">{mnn}</span> &nbsp;<span class="countdown-seconds">{snn}</span>'
		}); 
	});

	/* Slide down the embed form on the click of the embed button. */
	$('#embed').toggle(
		function(){
			$('#embed-dropdown').slideDown();
		},
		function(){
			$('#embed-dropdown').slideUp();
		}
	);
	
	/* Open the facebook embed code in a new window. */
	$('#embed-facebook').click(function(event){
		event.preventDefault();
		window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(location.href) + '&amp;t=' + encodeURIComponent(document.title), 'facebook', 'width=600,height=425,toolbar=no,status=no');
		 return false;
	});
	

	/* Set the replay button by telling it to rewrite its own html. */
	$('#replay-link a').click(function(event){
		event.preventDefault();
		player.sendEvent("STOP");
		player.sendEvent("PLAY","true");
	})

});


/**
 * Window Load
 *
 * Called when everything is loaded and in its place
 */
$(window).load(function(){
	
});



