//
// Inês Sobral
// EnterWeb
//

/* ************** *
 *  Slide
 * ************** */

//
// init constructor
//
function Slide (sourceImage, description)
{
	this.SourceImage = sourceImage;
	this.Description = description;
}

//
// show slide
//
Slide.prototype.Show = function (slideId, slideDescriptionId)
{    
	var slide = window.document.getElementById (slideId != null ? slideId : 'slide');
	if (slide != null)
	{
		slide.src = this.SourceImage;
	}

	var slideDescription = window.document.getElementById (slideDescriptionId != null ? slideDescriptionId : 'slideDescription');
	if (slideDescription != null)
	{
		slideDescription.innerHTML = this.Description;
	}
}

/* ************** *
 *  SlideShow
 * ************** */

//
// init constructor
//
function SlideShow ()
{
	this.Position = 0;
	this.Slides = new Array();
}

//
// adds a slide to SlideShow
//
SlideShow.prototype.Add = function (slide)
{
	this.Slides[this.Slides.length] = slide;
}

//
// show current slide
//
SlideShow.prototype.Show = function (slideId, slideDescriptionId)
{    
	// show image
	this.Slides[this.Position].Show (slideId, slideDescriptionId);

	// preload next image
	var nextImage = new Image ();

	nextImage.Src = this.Slides[(this.Position + this.Slides.length - 1) % this.Slides.length].SourceImage;
}

//
// goto previous slide
//
SlideShow.prototype.Previous = function (slideId, slideDescriptionId)
{    
	this.Position = (this.Position + this.Slides.length - 1) % this.Slides.length;

	this.Show (slideId, slideDescriptionId);
}

//
// goto next slide
//
SlideShow.prototype.Next = function (slideId, slideDescriptionId)
{    
	this.Position = (this.Position + 1) % this.Slides.length;

	this.Show (slideId, slideDescriptionId);
}


