//
// nav_hlite1.js - Navigation Highlighting
// Marco Vieth, 03.12.2001
// 0.01  03.12.2001  first tests
// 0.02  02.11.2003  adapted for sshow version 0.10
//

// requires sshow1.js, timer1.js!



var g_debug_flg = 0; // global debug flag (1 = debugging activated)


// Constructor for class Nav_hlite
function Nav_hlite(images, imgidx_list, sleep_min, sleep_rnd, on_duration) {
  // attributes
  this.imgidx_list = imgidx_list; // list of image indizes to change
  this.sleep_min = ((sleep_min) || (sleep_min == 0)) ? sleep_min : 2;
  this.sleep_rnd = ((sleep_rnd) || (sleep_rnd == 0)) ? sleep_rnd : 5;
  this.on_duration = ((on_duration) || (on_duration == 0)) ? on_duration : 1;

  this.hlite_status = 0; // status (0=init, 1=on, 2=off)
  this.hlite_chgimg = 0; // index for image to change

  // methods
  if (!Nav_hlite.prototype) { // old browsers get the methods directly into the object...
    this.change_it1 = Nav_hline_change_it1;
  }

  if (images) {
    this.sshow = new Sshow(images, null, Sshow_set_image_func);
    //this.change_it1();
  }
}

///////////////////////


//
// normally we would create unnamed functions here but for old browsers...
// Nav_hlite.prototype. ... = function(list) { ... }
//

// For new browsers (JS 1.2) set the prototypes...
new Nav_hlite(); // force old browsers to create prototype
if (Nav_hlite.prototype) {
  Nav_hlite.prototype.change_it1 = Nav_hlite_change_it1;
}


function Nav_hlite_change_it1() {
  this.sshow.change_image_auto(0); // switch off interval timer
  var time1 = 1;
  if (!this.hlite_status) { // 0 -> need to initialize
    if (this.imgidx_list) {
      //this.hlite_chgimg = Math.floor(Math.random() * 6) + 2; // select image index
      this.hlite_chgimg = this.imgidx_list[Math.floor(Math.random() * this.imgidx_list.length)];
        // select image index
    }
    time1 = Math.floor(Math.random() * this.sleep_rnd) + this.sleep_min; // timeout until next image (5*rnd+2)

  } else if (this.hlite_status == 1) { // 1: on
    this.sshow.change_image_abs(2, this.hlite_chgimg);
    time1 = this.on_duration; // on=yawn

  } else if (this.hlite_status == 2) { // 1: off
    this.sshow.change_image_abs(0, this.hlite_chgimg);
    this.hlite_status = -1; // restart
    time1 = 1;
  }

  this.hlite_status++; // next status
  this.sshow.change_image_auto(time1, this, 'change_it1');
}

// end

