/* *********************************************************
T I C K E R   C O N T R O L
Copyright (C) 2004, Comitas AG
All rights reserved.


------------------------------------
Annotation
------------------------------------
p_ObjectName has to have the same name as your object


------------------------------------
Before you start
------------------------------------
First Steps: 
edit Body-Tag: <body onLoad="eval(tickerOnLoad);">
include js-file between header-tags: 
<script language="JavaScript" src="ticker.js" type="text/javascript"/>


------------------------------------
How to use: (simple version)
------------------------------------
<script language="JavaScript">
var Ticker1 = new Ticker("Ticker1");
document.write(Ticker1.getHeader());
document.write('Hello World');
document.write(Ticker1.getFooter());
</script>

  or

<script language="JavaScript">
var Ticker1 = new Ticker("Ticker1");
Ticker1.simpleStart('Hello World')
</script>

------------------------------------
How to use 2: 
------------------------------------
<script language="JavaScript">
var Ticker1 = new Ticker("Ticker1");
Ticker1.boxheight    = $l_strTickerHeight;
Ticker1.boxwidth    = $l_strTickerWidth;
Ticker1.speed      = $l_strTickerSpeed;
Ticker1.flowDirection  = ${l_strTickerFlowDirection};
Ticker1.params      = " onDblClick='Ticker1.changeDirection()' onclick='(Ticker1.bMouseOver == 0) ? Ticker1.bMouseOver = 1 : Ticker1.bMouseOver = 0' ";
document.write(Ticker1.getHeader());
</script>

Write Ticker-Content here

<script language="JavaScript">
document.write(Ticker1.getFooter());
</script>

------------------------------------
Advanced Features and properties
------------------------------------
Parameter:  Ticker1.params
  > to stop the ticker just click once, to restart it click again
  > Ticker1.params = " onclick='(Ticker1.bMouseOver == 0) ? Ticker1.bMouseOver = 1 : Ticker1.bMouseOver = 0' ";
Styles:    Ticker1.styles
  > Ticker1.divStyles = "background-color : Blue;"
Width:    Ticker1.boxwidth
Height:    Ticker1.boxheight
Speed:    Ticker1.speed
Direction:  Ticker1.flowDirection (0=up, 1=down)
Pixel Step: Ticker1.pixelstep
Stop:    Ticker1.stopTicker()
Direction:  Ticker1.changeDirection()
********************************************************** */

var tickerCount = 0;
var tickerOnLoad = '';

function Ticker(p_ObjectName)
{
  tickerCount ++;
  tickerOnLoad += p_ObjectName + '.TickerOnload();';

  this.boxheight  = 120;
  this.boxwidth   = 275;
  this.speed      = 75;
  this.pixelstep  = 1;
  this.flowDirection = 0;
  this.bMouseOver = 0;
  this.objectName = p_ObjectName;
  this.params  = '';
  this.styles  = '';

  this.ns4        = (document.layers)? true : false;
  this.ie4        = (document.all && !this.ie4) ? true : false;
  this.ie5        = (document.all && this.ie4)? true : false;
  this.ns6        = (this.ie4 && navigator.appName.indexOf("Netscape") >= 0) ? true : false;
  this.w3c        = (document.getElementById) ? true : false;

  this.inner;
  this.outer;
  this.elementheight;
  this.strLayerInner = "LayerInner" + tickerCount;
  this.strLayerOuter = "LayerOuter" + tickerCount;

  this.stopTicker    = funcStopTicker;
  this.changeDirection = funcChangeDirection;
  this.getScrollBox  = funcScrollBox;
  this.getHeader    = funcTickerHead;
  this.getFooter    = funcTickerFoot;
  this.TickerOnload  = funcTickerOnload;
  this.simpleStart  = funcStart;

}

function funcTickerOnload()
{
  this.inner         = (this.ns4) ? document.layers[this.strLayerOuter].document.layers[this.strLayerInner] : (this.ie4) ? document.all[this.strLayerInner] : document.getElementById(this.strLayerInner);
  this.elementheight = (this.ns4) ? this.inner.document.height : this.inner.offsetHeight;

  if (this.ns4)
  {
    //document.outer.clip.width        = boxwidth;
    //document.outer.clip.height       = boxheight;
    document.layers[this.strLayerOuter].clip.width    = this.boxwidth;
    document.layers[this.strLayerOuter].clip.height   = this.boxheight;
    this.inner.top                   = (this.flowDirection == 1) ? - this.elementheight : this.boxheight - 2;
    this.inner.clip.width              = this.boxwidth - 4;
    this.inner.clip.height             = this.elementheight;
    //document.outer.visibility        = "show";
    document.layers[this.strLayerOuter].visibility    = "show";
    this.inner.visibility               = "show";
  }
  else
  {
    this.inner.style.top            = ((this.flowDirection == 1)? - this.elementheight : this.boxheight - 2) + 'px';
    this.inner.style.clip           = 'rect(0px, ' + (this.boxwidth - 4) + 'px, ' + this.elementheight + 'px, 0px)';
    this.inner.style.visibility     = "visible";
  }

  setInterval(this.objectName + '.getScrollBox()', this.speed);
}

function funcTickerHead()
{
  var txtHead = '<div style="width:' + this.boxwidth + 'px; height:' + this.boxheight + 'px; overflow: hidden;">';
  txtHead += (this.ns4) ? '<table cellpadding=0 cellspacing=0 border=0 height=' + this.boxheight + ' width=' + this.boxwidth + '><tr><td><ilayer name="' + this.strLayerOuter + '" visibility="hidden" width="' + this.boxwidth + '" height="' + this.boxheight + '" style="' + this.styles + '">'  : '<div id="' + this.strLayerOuter + '" style="position:relative; width:' + this.boxwidth + '; height:' + this.boxheight + '; visibility:visible; overflow:hidden;' + this.styles + '" >';
  txtHead += (this.ns4) ? '<layer  name="' + this.strLayerInner + '"  width="' + (this.boxwidth-4) + '" height="' + (this.boxheight-4) + '" visibility="hidden" left="2" top="2" >' : '<div id="' + this.strLayerInner + '"  style="position:absolute; visibility:hidden; left:2px; top:2px; width:'+(this.boxwidth-4)+'; overflow:hidden; cursor:default"' + this.params + '>';
  return txtHead;
}

function funcTickerFoot()
{
  return (this.ns4) ? '</layer></ilayer></td></tr></table></div>' : '</div></div></div>';  
}

function funcScrollBox()
{
  if (this.bMouseOver == 0)
  {
    if (this.ns4)
    {
      this.inner.top += (this.flowDirection == 1)? this.pixelstep: - this.pixelstep;

      if (this.flowDirection == 1)
      {
        if (this.inner.top > this.boxheight)
          this.inner.top = - this.elementheight;
      }
      else
      {
        if(this.inner.top < 2 - this.elementheight)
          this.inner.top = this.boxheight + 2;
      }
    }
    else
    {
      this.inner.style.top = parseInt(this.inner.style.top) + ((this.flowDirection == 1)? this.pixelstep: - this.pixelstep) + 'px';

      if (this.flowDirection == 1)
      {
        if (parseInt(this.inner.style.top) > this.boxheight)
          this.inner.style.top = - this.elementheight + 'px';
      }
      else
      {
        if (parseInt(this.inner.style.top) < 2 - this.elementheight)
          this.inner.style.top = this.boxheight + 2 + 'px';
      }
    }
  }
}

function funcStart(p_strMsg)
{
  document.write(this.getHeader());
  document.write(p_strMsg);
  document.write(this.getFooter());
}

function funcStopTicker()
{
  if(this.bMouseOver == 0)
    this.bMouseOver = 1;
  else
    this.bMouseOver = 0;
}

function funcChangeDirection()
{
  if(this.flowDirection == 1)
    this.flowDirection = 0;
  else
    this.flowDirection = 1;
}
