/* 
Name:
	mooSlideshow
*/
function mooSlideShow()
{
	//declare the class variables
	this.timerMs = 0;
	this.fadeDuration = 0;
	this.slides = null;
	this.parentId = null; 
	this.count = 0;
	this.currentIndex = 0; 
	this.nextIndex = 0;
	this.maxIndex = 0;
	
	this.initialise = function(sourceDiv, ms, fadeMs)
	{
		this.parentId = sourceDiv.id;
		this.timerMs = ms;
		this.fadeDuration = fadeMs;
		
		var sel = "#" + this.parentId + " div.Slide";
		this.slides = $$(sel);
		this.count = this.slides.length;
		this.maxIndex = this.count - 1;
		
		//fix bug where cross fade only happens on second round
		for(var i=1; i<this.count; i++)
		{
			var s = this.slides[i];
			var fixBugFx  = new Fx.Tween(s, {duration: 10});
			fixBugFx.set('display', 'none');
			fixBugFx.set('opacity', 0);
		}
		this.setNextPage();
	}
	
	this.setNextPage = function()
	{
		this.currentIndex = this.nextIndex;
		this.nextIndex = (this.currentIndex + 1);
		
		if (this.nextIndex > this.maxIndex)
			this.nextIndex = 0;

		//and set the function to call the next page			
		var callShowNextPage = function()
		{
			this.showNextPage();
		}
		callShowNextPage.delay(this.timerMs, this);
	}
	
	this.showNextPage =function()
	{
		var d = this.fadeDuration;
		var currentSlide = this.slides[this.currentIndex];
		var nextSlide = this.slides[this.nextIndex];
		
		var fadeOutFx = new Fx.Tween(currentSlide, {duration: d});
		fadeOutFx.set('display', 'block');
		fadeOutFx.start('opacity', 0);

		var fadeInFx = new Fx.Tween(nextSlide, {duration: d});
		fadeInFx.set('display', 'block');
		fadeInFx.start('opacity', 1);
		
		this.setNextPage();
	}
}


