function SlideShow(tcName) {
  this.cName     = tcName;
  this.nCurStep  = 0;
  this.TimeoutId = 0;
  this.lStop     = false;
  this.lPause    = false;
  this.oScreen   = null;
  this.Steps     = new Array();
  
  this.SetTimer = function(cCode, nInterval) {
    clearTimeout(this.TimeoutId);
    if (!this.lStop) { this.TimeoutId = setTimeout(cCode, nInterval); }
  }
  this.Start = function(tnStep) { 
    var nStartPoint;
    oJIFS.Reset();
    oSweetSpot.Reset();
    oE1.Reset();
    oE2.Reset();
    oE3.Reset();
    oE4.Reset();
    omlPrinter.Reset();
    omlTxt.Reset();
    omlAll.Reset();
    
    if (typeof tnStep == "number") {
      nStartPoint = tnStep; }
    else {
     aStartPoints = [0,13,21];
     nStartPoint  = Math.floor(Math.random()*3);
     nStartPoint  = aStartPoints[nStartPoint];
    }
    this.oScreen.style.visibility = "inherit"; 
    this.lStop = false; 
    this.nCurStep = nStartPoint; 
    this.Next(); 
  }
  
  this.Next = function() {
    this.nCurStep = this.nCurStep + 1;
    eval(this.Steps[this.nCurStep]);
  }
  
  this.Stop     = function() { this.lStop = true; }
  this.StopNow  = function() { this.lStop = true; clearTimeout(this.TimeoutId); }
  this.Hide     = function() { this.oScreen.style.visibility = "hidden"; }
  this.Pause    = function() { this.lPause = true; }
  this.Continue = function() { 
    if (this.lPause) { this.lPause = false; this.Next(); }
  }
  
}

function SlideShowElement(tcName) {
  this.cName      = tcName;
  this.oEl        = "";
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = 0;
  this.nBegLeft   = 0;
  this.nEndTop    = 0;
  this.nEndLeft   = 0;
  this.nDelay     = 0;
  this.nDelta     = 3;
  this.oSS        = null;
  
  this.Reset = function() {
    this.oEl.style.top  = this.nBegTop;
    this.oEl.style.left = this.nBegLeft;
  }
  
  this.Enter = function() {
    switch(this.cEnterMode) {
    case "SlideDown"  : lDone = this.SlideDown(this.nEndTop); break;
    case "SlideUp"    : lDone = this.SlideUp(this.nEndTop); break;
    case "SlideRight" : lDone = this.SlideRight(this.nEndLeft); break;
    case "SlideLeft"  : lDone = this.SlideLeft(this.nEndLeft); break;
    case "Show"       : lDone = this.Show(); break;
    }
    if (lDone) {this.oSS.SetTimer(this.cName + ".oSS.Next()", this.nDelay) }
    else       {this.oSS.SetTimer(this.cName + ".Enter()", this.nDelay) }
  }  

  this.Exit = function(tnDelay, tnFinalDelay) {
    switch(this.cExitMode) {
    case "SlideDown"  : lDone = this.SlideDown(this.nBegTop); break;
    case "SlideUp"    : lDone = this.SlideUp(this.nBegTop); break;
    case "SlideRight" : lDone = this.SlideRight(this.nBegLeft); break;
    case "SlideLeft"  : lDone = this.SlideLeft(this.nBegLeft); break;
    case "Hide"       : this.oEl.style.visibility = "hidden"; lDone = true; break;
    }
    if (lDone) { 
      if (tnFinalDelay = 0) { this.oSS.Next(); }
      else { this.oSS.SetTimer(this.cName + ".oSS.Next()", tnFinalDelay)} }
    else { 
      this.oSS.SetTimer(this.cName + ".Exit()", tnDelay) 
    }
  }
  
  this.GoHome = function(tnDelay) {
    this.oEl.style.top  = this.nBegTop;
    this.oEl.style.left = this.nBegLeft;
    if (typeof tnDelay == "number") { 
      if (tnDelay = 0) { this.oSS.Next(); }
      else { this.oSS.SetTimer(this.cName + ".oSS.Next()", tnDelay) }
    }
    else { this.oSS.SetTimer(this.cName + ".oSS.Next()", this.nDelay) }
  }
  
  this.Show = function() {
    this.oEl.style.top = this.nEndTop;
    this.oEl.style.visibility = "inherit";
    return true
  }
  this.SlideDown = function(nStopAt) {
    var nCurTop = xTop(this.oEl);
    if (nCurTop != nStopAt) { 
      nCurTop = Math.min(nStopAt, nCurTop + this.nDelta);
      this.oEl.style.top = nCurTop; }
    if (nCurTop < nStopAt) { return false; } else { return true; }
  }
  this.SlideUp = function(nStopAt) {
    var nCurTop = xTop(this.oEl);
    if (nCurTop != nStopAt) { 
      nCurTop = Math.max(nStopAt, nCurTop - this.nDelta);
      this.oEl.style.top = nCurTop; }
    if (nCurTop > nStopAt) { return false; } else { return true; }
  }
  

  this.SlideRight = function(nStopAt) {
    var nCurLeft = xLeft(this.oEl);
    if (nCurLeft != nStopAt) { 
      nCurLeft = Math.min(nStopAt, nCurLeft + this.nDelta);
      this.oEl.style.left = nCurLeft; }
    if (nCurLeft < nStopAt) { return false; } else { return true; }
  }
  this.SlideLeft = function(nStopAt) {
    var nCurLeft = xLeft(this.oEl);
    if (nCurLeft != nStopAt) { 
      nCurLeft = Math.max(nStopAt, nCurLeft - this.nDelta);
      this.oEl.style.left = nCurLeft; }
    if (nCurLeft > nStopAt) { return false; } else { return true; }
  }
  this.BeforeEnter = function() {}
  this.AfterExit   = function() {}

}

JIFS_MainSS.prototype = new SlideShow();
function JIFS_MainSS(tcName) {
  this.cName    = tcName;
  this.Steps[1] = "oJIFS.Exit();";
  this.Steps[2] = "oSweetSpot.BeforeEnter();";
  this.Steps[3] = "oSweetSpot.Enter();";
  this.Steps[4] = this.cName + ".SetTimer('" + this.cName + ".Next()', 5000)";
  this.Steps[5] = "oE1.Enter()";
  this.Steps[6] = this.cName + ".SetTimer('" + this.cName + ".Next()', 300)";
  this.Steps[7] = "oE2.Enter()";
  this.Steps[8] = this.cName + ".SetTimer('" + this.cName + ".Next()', 300)";
  this.Steps[9] = "oE3.Enter()";
  this.Steps[10] = this.cName + ".SetTimer('" + this.cName + ".Next()', 300)";
  this.Steps[11] = "oE4.Enter()";
  this.Steps[12] = "if (!this.lPause) { " + this.cName + ".SetTimer('" + this.cName + ".Next()', 15000) }";
  this.Steps[13] = "oSweetSpot.Exit(1,0);";
  this.Steps[14] = "omlPrinter.GoHome(0);";
  this.Steps[15] = "omlTxt.GoHome(0);";
  this.Steps[16] = "omlAll.Enter();";
  this.Steps[17] = "omlTxt.Enter();";
  this.Steps[18] = this.cName + ".SetTimer('" + this.cName + ".Next()', 300)";
  this.Steps[19] = "omlPrinter.Enter();";
  this.Steps[20] = this.cName + ".SetTimer('" + this.cName + ".Next()', 10000)";
  this.Steps[21] = "omlAll.Exit(1,0);";
  this.Steps[22] = "oJIFS.Enter();";
  this.Steps[23] = this.cName + ".SetTimer('" + this.cName + ".Next()', 10000)";
  this.Steps[24] = "oE1.GoHome(0);";
  this.Steps[25] = "oE2.GoHome(0);";
  this.Steps[26] = "oE3.GoHome(0);";
  this.Steps[27] = "oE4.GoHome(0);";
  this.Steps[28] = this.cName + ".SetTimer('" + this.cName + ".Next()', 1000); this.nCurStep=0;";
}

SweetSpot.prototype = new SlideShowElement();
function SweetSpot(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -280;
  this.nEndTop    = 10;
  this.nBegLeft   = 0;
  this.nEndLeft   = 0;
  this.nDelta     = 8;
  this.BeforeEnter = function() { this.oEl.style.top = -119; this.oSS.Next(); }
}
ProPoly.prototype = new SlideShowElement();
function ProPoly(tcName) {
  this.cName    = tcName;
  this.nBegTop  = -202;
  this.nEndTop  = 0;
  this.nBegLeft = 0;
  this.nEndLeft = 0;
  this.nDelta   = 12;
}
Terasil.prototype = new SlideShowElement();
function Terasil(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideUp";
  this.cExitMode  = "SlideDown";
  this.nBegTop    = 112;
  this.nEndTop    = 0;
  this.nBegLeft   = 182;
  this.nEndLeft   = 0;
  this.nDelta     = 12;
}
Steamer.prototype = new SlideShowElement();
function Steamer(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -202;
  this.nEndTop    = 0;
  this.nBegLeft   = 364;
  this.nDelta     = 12;
}
Plus.prototype = new SlideShowElement();
function Plus(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "Show";
  this.cExitMode  = "Hide";
}
Answer.prototype = new SlideShowElement();
function Answer(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -50;
  this.nEndTop    = 112;
  this.nBegLeft   = 0;
  this.nDelta     = 6;
}
ssmlAll.prototype = new SlideShowElement();
function ssmlAll(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "Show";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -282;
  this.nEndTop    = 10;
  this.nDelta     = 10;
}
ssmlTxt.prototype = new SlideShowElement();
function ssmlTxt(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -202;
  this.nDelta     = 8;
}
ssmlPrinter.prototype = new SlideShowElement();
function ssmlPrinter(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideRight";
  this.cExitMode  = "SlideLeft";
  this.nEndLeft   = 282;
  this.nDelta     = 9;
}
ssJIFS.prototype = new SlideShowElement();
function ssJIFS(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -252;
  this.nEndTop    = 10;
  this.nDelta     = 10;
}



JIFS_FabSS.prototype = new SlideShow();
function JIFS_FabSS(tcName) {
  this.cName    = tcName;
  this.Steps[1] = "oslFab.Enter();";
  this.Steps[2] = this.cName + ".StopNow();";
  
  this.ShowSlide = function(cSlide, oSlide) {
    this.Steps[1] = cSlide + ".Enter();";
    eval(cSlide + ".oEl = oSlide");
    eval(cSlide + ".Reset();");
    eval(cSlide + ".oEl.style.visibility = 'inherit';");
    this.Start(0);
  }
}
ssSingle.prototype = new SlideShowElement();
function ssSingle(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -282;
  this.nDelta     = 12;
}
ssInk.prototype = new SlideShowElement();
function ssInk(tcName) {
  this.cName      = tcName;
  this.cEnterMode = "SlideDown";
  this.cExitMode  = "SlideUp";
  this.nBegTop    = -252;
  this.nDelta     = 12;
}
