/* (c) 2001 Ulrich Kritzner */

function ElViewer_Add_Element(elementname,elapse,left,top)
{
  if (elementname&&elapse)
  {
    this.left[this.count]=left;
    this.top[this.count]=top;
    if (window.document.all)
      this.elements[this.count]=eval("window.document.all."+elementname+".style");
    else
      if (typeof(window.document.getElementById)=="function")
        this.elements[this.count]=window.document.getElementById(elementname).style;
      else
        this.elements[this.count]=eval("window.document."+elementname);
    this.elapse[this.count]=elapse;
    this.count++;
  }
}

function ElViewer_Show_Element(number)
{
  var i;
  this.Stop();
  this.current=number%this.count;
  for (i=0;i<this.count;i++)
  {
    this.elements[i].left=this.hiddenleft;
    this.elements[i].top=this.hiddentop;
  }
  this.elements[this.current].left=this.left[this.current];
  this.elements[this.current].top=this.top[this.current];
}

function ElViewer_Step(_modus)
{
  with (this)
  {
    switch (_modus)
    {
      case 0:
        current=(current+1)%count;
	break;
      case 1:
        current=(current+count-1)%count;
	break;
    }
    ShowElement(current)
  }
}

function ElViewer_TimerFunc()
{
  with (this)
  {
    elements[current].left=hiddenleft;
    elements[current].top=hiddentop;
    switch (modus)
    {
      case 0:
        current=(current+1)%count;
	break;
      case 1:
        current=(current+count-1)%count;
	break;
      case 2:
        if (current<count-1)
          current++;
	else
	  timestep=0;
	break;
      case 3:
        if (current>0)
          current--;
	else
	  timestep=0;
	break;
      case 4:
        if (current<count-1)
          current++;
	else
	{
	  timestep=-1;
	  modus=5;
	}
	break;
      case 5:
        if (current>0)
          current--;
	else
	{
	  timestep=-1;
	  modus=4;
	}
	break;
    }
    elements[current].left=left[current];
    elements[current].top=top[current];
    if (timestep==-1)
      timestep=1;
    else if (timestep>0)
      timestep=elapse[current];
    else if (this.EventHandler)
      this.EventHandler(0);
  }
}

function ElViewer_Set_Event_Handler(eventhandler)
{
  this.EventHandler=eventhandler;
}

function ElViewer_Stop()
{
  var oldrun=this.timestep;
  this.timestep=0;
  if (oldrun)
    if (this.EventHandler)
      this.EventHandler(0);
}

function ElViewer_Run(modus)
{
  this.modus=modus;
  this.Stop();
  this.timestep=1;
  if (this.EventHandler)
    this.EventHandler(1);
  u_timer_continue();
}

function ElViewer(hiddenleft,hiddentop)
{
  this.AddElement=ElViewer_Add_Element;
  this.ShowElement=ElViewer_Show_Element;
  this.TimerFunc=ElViewer_TimerFunc;
  this.SetEventHandler=ElViewer_Set_Event_Handler;
  this.Stop=ElViewer_Stop;
  this.Step=ElViewer_Step;
  this.Run=ElViewer_Run;
  this.hiddenleft=hiddenleft;
  this.hiddentop=hiddentop;
  this.left=new Array();
  this.top=new Array();
  this.elements=new Array();
  this.elapse=new Array();
  this.count=0;
  this.current=0;
  this.timestep=0;
  this.timeval=0;
  this.modus=0;
  u_timer_add_object(this);
}

