function Loaded() {
  if (PageIsOkayFlag) {
    // Initialize
    CallStatus = document.getElementById('callstatus');
    UpdateFrames();
  }
}

function PP(d1x, d1y, d1f, d2x, d2y, d2f, d3x, d3y, d3f, d4x, d4y, d4f, d5x, d5y, d5f, d6x, d6y, d6f, d7x, d7y, d7f, d8x, d8y, d8f) {
  this.d1x = d1x;  this.d1y = d1y;  this.d1f = d1f;
  this.d2x = d2x;  this.d2y = d2y;  this.d2f = d2f;
  this.d3x = d3x;  this.d3y = d3y;  this.d3f = d3f;
  this.d4x = d4x;  this.d4y = d4y;  this.d4f = d4f;
  this.d5x = d5x;  this.d5y = d5y;  this.d5f = d5f;
  this.d6x = d6x;  this.d6y = d6y;  this.d6f = d6f;
  this.d7x = d7x;  this.d7y = d7y;  this.d7f = d7f;
  this.d8x = d8x;  this.d8y = d8y;  this.d8f = d8f;
}

function SetCurObject(I) {
  if (I == 1)      CurObject = document.getElementById('SpotA');
  else if (I == 2) CurObject = document.getElementById('SpotB');
  else if (I == 3) CurObject = document.getElementById('SpotC');
  else if (I == 4) CurObject = document.getElementById('SpotD');
  else if (I == 5) CurObject = document.getElementById('SpotE');
  else if (I == 6) CurObject = document.getElementById('SpotF');
  else if (I == 7) CurObject = document.getElementById('SpotG');
  else if (I == 8) CurObject = document.getElementById('SpotH');
}

function UpdateFrames() {
  // This function shows/hides dancer icons and start buttons
  var CurVis;
  var CurHeader;
  var OppVis;
  var I;

  // Show/Hide dancer icons
  if (DancersDisplayedFlag) {
    CurVis = 'visible';
  } else {
    CurVis = 'hidden';
  }
  for (I = 1; I <= 8; I++) {
    SetCurObject(I);
    with (CurObject.style) {visibility = CurVis};
  }

  // Show/Hide start buttons
  if (InitIpFlag) {
    CurVis = 'hidden';
    OppVis = 'hidden';
    CurHeader = 'text/inprogress.gif';
  } else {
  }
  CurVis = 'visible';
  OppVis = 'visible';
  CurObject = document.getElementById('NewButtons');
  with (CurObject.style) {visibility = CurVis};
  CurObject = document.getElementById('WriteButtons');
  with (CurObject.style) {visibility = OppVis};
}

function FrameZero() {
  IFrame = 0;
  FrameGetData();
  UpdateDancers();
  DancersDisplayedFlag = true;
  UpdateFrames();
  UpdateCallStatus();
}

function FrameNext() {
  if (IFrame < NFrame) {	 
    IFrame++;
    FrameGetData(); 
    UpdateDancers();
    UpdateCallStatus();
  }			 
}

function FramePrevious() {
  if (IFrame > 0) {	 
    IFrame--;
    FrameGetData(); 
    UpdateDancers();
    UpdateCallStatus();
  }			 
}

function FramePlay() {
  if (!PauseFlag) {
    FrameNext();
    if (IFrame < NFrame) window.setTimeout('FramePlay();',FrameDelay);
  }	 
}

function FramePlayBackward() {
  if (!PauseFlag) {
    FramePrevious();
    if (IFrame > 0) window.setTimeout('FramePlayBackward();',FrameDelay);
  }		
}

function UpdateCallStatus () {
  if (IFrame == 0) {
    CallStatus.innerHTML = "BEFORE (Frame " + IFrame + ")";
  } else if (IFrame == NFrame) {
    CallStatus.innerHTML = "AFTER (Frame " + NFrame + ")";
  } else {	
    CallStatus.innerHTML= "Frame " + IFrame + " out of " + NFrame;
  }	 
}

function StartPlay() {
  PauseFlag = true;
  window.setTimeout('PauseFlag = false; FramePlay();',FrameDelay * 2);
}

function StartPlayBackward() {
  PauseFlag = true; 
  window.setTimeout('PauseFlag = false; FramePlayBackward();',FrameDelay * 2);
}

function FrameGetData() {
  X[1] = Frame[IFrame].d1x; Y[1] = Frame[IFrame].d1y; Facing[1] = Frame[IFrame].d1f;
  X[2] = Frame[IFrame].d2x; Y[2] = Frame[IFrame].d2y; Facing[2] = Frame[IFrame].d2f;
  X[3] = Frame[IFrame].d3x; Y[3] = Frame[IFrame].d3y; Facing[3] = Frame[IFrame].d3f;
  X[4] = Frame[IFrame].d4x; Y[4] = Frame[IFrame].d4y; Facing[4] = Frame[IFrame].d4f;
  X[5] = Frame[IFrame].d5x; Y[5] = Frame[IFrame].d5y; Facing[5] = Frame[IFrame].d5f;
  X[6] = Frame[IFrame].d6x; Y[6] = Frame[IFrame].d6y; Facing[6] = Frame[IFrame].d6f;
  X[7] = Frame[IFrame].d7x; Y[7] = Frame[IFrame].d7y; Facing[7] = Frame[IFrame].d7f;
  X[8] = Frame[IFrame].d8x; Y[8] = Frame[IFrame].d8y; Facing[8] = Frame[IFrame].d8f;
}

function UpdateDancers()
{
  var I;
  for (I = 1; I <= 8; I++) {
    if (X[I] != -1) {
      SetCurObject(I);
      with (CurObject.style) {left = X[I] - 80; top = Y[I] - 60;}
      with (CurObject) {src = GifPathname(DanId[I], Facing[I])};
    }	 
  }
}

function CanBeCalled(I)
{
  return true;
}

