function ImageRotator(params)
{
	params = params || {};
	
	var defaults = {
		id:              null,  // id of the img element
		initialDelay:    1000,  // time to delay after page load
		transitionDelay: 1000,  // time between image transitions
		takeCurrent:     true,  // if true, put the current image at the end of the images array
		images:          []     // array of image hashes, with each hash containing html image attributes
	};
	
	var name;
	for (name in defaults) {
		if (typeof params[name] != 'undefined') {
			this[name] = params[name];
		} else {
			this[name] = defaults[name];
		}
	}
	
	this.showNextImage = this.wrap(this.showNextImage);
	this.onWindowLoad  = this.wrap(this.onWindowLoad);
	
	if (window.addEventListener) {
		addEventListener('load', this.onWindowLoad, false);
	} else if (window.attachEvent) {
		attachEvent('onload', this.onWindowLoad);
	}
}

ImageRotator.prototype.wrap = function (func)
{
	var self = this;
	return function () {
		return func.call(self, arguments);
	}
}

ImageRotator.prototype.showNextImage = function ()
{
	var nextImage = this.images[this.nextImageIndex];
	
	var name;
	for (name in nextImage) {
		this.img.setAttribute(name, nextImage[name]);
	}
	
	this.nextImageIndex = (this.nextImageIndex + 1) % this.images.length;
	
	setTimeout(this.showNextImage, this.transitionDelay);
}

ImageRotator.prototype.onWindowLoad = function (e)
{
	this.img = document.getElementById(this.id);
	
	if (this.takeCurrent) {
		this.images.push({
			src: this.img.src,
			alt: this.img.alt,
			title: this.img.title
		});
	}
	
	this.nextImageIndex = 0;
	
	if (this.initialDelay > 0) {
		setTimeout(this.showNextImage, this.initialDelay);
	} else {
		this.showNextImage();
	}
}