/**********************************************/
// Functions
/**********************************************/
function ImageRotatorPreviousPicture(sId)
{
	if (window.oImageRotatorManager)
	{
		var oRotator = oImageRotatorManager.FindRotator(sId);
		if (oRotator)
		{
			oRotator.PreviousPicture();
		}
	}
}
function ImageRotatorPlay(sId)
{
	if (window.oImageRotatorManager)
	{
		var oRotator = oImageRotatorManager.FindRotator(sId);
		if (oRotator)
		{
			oRotator.Play();
		}
	}
}
function ImageRotatorPause(sId)
{
	if (window.oImageRotatorManager)
	{
		var oRotator = oImageRotatorManager.FindRotator(sId);
		if (oRotator)
		{
			oRotator.Pause();
		}
	}
}
function ImageRotatorNextPicture(sId)
{
	if (window.oImageRotatorManager)
	{
		var oRotator = oImageRotatorManager.FindRotator(sId);
		if (oRotator)
		{
			oRotator.NextPicture();
		}
	}
}
/**********************************************/
// Class CImageRotatorConfig
/**********************************************/
function CImageRotatorConfig()
{
	//Attributes
	this.NavigationBarStyle = "ImageRotatorNavigationBar";
	this.TitleBarStyle = "ImageRotatorTitleBar";
	this.PictureBoxStyle = "ImageRotatorPictureBox";
	this.PreviousButton = "<img src=\"../images/icons/imagerotatorprevious.gif\" border=\"0\">";
	this.NextButton = "<img src=\"../images/icons/imagerotatornext.gif\" border=\"0\">";
	this.PlayButton = "<img src=\"../images/icons/imagerotatorplay.gif\" border=\"0\">";
	this.PauseButton = "<img src=\"../images/icons/imagerotatorpause.gif\" border=\"0\">";
	this.iTimerFrequency = 4000;  //miliseconds
	this.PreviousButtonTitle = "Anterior";
	this.PlayButtonTitle = "Play";
	this.PauseButtonTitle = "Pausa";
	this.NextButtonTitle = "Siguiente";
	
	//Methods
}
/**********************************************/
// Class CImageRotatorPicture
/**********************************************/
function CImageRotatorPicture(sId, sTitle, sPictureName, sLinkUrl, sText)
{
	//Attributes
	this.Id = sId;
	this.Title = sTitle;
	this.PictureName = sPictureName;
	this.LinkUrl = sLinkUrl;
	this.Text = sText;
	
	//Methods
	this.GetCode = CImageRotatorPictureGetCode;
}
function CImageRotatorPictureGetCode(iWidth, iHeight)
{
	var sCode = "";
	if (this.LinkUrl) sCode += "<a href=\"" + this.LinkUrl + "\" title=\"" + (this.Text ? this.Text : this.Title)+ "\">";
	sCode += "<img src=\"" + this.PictureName + "\" border=\"0\" alt=\"" + (this.Text ? this.Text : this.Title)+ "\" id=\"" + this.Id + "\"" + (iWidth ? " width=\"" + iWidth + "\"" : "") + "" + (iHeight ? " height=\"" + iHeight + "\"" : "") + ">";
	if (this.LinkUrl) sCode += "</a>";
	return sCode;
}
/**********************************************/
// Class CImageRotatorRotator
/**********************************************/
function CImageRotatorRotator(sId, iPictureWidth, iPictureHeight, iTimerFrequency)
{
	//Attributes
	this.Id = sId;
	this.PictureWidth = iPictureWidth;
	this.PictureHeight = iPictureHeight;
	this.Pictures = new Array();
	this.TimerId = null;
	this.TimerFrequency = (iTimerFrequency ? iTimerFrequency : oImageRotatorConfig.iTimerFrequency);
	this.Index = 0;
	
	//Methods
	this.AddPicture = CImageRotatorRotatorAddPicture;
	this.GetNavigationBar = CImageRotatorRotatorGetNavigationBar;
	this.GetCode = CImageRotatorRotatorGetCode;
	this.Draw = CImageRotatorRotatorDraw;
	this.PreviousPicture = CImageRotatorRotatorPreviousPicture;
	this.Play = CImageRotatorRotatorPlay;
	this.Pause = CImageRotatorRotatorPause;
	this.NextPicture = CImageRotatorRotatorNextPicture;
	this.GetTitleBar = CImageRotatorRotatorGetTitleBar;
	this.GetPictureBox = CImageRotatorRotatorGetPictureBox;
	this.DrawCurrentPicture = CImageRotatorRotatorDrawCurrentPicture;
	this.StartTimer = CImageRotatorRotatorStartTimer;
	this.StopTimer = CImageRotatorRotatorStopTimer;
	this.TimerExec = CImageRotatorRotatorTimerExec;
}
function CImageRotatorRotatorAddPicture(sTitle, sPictureName, sLinkUrl, sText)
{
	this.Pictures[this.Pictures.length] = new CImageRotatorPicture(this.Id + "_" + this.Pictures.length, sTitle, sPictureName, sLinkUrl, sText);
	return this.Pictures[this.Pictures.length - 1];
}
function CImageRotatorRotatorGetTitleBar()
{
	var sCode = "";
	sCode += "<div id=\"" + this.Id + "_divTitleBar\" class=\"" + oImageRotatorConfig.TitleBarStyle + "\">\n";
	sCode += "&nbsp;";
	sCode += "</div>\n";
	return sCode;
}
function CImageRotatorRotatorGetPictureBox()
{
	var sCode = "";
	sCode += "<div id=\"" + this.Id + "_divPictureBox\" class=\"" + oImageRotatorConfig.PictureBoxStyle + "\">\n";
	sCode += "&nbsp;";
	sCode += "</div>\n";
	return sCode;
}
function CImageRotatorRotatorGetNavigationBar()
{
	var sCode = "";
	sCode += "<div id=\"" + this.Id + "_divNavigationBar\" class=\"" + oImageRotatorConfig.NavigationBarStyle + "\">\n";
	sCode += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
	sCode += "<tr valign=\"middle\">\n";
	sCode += "<td align=\"center\"><a href=\"javascript:ImageRotatorPreviousPicture('" + this.Id + "');\" title=\"" + oImageRotatorConfig.PreviousButtonTitle + "\">" + oImageRotatorConfig.PreviousButton + "</a></td>\n";
	sCode += "<td width=\"10\"></td>\n";
	sCode += "<td align=\"center\"><a href=\"javascript:ImageRotatorPlay('" + this.Id + "');\" title=\"" + oImageRotatorConfig.PlayButtonTitle + "\">" + oImageRotatorConfig.PlayButton + "</a></td>\n";
	sCode += "<td width=\"10\"></td>\n";
	sCode += "<td align=\"center\"><a href=\"javascript:ImageRotatorPause('" + this.Id + "');\" title=\"" + oImageRotatorConfig.PauseButtonTitle + "\">" + oImageRotatorConfig.PauseButton + "</a></td>\n";
	sCode += "<td width=\"10\"></td>\n";
	sCode += "<td align=\"center\"><a href=\"javascript:ImageRotatorNextPicture('" + this.Id + "');\" title=\"" + oImageRotatorConfig.NextButtonTitle + "\">" + oImageRotatorConfig.NextButton + "</a></td>\n";
	sCode += "</tr>\n";
	sCode += "</table>\n";
	sCode += "</div>\n";
	return sCode;
}
function CImageRotatorRotatorDrawCurrentPicture()
{
	if (this.Index < this.Pictures.length)
	{
		var oDiv = document.getElementById(this.Id + "_divPictureBox");
		if (oDiv)
		{
			oDiv.innerHTML = this.Pictures[this.Index].GetCode(this.PictureWidth, this.PictureHeight);
		}
		oDiv = document.getElementById(this.Id + "_divTitleBar");
		if (oDiv)
		{
			oDiv.innerHTML = this.Pictures[this.Index].Title;
		}
	}
}
function CImageRotatorRotatorGetCode()
{
	var sCode = "";
	sCode += this.GetTitleBar();
	sCode += this.GetPictureBox();
	sCode += this.GetNavigationBar();
	return sCode;
}
function CImageRotatorRotatorDraw(sDivId)
{
	var sCode = this.GetCode();
	var oDiv = document.getElementById(sDivId);
	if (oDiv)
	{
		oDiv.innerHTML = sCode;
		this.DrawCurrentPicture();
		this.StartTimer();
	}
}
function CImageRotatorRotatorStartTimer()
{
	var oMe = this;
	this.Timer = setTimeout(function() {oMe.TimerExec();}, this.TimerFrequency);
}
function CImageRotatorRotatorStopTimer()
{
	clearTimeout(this.Timer);
	this.Timer = null;
}
function CImageRotatorRotatorTimerExec()
{
	this.NextPicture();
	this.StartTimer();
}
function CImageRotatorRotatorPreviousPicture()
{
	if (this.Index > 0)
	{
		this.Index--;
	}
	else
	{
		this.Index = this.Pictures.length - 1;
	}
	this.DrawCurrentPicture();
}
function CImageRotatorRotatorPlay()
{
	if (this.Timer == null)
	{
		this.StartTimer();
	}
}
function CImageRotatorRotatorPause()
{
	if (this.Timer != null)
	{
		this.StopTimer();
	}
}
function CImageRotatorRotatorNextPicture()
{
	if (this.Index < this.Pictures.length - 1)
	{
		this.Index++;
	}
	else
	{
		this.Index = 0;
	}
	this.DrawCurrentPicture();
}
/**********************************************/
// Class CImageRotatorManager
/**********************************************/
function CImageRotatorManager()
{
	//Attributes
	this.Rotators = new Array();
	
	//Methods
	this.AddRotator = CImageRotatorManagerAddRotator;
	this.Initialize = CImageRotatorManagerInitialize;
	this.FindRotator = CImageRotatorManagerFindRotator;
}
function CImageRotatorManagerAddRotator(iPictureWidth, iPictureHeight, iTimerFrequency)
{
	this.Rotators[this.Rotators.length] = new CImageRotatorRotator("Rotator_" + this.Rotators.length, iPictureWidth, iPictureHeight, iTimerFrequency);
	return this.Rotators[this.Rotators.length - 1];
}
function CImageRotatorManagerFindRotator(sRotatorId)
{
	var oRotator = null;
	var i = 0;
	while ((i < this.Rotators.length) && (!oRotator))
	{
		if (this.Rotators[i].Id.toLowerCase() == sRotatorId.toLowerCase()) oRotator = this.Rotators[i];
		i++;
	}
	return oRotator;
}
function CImageRotatorManagerInitialize()
{
}


var oImageRotatorManager = new CImageRotatorManager();
var oImageRotatorConfig = new CImageRotatorConfig();
