var playList        = new Array();
var bPaused         = true;
var intervalId      = null;


// PUBLIC PLAY FUNCTIONS
function play ()
{
  bPaused = false;
  intervalId = setInterval ("playPlaylist()", 33);
}

function pause ()
{
  bPaused = true;
  clearInterval (intervalId);
}

function playIsPaused ()
{
  return (bPaused);
}

function playClear ()
{
  playList.length = 0;
}

// add one item to playlist
function playAdd(item, bImmediate)
{
  if (bImmediate)
    if (playList.length != 0)
      playList[0] = playList[0] + ";" + item;
    else
      playList[0] = item;
  else
    playList[playList.length] = item;
}

// add array of items to playlist
function playListAdd (items, bImmediate)
{
  if (bImmediate)
  {
    for (var ndx = 0; ndx < items.length; ndx++)
    {
      if (playList.length > ndx)
        playList[ndx] = playList[ndx] + ";" + items[ndx];
      else
        playList[ndx] = items[ndx];
    }
  }
  else
  {
    playList = playList.concat (items);
  }
}

function playAppend (item)
{
  playList.push(item);
}

function playTween(who, what, where, when, how)
{
  var cmds      = new Array ();
  var tween     = new Tween (who, what, where, when, how);

  buildCmdList  (tween, cmds);
  playListAdd   (cmds, tween.when);
}


// PRIVATE PLAY FUNCTIONS
function playPlaylist ()
{
  if (bPaused == false)
  {
    if (playList.length != 0)
    {
      currentSelection = playList.shift();
      //logDebug (currentSelection);
      eval (currentSelection);
      //logDebug ("done");
    }

    if (playList.length == 0)
      clearInterval (intervalId);
  }
}

