var now = new Date();
var end;
//var end = new Date("May 29, 2009 19:00:00");

function toSt2( n )
{
  s = "";
  if ( n < 10 ) s += "0";
  return ( s + n ).toString();
}

function toSt3( n )
{
  s = "";
  if ( n < 10 ) s += "00";
  else if ( n < 100 ) s += "0";
  return ( s + n ).toString();
}

function countdown( myEndTime )
{
  var count = 0;

  if ( myEndTime )
  {
    end = myEndTime;
  }

  if ( end )
  {
    d = new Date();
    count = Math.floor( end.getTime() - d.getTime() );
  }

  var elemCountDays    = jQuery( '.countdown #count_days' );
  var elemCountHours   = jQuery( '.countdown #count_hours' );
  var elemCountMinutes = jQuery( '.countdown #count_minutes' );
  var elemCountSeconds = jQuery( '.countdown #count_seconds' );
  var elemTextDays     = jQuery( '.countdown #text_days' );
  var elemTextSeconds  = jQuery( '.countdown #text_seconds' );

  var seconds = '00';
  var minutes = '00';
  var hours   = '00';
  var days    = '0';

  if ( count > 0 )
  {
    miliseconds = toSt3( count % 1000 ); count = Math.floor( count / 1000 );
    seconds     = toSt2( count % 60 );   count = Math.floor( count / 60 );
    minutes     = toSt2( count % 60 );   count = Math.floor( count / 60 );
    hours       = toSt2( count % 24 );   count = Math.floor( count / 24 );
    days        = count;

    var timeout = 60000;

    if ( days == 0 )
    {
      elemCountDays.hide();
      elemTextDays.hide();
      elemCountSeconds.show();
      elemTextSeconds.show();
      timeout = 1000;
    }

    setTimeout( "countdown()", timeout );
  }

  elemCountDays.html( days );
  elemCountHours.html( hours );
  elemCountMinutes.html( minutes );
  elemCountSeconds.html( seconds );
}