/* Rotating partypic javascript */

var nsvPartypics = new Array();
var nsvPartyPicInterval = null;
var speed = 2;
var timeOutStart = 100;
var transparancyStart = 20;
var zIndexDown = "0";
var zIndexNext = "10";
var zIndexTop = "20";

function nsvPartypicUpdate_nofade() {
  if (this.down) {
    if (this.current == 0) {
      this.down = false;
      this.current ++;
    } else {
      this.images[this.current].visible = false;
      this.current --;
    }
  } else {
    if (this.current == this.images.length-1) {
      this.down = true;
      this.images[this.current].visible = true;
    } else {
      this.images[this.current].visible = true;
      this.current ++;
    }
  }
  for (var j = 0; j < this.images.length; j++) {
    if (this.images[j].visible) {
      this.images[j].element.style.display = "inline";
    } else {
      this.images[j].element.style.display = "none";
    }
  }
}

function setTransparancy(element, alpha) {
  element.style.opacity = alpha;
  element.style.KHTMLOpacity = alpha;
  element.style.filter = "alpha(opacity=" + Math.round(alpha*100) + ")"; 
}

function reshuffle() {
  var i;
  for (i = 0; i < this.images.length; i++) {
    this.images[i].element.style.zIndex = zIndexDown;
    setTransparancy(this.images[i].element, 1.0);
    this.images[i].element.style.display = "none";
  }
  //Set next image under top:
  this.images[(this.current + 1) % this.images.length].element.style.zIndex = zIndexNext;
  this.images[(this.current + 1) % this.images.length].element.style.display = "inline";

  //Set current image on top:
  //setTransparancy(this.images[this.current].element,1.0);
  this.images[this.current].element.style.zIndex = zIndexTop;
  this.images[this.current].element.style.display= "inline";
}

function nsvPartypicUpdate() {
  var image = this.images[this.current];
  if (image.timeOut < 1) {
    image.timeOut = 0;
    this.current = (this.current + 1) % this.images.length;
    image.timeOut = timeOutStart;
    this.reshuffle();
  } else {
    if (image.timeOut < transparancyStart)
      setTransparancy(this.images[this.current].element,image.timeOut/transparancyStart);
    image.timeOut -= speed;
  }
}

function nsvPartypicUpdates() {
  /*
  for(var i = 0; i < nsvPartypics.length; i++) {
    nsvPartypics[i].update();
  }
  */
  nsvPartypics[0].update();
}

function nsvPartyPic(id, doInterval) {
  var parent = document.getElementById(id);
  var image = parent.getElementsByTagName("span");
  this.images = new Array();
  for (var j = 0; j < image.length; j++) {
    this.images[j] = new Object();
    this.images[j].element = image[j];
    this.images[j].visible = true;
    this.images[j].timeOut = timeOutStart;
    this.images[j].alpha = 100;
  }
  this.current = image.length - 1;

  this.down = true;
  //this.update = nsvPartypicUpdate_nofade;
  this.update = nsvPartypicUpdate;
  this.reshuffle = reshuffle;
  this.reshuffle();
  nsvPartypics[nsvPartypics.length] = this;
  if ((nsvPartyPicInterval == null) && (doInterval == true))
    nsvPartyPicInterval = window.setInterval(nsvPartypicUpdates, 100);
}

