function PanelRotator() 
{
	this.CurrentSection		= 0;
	this.Delay				= 6;
	this.TimeoutInstance 	= null;
	this.Sections			= new Array();
}

PanelRotator.prototype.AddSection = function(SectionID)
{
	this.Sections[this.Sections.length] = SectionID;
}

PanelRotator.prototype.GetRandomSectionIndex = function()
{
	return Math.floor(Math.random() * this.Sections.length)
}

PanelRotator.prototype.GetPreviousSectionIndex = function()
{
	var NewSectionID = this.CurrentSection - 1;
	if(NewSectionID < 0)
		NewSectionID = this.Sections.length - 1;

	return NewSectionID;
}

PanelRotator.prototype.GetNextSectionIndex = function()
{
	var NewSectionID	= this.CurrentSection + 1;
	NewSectionID		= NewSectionID % this.Sections.length;

	return NewSectionID;
}

PanelRotator.prototype.NavigateSection = function(SectionIndex)
{
    clearTimeout(this.TimeoutInstance);
    
	return this._changeSections(SectionIndex);
}

PanelRotator.prototype.MoveNext = function()
{
    return this.NavigateSection(this.GetNextSectionIndex())
}

PanelRotator.prototype.MovePrevious = function()
{
    return this.NavigateSection(this.GetPreviousSectionIndex())
}

PanelRotator.prototype._changeSections = function(SectionIndex)
{
    this.CurrentSection	= SectionIndex;

	for(var ct = 0; ct < this.Sections.length; ct++)
	{
		var Section = document.getElementById(this.Sections[ct]);	
	    if(ct == this.CurrentSection)
	        Section.style.display = "block";
		else Section.style.display = "none";
	}

	this.AutoPlayNextSection();

	return false;
}

PanelRotator.prototype.AutoPlayNextSection = function(Timer)
{
	if(Timer == null)
		Timer = this.Delay;
	else this.Delay = Timer;
	
	var self = this;
	function relayer()
	{
		self._changeSections(self.GetNextSectionIndex());
	}
		
	this.TimeoutInstance = setTimeout(relayer, Timer * 1000);
}

