// Title: Tigra Scroller PRO
// URL: http://www.softcomplex.com/products/tigra_scroller_pro/
// Version: 2.1
// Date: 01-19-2006 (mm-dd-yyyy)
// Notes: Registration needed to use this script legally.
//	Visit official site for details.
// ----------------------------------------
// set correct path to Tigra Scroller files
var TScroll_path_to_files = 'stackscroller/';


// please, don't change anything below this line
// ----------------------------------------------
var TScroll = [];
document.write('<scr'+'ipt language="JavaScript" src="' + TScroll_path_to_files + 'scroll.' + (document.layers ? 'nn4' : 'dom') + '.js"></scr'+'ipt>');

function TScroll_init (LOOK, BEHAVE, ITEMS) {
  this.id = TScroll.length;
  TScroll[this.id] = this;
  
  this.step = BEHAVE.speed != 0 ? BEHAVE.speed : 1;
  this.interval = BEHAVE.interval? BEHAVE.interval : 50;
  this.t_roll = this.prior = 0;
  this.pseq = this.step < 0 ? [1, 0] : [0, 1];
  this.astep = Math.abs(this.step);
  this.zindex = BEHAVE.zindex?BEHAVE.zindex:0;
  this.items = [];
  this.iauto = BEHAVE.auto;
  this.hide_buttons = BEHAVE.hide_buttons;
  this.nonstop = BEHAVE.nonstop;
  var i, j, 
	  im = this.iauto?{"pa":0, "re":1, "nx":2, "pr":3}:{'up':0,"dn":1},
	  f_ = function () {},
	  ctrl = {
		"s_i": LOOK.s_i,
		"s_b": LOOK.s_b,
		"s_m": LOOK.s_m
  },
  vertical = BEHAVE.vertical,
  w = LOOK.size[0] ? LOOK.size[0] : TScr_DEFAULT.size[0],
  h = LOOK.size[1] ? LOOK.size[1] : TScr_DEFAULT.size[1];

  for(i in im){
	ctrl[i] = LOOK[i] && typeof(LOOK[i]) == "object" ? LOOK[i] : TScr_DEFAULT[i];
  }
  this.height = vertical ? h : w;
  this.distance = typeof(LOOK.distance) == 'number' ? LOOK.distance : this.height;
  this.n_width = vertical?0:LOOK.item_w != null ? LOOK.item_w : w;
  this.pos = 0;
  
  
  this.build = TScr_build;
  this.run = TScr_run;
  this.ctrl = [];
  this.img = [];

  var c = [];
  for(i in im){
		//preload button front image
		j = im[i]*2;
		c[j] = new Image(ctrl[i][2], ctrl[i][3]);	
		c[j].src = ctrl[i][4] ? ctrl[i][4] : TScr_DEFAULT[i][4];
		//preload button mover image
		c[j+1] = new Image(ctrl[i][2], ctrl[i][3]);	
		c[j+1].src = ctrl[i][5] ? ctrl[i][5] : c[j].src;
  }
  this.ctrl.img = c;
  this.move = function (p) { 
    if (this.prior <= p && this.t_roll == 0) {  
      this.prior = 0;
      this.t_roll = setTimeout('TScroll[' + this.id + '].roll('+p+')', this.interval); 
    }
  }; 

  this.stop = function (p) { 
    if (this.prior < p) this.prior = p;
		if (this.t_sleep) {
			clearTimeout(this.t_sleep);
			this.t_sleep = 0;
		}
    if (this.t_roll != 0) {
      clearInterval(this.t_roll);
      this.t_roll = 0;
    }
  };

  this.sleep = function (delay) {
    this.stop(0); 
    this.t_sleep = setTimeout('TScroll[' + this.id + '].wake()', delay * 1000);
  };
  
  this.wake = function () {
    this.ajust(); 
    this.pos -= this.step;
    this.move(0);
  };
  
  this.jump_to = function (n_index) {  
     if (!this.items[n_index]) return;  
     this.pos = - this.img[n_index];  
     this.ajust();  
 };
 
  this.roll = function (p) {
    var i, j, t;

    for (i in this.items)
      for (j in this.pseq)
        if (Math.abs(this.pos + this.items[i].delta[this.pseq[j]]) < this.astep) {
		  var ld = this.items.length - 1;	
          if (document.body && this.b_trans) { 
            x = this.pos + this.items[i].delta[this.pseq[1 - j]];
            this.t = ((x > 0) ^ (this.step > 0) || (x == 0)) ?
              (this.step > 0 ? 
                (i == ld ? [this.img[0], 0] : [this.img[i * 1 + 1], i * 1 + 1]) : 
                (i == 0 ? [this.items[ld].delta[1], ld] : [this.items[i-1].delta[1], i - 1])
              ) : 0;
          }
          if (this.items[i].pause[this.pseq[j]] > 0) {
            this.pos = - this.items[i].delta[this.pseq[j]];
            this.ajust(1);
            return this.sleep (this.items[i].pause[this.pseq[j]]);
          }
        }
    if (this.step > 0 && this.pos + this.img_last < this.astep) this.pos = this.step;
    else if (this.step < 0 && - this.pos < this.astep) this.pos = - this.img_last;
    this.pos -= this.step;
    this.ajust();
    this.t_roll = 0;
	this.move(p);
  };
// event handlers
  if (this.iauto)
    this.mout = this.mover = this.click_pau = this.click_res = this.click_pass = f_;
  else {
    if (this.hide_buttons) this.mover = this.mout = f_;
		this.mout_dn = this.mout_up = this.mover_up = this.mover_dn = f_;
  }
// building HTML
  this.build (w, h, vertical, ctrl, ITEMS);
}

function TScr_run () {  
// size estimations
  this.updatemainlayer('lmain');

  this.main = this.getLayrStyle("lmain");
  this.img_last = this.getImgOffset(this.items.length);
  for (var i in this.items) {
    this.img[i] = this.getImgOffset(i) + this.offset[0];
	var n_pause = this.getImgOffset(i*1 + 1) - this.height + this.offset[1];
	while(n_pause<0) n_pause += this.img_last;
    this.items[i].delta = [this.img[i],n_pause];
  }
  this.img[this.img.length] = this.img_last;
  this.main.visibility = this.lay_show;
  if (this.iauto) {
    this.ctrl.pau = this.getLayrStyle("lpau");
    this.ctrl.res = this.getLayrStyle("lres");
    this.ctrl.nxt = this.getLayrStyle("lnxt");
    this.ctrl.prv = this.getLayrStyle("lprv");
    this.move(0);
  }
  else {
    this.ctrl.up = this.getLayrStyle("laup"); 
    this.ctrl.dn = this.getLayrStyle("ladn");
  }
  this.rollover = function(b_over,n) {
   var o_obj = document.images['ib_' + n+ '_' + this.id];
   if(o_obj) o_obj.src = this.ctrl.img[(b_over?n+1:n)].src;
  };
  //rollover fixes size of the scroller in opera8b
  this.rollover(1,0); //for opera8b compatibility
  this.rollover(0,0); //for opera8b compatibility
// event handlers
  if (this.iauto) {
    this.mout = this.hide_buttons ? 
      function (n) {
		this.rollover(0,n);
        this.ctrl.nxt.visibility = 
        this.ctrl.prv.visibility = 
        this.ctrl.pau.visibility = 
        this.ctrl.res.visibility = this.lay_hide;
        this.move(1);
		return true;
      } : function (n) { this.rollover(0,n);this.move(1);return true; };

    this.mover  = this.hide_buttons ? 
      function (n) { 
		this.rollover(1,n);
        this.ctrl.nxt.visibility = 
        this.ctrl.prv.visibility = this.lay_show; 
        if (this.prior < 2) {
          this.ctrl.pau.visibility = this.lay_show; 
          this.ctrl.res.visibility = this.lay_hide;
        }
        else  {
          this.ctrl.pau.visibility = this.lay_hide; 
          this.ctrl.res.visibility = this.lay_show;
        }
        if(!this.nonstop) this.stop(1); 
		return true;
      } : function (n) {this.rollover(1,n); if(!this.nonstop)this.stop(1);return true;};  
   
    this.click_pau = function () {
      this.ctrl.pau.visibility = this.lay_hide;  
      this.ctrl.res.visibility = this.lay_show;  
      this.stop(2); 
    };

    this.click_res = function () {
      this.ctrl.pau.visibility = this.lay_show; 
      this.ctrl.res.visibility = this.lay_hide;  
      this.prior = 1;
    };

    this.click_pass = function (dir) {
      if (this.step * dir > 0) {
        var i = 0;
        while (i < this.img.length && this.img[i] <= - this.pos) i ++;
        if (i == this.img.length - 1) i = 0;
        this.pos = - this.img[i];
      }
      else {  
        var i = this.img.length - 1;
        while (i >= 0 && this.img[i] >= - this.pos) i --;
        if (i == -1) i = this.items.length-1;
        this.pos = - this.img[i] //+(!this.n_width?this.distance:0);
      }
      this.ajust();
    }
  }
  else {
    if (this.hide_buttons) { 
      this.mover = function (n) { this.rollover(1,n);this.ctrl.up.visibility = this.ctrl.dn.visibility = this.lay_show };
      this.mout  = function (n) { this.rollover(0,n);this.ctrl.up.visibility = this.ctrl.dn.visibility = this.lay_hide };
	  this.mout_dn = this.mout_up = function (n) { this.rollover(0,n);this.mout(); this.stop(1); };
    }
	else this.mout_dn = this.mout_up = function (n) { this.rollover(0,n);this.stop(1) };		
    this.mover_up = function (n) {
      this.rollover(1,n);	
      if (this.hide_buttons) this.mover();
      this.step = - this.astep;
      this.pseq = [0, 1];
      this.move(1); 
    };
    this.mover_dn = function (n) { 
      this.rollover(1,n);
      if (this.hide_buttons) this.mover();
      this.step = this.astep; 
      this.pseq = [1, 0];
      this.move(1); 
    }
  }
}

// Defaults
var TScr_DEFAULT = {
	'size' : [150,100],
	'up' : [130, 4, 16, 16, TScroll_path_to_files + 'aup.gif'],
	'dn' : [130, 80, 16, 16, TScroll_path_to_files + 'adn.gif'],
	'pa' : [110, 80, 16, 16, TScroll_path_to_files + 'pau.gif'],
	're' : [110, 80, 16, 16, TScroll_path_to_files + 'res.gif'],
	'nx' : [130, 80, 16, 16, TScroll_path_to_files + 'nxt.gif'],
	'pr' : [90, 80, 16, 16, TScroll_path_to_files + 'prv.gif'],
	'pix' : TScroll_path_to_files + 'pixel.gif'
}