if(typeof(XPRIMA) == "undefined") XPRIMA = {}
XPRIMA.SpyShots = function() {
  return {
    articles: [],
    photoPos: 0,
    cycleTimer: null,
    cycleTime: 6000,

    cycle: function() {
      this.stopTimer();
      if(this.photoPos >= this.articles.length) this.photoPos = 0;
      this.updateData(this.photoPos);
      this.photoPos++;
      this.startTimer();
    },
    
    startTimer: function() {
      this.cycleTimer = setTimeout("XPRIMA.SpyShots.cycle()", this.cycleTime);
    },
    
    stopTimer: function() {
      if(this.cycleTimer != null) {
        clearTimeout(this.cycleTimer);
        this.cycleTimer = null;
      }
    },
    
    updateData: function(pos) {    
      if(pos < this.articles.length) {
        var art = this.articles[pos];
        if(art != null) {
          var t = document.getElementById("spy-featured-titlelink");
          var l = document.getElementById("spy-featured-link");
          var a = document.getElementById("spy-featured-abstract");
          var i = document.getElementById("spy-featured-img");
          if(t != null && l != null && a != null && i != null) {
            t.href = art.l;
            t.innerHTML = art.t;
            a.innerHTML = art.a;
            i.style.width = art.f ? "220px" : "150px";
            i.src = art.p;
            l.href = art.l;
          }
        }
        
        for(var x = 0; x < this.articles.length; x++) {
          var p = document.getElementById("spy-featured-" + x.toString());
          if(p != null) {
            p.style.backgroundColor = (x == pos) ? "#DCE8F6" : "#F3F4F8";
          }
        }        
      }
    },
    
    selectArticle: function(pos) {
      this.stopTimer();
      if(pos < this.articles.length) {
        this.updateData(pos);
        this.photoPos = pos;
      }
    }
  }
}();
