function NemoImageCarouselController(carouselElementID, speed)
{
	this.index = 0;
	this.speed = speed;
	this.carouselElementID = carouselElementID;
	this.init();
}

function CarouselUpdate(carousel)
{
	
	carousel.update();	
	
}

NemoImageCarouselController.prototype.init = function()
{
	this.carouselElement = document.getElementById(this.carouselElementID);
	// hide all images except top
	var elements = this.carouselElement.getElementsByTagName("*");
	
	// randomise start
	this.index = Math.floor(Math.random()*(elements.length));
	
	// Start timer
	CarouselUpdate(this);
	
}

NemoImageCarouselController.prototype.update = function()
{
	
	// hide all images except top
	var elements = this.carouselElement.getElementsByTagName("*");
	
	var nextIndex = 0;
	if(this.index < (elements.length - 1)) nextIndex = this.index + 1;
		
	// swop images 
	$(elements[this.index]).fadeOut(this.speed);
	$(elements[nextIndex]).fadeIn(this.speed);
	
	this.index = nextIndex;
	
	setTimeout(CarouselUpdate, (this.speed * 2), this);
}
