// ImageRevolver, Copyright 2007 Dropit AB, author Stefan Friman
// This code uses parts of X, a Cross-Browser Javascript Library, 
// Distributed under the terms of the GNU LGPL


// The array of ImageRevolver instances
var _xObjs = new Array();

// The object initialization
var ImageRevolver = function( parent, objects, timeout, key ) {
	_xObjs[parent] = this;
	this.parent = parent;
	this.Items = objects;
	this.Image = new Image();
	this.current = 1;
  // Cache the first (next) image
  this.cacheImages();
  
  //Start the timer
  this.timer = window.setInterval("changeImage('" + parent + "')", timeout * 1000);
}

ImageRevolver.prototype.cacheImages = function() 
{
  // Load the next image
  this.Image.src = this.Items[this.current];
  
  // Add to or reset the counter
  if( this.current == (this.Items.length - 1) )
    this.current = 0;
  else 
    this.current++;
} 

// Global function to change the image of the given img-element
function changeImage( obj )
{
  var cont = xGetElementById(obj);
  cont.src = _xObjs[obj].Image.src;
  _xObjs[obj].cacheImages();
}
