// JavaScript Document
/*

Priklad inicializace:
var topSmallImg = new loopSmallImgClass('topSmallImg');
topSmallImg.arrPictures = [['obr1.jpg','','',0],['obr2.jpg','','',0],['obr3.jpg','','',0]];
topSmallImg.init();
// taky definovat dir!!!
topSmallImg.dir = '../neco/';
*/

function loopSmallImgClass(objName) {

  this.actual = 0;
  this.timer = null;
  this.speed = 4000;
  this.dir = './images_top/';
  this.elemId = 'flippingimg';
  this.elem = null;
  this.objName = objName;
  this.arrPictures = new Array( /* [src,title,link,0/1=noveokno],.. */ );

  this.init = function() {
    this.reset();
    this.timerrun();
  }

  this.reset = function() {
    this.actual = 0;
    if (this.timer) clearInterval(this.timer);
    this.elem = document.getElementById(this.elemId);
  }

  this.timerrun = function() {
    this.timer = setInterval(this.objName+'.flipping()',this.speed);
  }

  this.flipping = function() {
    if (!this.elem || this.arrPictures.length<1) return false;
    if (this.arrPictures[this.actual+1]) {
      this.actual++;
    } else {
      this.actual = 0;
    }
    if (this.elem.filters && this.elem.filters[0]) {
      this.elem.filters[0].Apply();
    }
    this.setParams();
    if (this.elem.filters && this.elem.filters[0]) {
      this.elem.filters[0].Play();
    }
  }
  
  this.setParams = function() {
    this.elem.src = this.dir+this.arrPictures[this.actual][0];
    this.elem.alt = this.arrPictures[this.actual][1];
    if (this.elem.parentNode.nodeName=='A') {
      this.elem.parentNode.href = this.arrPictures[this.actual][2];
      this.elem.parentNode.target = (this.arrPictures[this.actual][3]?'_blank':'');
      this.elem.parentNode.title = this.arrPictures[this.actual][1];
    }
  }

  //this.init();
}
