var ImageRotator = {
	_image_array: [],
	_image_count: 0,
	_current_image: null,
	_container: null,
	_display_style: 'inline',

	load_image_array: function(container) {
		elements = container.getElementsByTagName('img')
		for (var i=0; i < elements.length; i++) {
			img = elements[i]
			this._image_array[this._image_count] = img;
			this._image_count++;
			this._display_style = img.style.display;
			if (this._image_count != 1) { img.style.display = 'none'; }
		}
	},
	rotate: function(interval) {
			this.show_next_image();
			setTimeout('ImageRotator.rotate('+interval+')', interval);
	},
	show_next_image: function() {
		if (this._current_image != null) {
			// hide the last image we were looking at
			this._image_array[this._current_image].style.display = 'none';
			// Move onto the next image
			if (++this._current_image == this._image_count) { this._current_image = 0; }
			// show the next image
			this._image_array[this._current_image].style.display = this._display_style;
		}
		else { // this is the first run so we don't need to set any displays
			this._current_image = 0;
		}
	},
	start_rotating_images: function(id, interval) {
		if (this._container = document.getElementById(id)) {
			this.load_image_array(this._container);
			if (this._image_count > 0) { 
				if (this._image_count > 1) { this.rotate(interval || 5000); }
			}
			else {
				// alert('ImageRotator Error: No images found to rotate through.');
			}
		}
		else {
			alert('ImageRotator Error: Container id not found: '+id);
		}
	}
	
}
