var objPlayer;
var bStartPlayer = false;

/**
 * Page's OnLoad function that is used to setup the countdown timer
 */
$j(document).ready(function(){
  if (dtCmgNow  > dtShowEnds) {
    //Show is over. Don't do anything
    $j('#show_is_over').show();
    $j('#counter').hide();
    return true;
  }
  else if (dtShowStarts > dtCmgNow ) {
    if (window.console && window.console.log) {
//      console.log('CountdownToDate is in the future, creating countdown timer...');
    }
    $j('#defaultCountdown').countdown({
      until: +dtSecondsTilLive, //set on the main PHP page since we need dynamic date pieces
      onExpiry: start_playlist,
      format: 'DHMS'
    });
  }
  else {
    if (window.console && window.console.log) {
//      console.log('Already past the start time. Go for it!');
    }
    bStartPlayer = true;
    $j('#counter').hide();
  }
});


/**
 * Callback functione xecuted when the swfobject is fully loaded so that we
 * can get the instance of the actual object and store it for future use.
 *
 * @param  obj   SWFObject after it's been fully instantiated
 * @return void
 */
function playerReady(obj) {
  objPlayer = document.getElementById(obj['id']);
  if (bStartPlayer) {
    objPlayer.sendEvent("PLAY","true");
  }
}

/**
 * Callback function executed when the countdown timer hits 00:00:00.
 *
 * @return void
 */
function start_playlist() {
  if (objPlayer) {
    objPlayer.sendEvent("PLAY","true");
  }
  $j('#counter').hide(); //in the header
  $j('#counter').countdown('destroy');

  $j('#jsJoinUsLive').show();
};

