var SLIDESHOWS = new Array();

function SLIDESHOW(picName, btnOffsetLeft, btnOffsetTop, btnLeft, btnRight, picLink, picLinkTarget)
{
	if (!btnOffsetLeft) btnOffsetLeft = 0;
	if (!btnOffsetTop) btnOffsetTop = 0;
	
	this.Index = SLIDESHOWS.length;
	SLIDESHOWS[this.Index] = this;
	this.Buttons = new Array();
	this.Interval = 0;
	this.timerID = 0;
	this.timerIDOL = 0;
	this.animOL = 0;
	this.animRun = false;
	this.Images = new Array();
	this.ImgPath = new Array();
	this.ImgUrl = new Array();
	this.ImgTarget = new Array();
	this.Images[0] = new Image();
	this.Images[0].src = picName;
	this.ImgPath[0] = picName;
	this.ImgUrl[0] = picLink;
	this.ImgTarget[0] = picLinkTarget;
	this.ImgNr = 0;

	var tx = "<div style=\"position:relative;\"><img id=\"PicSLIDESHOW" + this.Index + "\" src=\"" + picName + "\" border=\"0\">";
	tx += "<div style=\"position:absolute;z-Index:4;left:0px;top:0px;\">";
	if (picLink.length > 0) tx += "<a id=\"ASLIDESHOWOL" + this.Index + "\" href=\"" + picLink + "\" target=\"" + picLinkTarget + "\">";	
	tx += "<img id=\"PicSLIDESHOWOL" + this.Index + "\" src=\"" + picName + "\" border=\"0\" style=\"filter:alpha(opacity=100);-moz-opacity:1.0\">";
	if (picLink.length > 0) tx += "</a>";	
	tx += "</div>";
	
	if (btnLeft && btnRight && btnLeft.length > 0 && btnRight.length > 0)
	{
		for (var i = 0; i < 4; i++)
			this.Buttons[i] = new Image();

		this.Buttons[0].src = btnLeft;
		this.Buttons[1].src = btnRight;

		tx += "<div style=\"position:absolute;z-Index:10;left:" + btnOffsetLeft + "px;top:" + btnOffsetTop + "px;\"><img id=\"PicSLIDESHOWLeft" + this.Index + "\" src=\"" + btnLeft + "\" border=\"0\" onClick=\"SLIDESHOWS[" + this.Index + "].Previous();\"><img id=\"PicSLIDESHOWRight" + this.Index + "\" src=\"" + btnRight + "\" border=\"0\" onClick=\"SLIDESHOWS[" + this.Index + "].Next();\"></div>";
	}
	
	this.addPicture = function(picName, picLink, picLinkTarget)
	{
		var nr = this.Count();
		this.ImgPath[nr] = picName;
		this.Images[nr] = new Image();
		this.ImgUrl[nr] = picLink;
		this.ImgTarget[nr] = picLinkTarget;
	}
	
	this.Count = function()
	{
		return this.Images.length;
	}
	
	this.Previous = function()
	{
		if (this.animRun) return false;
		
		this.ImgNr--;
		if (this.ImgNr < 0) this.ImgNr += this.Count();
		this.ImgNr--;
		if (this.ImgNr < 0) this.ImgNr += this.Count();

		this.StopTimer();
		SLIDESHOWRender(this.Index);
	}

	this.Next = function()
	{
		if (this.animRun) return false;

		this.StopTimer();
		SLIDESHOWRender(this.Index);
	}
	
	this.Start = function(timeInterval)
	{
		if (!timeInterval) timeInterval = 5000;
		this.Interval = timeInterval;

		for (var i = 1; i < this.Count(); i++)
			this.Images[i].src = this.ImgPath[i];

		this.StopTimer();
		this.timerID = setInterval("SLIDESHOWRender(" + this.Index + ")", this.Interval);
	}

	this.StopTimer = function()
	{
		if (this.timerID != 0)
		{
			clearInterval(this.timerID);
			this.timerID = 0;
		}
		if (this.timerIDOL != 0)
		{
			clearInterval(this.timerIDOL);
			this.timerIDOL = 0;
		}
	}
	
	document.write(tx + "</div>");
	
	return this;
}

function SLIDESHOWRender(Index)
{
	SLIDESHOWS[Index].ImgNr = (SLIDESHOWS[Index].ImgNr + 1) % SLIDESHOWS[Index].Count();
	if (SLIDESHOWS[Index].Images[SLIDESHOWS[Index].ImgNr].complete)
	{
		document.getElementById("PicSLIDESHOW" + SLIDESHOWS[Index].Index).src = SLIDESHOWS[Index].Images[SLIDESHOWS[Index].ImgNr].src;
		if (SLIDESHOWS[Index].timerIDOL != 0)
		{
			clearInterval(SLIDESHOWS[Index].timerIDOL);
			SLIDESHOWS[Index].timerIDOL = 0;
		}
		
		SLIDESHOWS[Index].animOL = 100;
		SLIDESHOWS[Index].animRun = true;
		SLIDESHOWS[Index].timerIDOL = setInterval("SLIDESHOWRenderAnim(" + Index + ")", 20);
	}
}

function SLIDESHOWRenderAnim(Index)
{
	if (SLIDESHOWS[Index].animOL <= 0)
	{
		document.getElementById("PicSLIDESHOWOL" + SLIDESHOWS[Index].Index).src = document.getElementById("PicSLIDESHOW" + SLIDESHOWS[Index].Index).src;
		if (document.getElementById("ASLIDESHOWOL" + SLIDESHOWS[Index].Index))
		{
			document.getElementById("ASLIDESHOWOL" + SLIDESHOWS[Index].Index).href = SLIDESHOWS[Index].ImgUrl[SLIDESHOWS[Index].ImgNr];
			document.getElementById("ASLIDESHOWOL" + SLIDESHOWS[Index].Index).target = SLIDESHOWS[Index].ImgTarget[SLIDESHOWS[Index].ImgNr];
		}
		
 		if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion) >= 5)
    	document.getElementById("PicSLIDESHOWOL" + SLIDESHOWS[Index].Index).style.MozOpacity = 1;
 		else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4)
 			document.getElementById("PicSLIDESHOWOL" + SLIDESHOWS[Index].Index).filters.alpha.opacity = 100;

		clearInterval(SLIDESHOWS[Index].timerIDOL);
		SLIDESHOWS[Index].timerIDOL = 0;
		SLIDESHOWS[Index].animRun = false;

	}
	else
	{
		SLIDESHOWS[Index].animOL -= 5;
 		if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion) >= 5)
    	document.getElementById("PicSLIDESHOWOL" + SLIDESHOWS[Index].Index).style.MozOpacity = SLIDESHOWS[Index].animOL / 100;
 		else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4)
 			document.getElementById("PicSLIDESHOWOL" + SLIDESHOWS[Index].Index).filters.alpha.opacity = SLIDESHOWS[Index].animOL;
	}
}

