/*
  obticker.js
  include file for use of OmanBros.com Ticker
  Author: TheGismo
  Copyright (c)2003 by OmanBros.com. All rights reserved.
  Last update: 17.01.2003

  Contents:
	function obCreateTicker
	object obTicker
	
  This ticker assumes that an image should be panned horizontally
  (left or right direction). So, there must be a layer (span-tag)
  with a proper id-tag including an image (png, jpg or whatever).
  The layer must be absolute positioned.
  
  Following Browsers are supported:
    Microsoft Internet Explorer V 4.x or higher
    Netscape Navigator V 4.x or higher
    
  Javascript V 1.2 is presumed.
*/

/* -------------------------------------------------------------------
  All tickers will be kept in the following array, so that more than
  one ticker can be used on a single web page
*/
var obTickers=new Array()

/* -------------------------------------------------------------------
  function obCreateTicker

  This function creates a new ticker and inserts an entry into the
  obTickers array. Each ticker represents an autonome instance of
  the object obTicker. The parameter tickID is given to identify
  a new object uniquely, so there must not be more than one ticker
  with a given ID. This ID represents also the id of the corresponding
  absolute positioned layer.
  
  wImg and hImg represent the width and height of the image which
  should be panned (left or right). wClip sets the clipping width.
  This can be smaller or larger as the width of the image.
  
  tickTime sets the time in milliseconds when the obTicker's Start
  method should be called again, which recalculates the new positions
  and clipping values. tickRight, if set to true, turns the panning
  from left to right.
  
  If the parameters (except tickID, which must be set) are missing,
  then default values are assumed.
*/
function obCreateTicker(tickID,wImg,hImg,wClip,tickTime,tickRight) {
  if (!tickID) {
    alert("obCreateTicker: No tickID defined!")
    return false
  }
  if (obTickers[tickID]) {
    alert("obCreateTicker: tickID="+tickID+" already defined!")
    return false
  }
  var obt=new obTicker(tickID,wImg,hImg,wClip,tickTime,tickRight)
  obTickers[tickID]=obt
  return obt
}
    
/* -------------------------------------------------------------------
  object obTicker

  This is the object of obTicker, which is responsible of the whole
  ticker functionallity. The constructor is called by obCreateTicker
  and should not be called directly. The obStartTicker method gets
  called on successful creation of the object.
*/
function obTicker(tickID,wImg,hImg,wClip,tickTime,tickRight) {
  if (!tickID) {
    alert("obTicker: No tickID defined!")
    return false
  }
  this.id=tickID
  this.time=tickTime || 20
  this.right=tickRight || false
  this.wImg=wImg || 200
  this.hImg=hImg || 20
  this.wClip=wClip || 200
  this.lPos=0
  this.tPos=0
  if (is.ns5) with (document.getElementById(this.id).style) {
    this.lPos=parseInt(left)
    this.tPos=parseInt(top)
    this.Start=obStartTicker
  } else if (is.ns4 || document.layers) with (document.layers[this.id]) {
    this.lPos=parseInt(left)
    this.tPos=parseInt(top)
    this.Start=obStartTicker
  } else if (document.all) with (document.all[this.id].style) {
    this.lPos=parseInt(left)
    this.tPos=parseInt(top)
    this.Start=obStartTicker
  }
  if (this.right) {
    this.lImg=this.lPos-this.wImg
    this.lClip=this.wImg
    this.rClip=this.wImg
  } else {
    this.lImg=this.wClip
    this.lClip=0
    this.rClip=0
  }
  if (this.Start) this.Start()
  return true
}

function obStartTicker() {
  if (is.ns5) with (document.getElementById(this.id).style) {
    left=this.lImg
    clip='rect(0 '+this.rClip+' '+this.hImg+' '+this.lClip+')'
  } else if (is.ns4 || document.layers) with (document.layers[this.id]) {
    left=this.lImg
    clip.left=this.lClip
    clip.right=this.rClip
    clip.bottom=this.hImg
  } else if (document.all) with (document.all[this.id].style) {
    left=this.lImg
    clip='rect(0 '+this.rClip+' '+this.hImg+' '+this.lClip+')'
  } else return false
  if (this.right) {
    // right panning
    this.lImg++
    if (this.lImg>this.wClip) {
      this.lImg=this.lPos-this.wImg
      this.lClip=this.wImg
      this.rClip=this.wImg
    }
    this.lClip--
    if (this.lClip<0) this.lClip=0
    if (this.lImg>(this.wClip-this.wImg)) this.rClip--
    if (this.rClip<0) this.rClip=0
  } else {
    // left panning
    this.lImg--
    if (this.lImg<(this.lPos-this.wImg)) {
      this.lImg=this.wClip
      this.lClip=0
      this.rClip=0
    }
    if (this.lImg<this.lPos) this.lClip++
    if (this.lClip>this.wImg) this.lClip=this.wImg
    this.rClip++
    if (this.rClip>this.wImg) this.rClip=this.wImg
  }
  setTimeout("obTickers['"+this.id+"'].Start()",this.time)
  return true
}
