
function CSlideShow(sName, sVariableName, nX, nY, nWidth, nHeight)
{
	this.m_sName = sName;
	this.SlideShowDinamicDraw = new CDinamicDraw("SlideShow"+sName, nX, nY);
	document.write('<img id=CashId width=0 height=0 border=0>\n');

	this.m_sVariableName = sVariableName;
	this.m_nX = nX;
	this.m_nY = nY;

	this.m_nMaxHeightImage = 500;
	this.m_nMaxWidthImage = 500;
	this.m_nMinHeightImage = 1;
	this.m_nMinWidthImage = 1;

	this.m_nHeightWindow = nHeight;
	this.m_nWidthWindow = nWidth;
	this.m_nHeightImage = 0;
	this.m_nWidthImage = 400;
	this.m_nIncImage = 10;
	this.m_nDecImage = 10;

	this.m_nPause = 15000;
	this.m_nIncPause = 1000;
	this.m_nDecPause = 1000;

	this.m_arFotos = new Array();
	this.m_arOperations = new Array();

	this.m_nCurrentIndex = 0;
	this.m_nTimerId = 0;
	this.m_nStatus = 0;
	this.m_bLoadOnComlete = false;

	this.IncImageSize = CSlideShow_IncImageSize;
	this.DecImageSize = CSlideShow_DecImageSize;
	this.IncPause = CSlideShow_IncPause;
	this.DecPause = CSlideShow_DecPause;
	this.Operate = CSlideShow_Operate;
	this.NextImage = CSlideShow_NextImage;
	this.PrevImage = CSlideShow_PrevImage;
	this.ToBegin = CSlideShow_ToBegin;
	this.ToEnd = CSlideShow_ToEnd;

	this.Pause = CSlideShow_Pause;
	this.StartSlidesNext = CSlideShow_StartSlidesNext;
	this.StartSlidesPrev = CSlideShow_StartSlidesPrev;
	this.LoadAllImages = CSlideShow_LoadAllImages;

	this.RedrawImage = CSlideShow_RedrawImage;
	this.OnClock = CSlideShow_OnClock;
	this.CashImage = CSlideShow_CashImage;
	this.CashImageComplete = CSlideShow_CashImageComplete;

	this.SlideShowDinamicDraw.Draw();
}

function CSlideShow_IncImageSize()
{
	bChanged = false;
	if((this.m_nHeightImage != 0) && !(this.m_nHeightImage + this.m_nIncImage > this.m_nMaxHeightImage)) 
	{
		this.m_nHeightImage += this.m_nIncImage;
		bChanged = true;
	}

	if((this.m_nWidthImage != 0) && !(this.m_nWidthImage + this.m_nIncImage > this.m_nMaxWidthImage)) 
	{
		this.m_nWidthImage += this.m_nIncImage;
		bChanged = true;
	}
	if(bChanged) this.RedrawImage();
}

function CSlideShow_DecImageSize()
{
	bChanged = false;
	if((this.m_nHeightImage != 0) && !(this.m_nHeightImage - this.m_nDecImage < this.m_nMinHeightImage)) 
	{
		this.m_nHeightImage -= this.m_nDecImage;
		bChanged = true;
	}
	if((this.m_nWidthImage != 0) && !(this.m_nWidthImage - this.m_nDecImage < this.m_nMinWidthImage)) 
	{
		this.m_nWidthImage -= this.m_nDecImage;
		bChanged = true;
	}
	if(bChanged) this.RedrawImage();
}

function CSlideShow_IncPause()
{
	this.m_nPause += this.m_nIncPause;
	if(this.m_nStatus!=0)
	{
		clearTimeout(this.m_nTimerId);
		this.m_nTimerId=setTimeout('CSlideShow_OnClock("'+this.m_sVariableName+'")', this.m_nPause);
	}
}

function CSlideShow_DecPause()
{
	if(this.m_nPause - this.m_nDecPause > 0) 
	{
		this.m_nPause -= this.m_nDecPause;
		if(this.m_nStatus!=0)
		{
			clearTimeout(this.m_nTimerId);
			this.m_nTimerId=setTimeout('CSlideShow_OnClock("'+this.m_sVariableName+'")', this.m_nPause);
		}
	}
}

function CSlideShow_Operate()
{
	if(this.m_arOperations[this.m_nCurrentIndex]) eval(this.m_arOperations[this.m_nCurrentIndex]);
}

function CSlideShow_NextImage()
{
	if(this.m_arFotos[this.m_nCurrentIndex+1]) 
	{
		this.m_nCurrentIndex++;
		this.RedrawImage();
	}
}

function CSlideShow_PrevImage()
{
	if(this.m_arFotos[this.m_nCurrentIndex-1]) 
	{
		this.m_nCurrentIndex--;
		this.RedrawImage();
	}
}

function CSlideShow_ToBegin()
{
	this.m_nCurrentIndex = 0;
	this.RedrawImage();
}

function CSlideShow_ToEnd()
{
	this.m_nCurrentIndex = this.m_arFotos.length-1;
	this.RedrawImage();
}

function CSlideShow_OnClock(sVariableName)
{
	var ShowSlidesVariable;
	eval('ShowSlidesVariable='+sVariableName);
	if(ShowSlidesVariable.m_nCurrentIndex+ShowSlidesVariable.m_nStatus >= 0 && 
		ShowSlidesVariable.m_nCurrentIndex+ShowSlidesVariable.m_nStatus < ShowSlidesVariable.m_arFotos.length &&
		ShowSlidesVariable.CashImageComplete()) 
	{
		ShowSlidesVariable.m_nCurrentIndex += ShowSlidesVariable.m_nStatus;
		ShowSlidesVariable.RedrawImage();
		ShowSlidesVariable.CashImage();
		ShowSlidesVariable.m_nTimerId=setTimeout('CSlideShow_OnClock("'+sVariableName+'")', ShowSlidesVariable.m_nPause);
	}
	else ShowSlidesVariable.Pause();
}

function CSlideShow_Pause()
{
	if(this.m_nStatus!=0)
	{
		this.m_nStatus=0;
		clearTimeout(this.m_nTimerId);
	}
}

function CSlideShow_StartSlidesNext()
{
	this.m_nStatus=1;
	this.CashImage();	 
	this.m_nTimerId=setTimeout('CSlideShow_OnClock("'+this.m_sVariableName+'")', this.m_nPause);
}

function CSlideShow_StartSlidesPrev()
{
	this.m_nStatus=-1;
	this.CashImage();
	this.m_nTimerId=setTimeout('CSlideShow_OnClock("'+this.m_sVariableName+'")', this.m_nPause);
}


function CSlideShow_LoadAllImages()
{
	arImages = new Array();
	for(i in this.m_arFotos)
	{
		arImages[i] = new Image();
		arImages[i].src = this.m_arFotos[i];
	}
}

function CSlideShow_RedrawImage()
{
	if(this.m_arFotos[this.m_nCurrentIndex])
	{
		var sImg = '<table class=SlideShowTable'+this.m_sVariableName+
				' width='+this.m_nWidthWindow+' height='+this.m_nHeightWindow+
				'><tr><td align=center valign=top><a href="" onclick="'+this.m_sVariableName+
				'.Operate(); return false;"><img class=SlideShowTable'+this.m_sVariableName+
				' src="'+this.m_arFotos[this.m_nCurrentIndex]+'"';
		if(this.m_nHeightImage > 0) sImg += " height="+this.m_nHeightImage;
		if(this.m_nWidthImage > 0) sImg += " width="+this.m_nWidthImage;
		sImg += " border=0></a></td></tr></table>";
		this.SlideShowDinamicDraw.Redraw(sImg);
	}
}

function CSlideShow_CashImage()
{
	if(document.getElementById && this.m_nStatus != 0 && this.m_nCurrentIndex+this.m_nStatus >= 0 && 
		this.m_nCurrentIndex+this.m_nStatus < this.m_arFotos.length)
			document.getElementById("CashId").src=this.m_arFotos[this.m_nCurrentIndex+this.m_nStatus];
}

function CSlideShow_CashImageComplete()
{
	if(this.m_bLoadOnComlete && document.getElementById)
		return document.getElementById("CashId").complete;
	else return true;
}
