/*
	Javascript-Klasse für den Slideshow-Export
*/
var SlideShow = function()
{
	this.Container	= gE(arguments[0]);
	this.ImageDiv	= mE('div');
	this.ImageDiv.className = 'slideshowimage';
	this.CaptionDiv	= mE('div');
	this.CaptionDiv.className = 'slideshowcaption';
	this.NextDiv	= mE('div');
	this.NextDiv.className = 'slideshownext';
	this.NextLink = mE('a');
	this.NextLink.appendChild(document.createTextNode('>>'));
	this.NextDiv.appendChild(this.NextLink);

	this.Stuff		= mE('div');
	this.Container.appendChild(this.ImageDiv);
	this.Stuff.appendChild(this.NextDiv);
	this.Stuff.appendChild(this.CaptionDiv);
	this.Container.appendChild(this.Stuff);
	this.Image		= new Image();
	this.ImageLoad	= new Image();
	this.Index		= 0;
	this.UrlPrefix	= null;
	this.Url		= null;
	this.Timeout	= false;
	var Resizeto 	= false;
	var Seconds	 	= 0;
	var Images		= new Array();
	var Captions	= null;
	var Mode		= 'fill';
}

SlideShow.prototype.Create = function()
{
	this.UrlPrefix 	= this.Resizeto ? '../../resources/php/image_preview.php?w='+this.Resizeto[0]+'&h='+this.Resizeto[1]+'&m='+this.Mode+'&url=../' : '../bilder/';
	this.Url	   	= this.UrlPrefix+this.Images[this.Index];
	this.Image.src 	= this.Url;
	this.Image.SlideShow = this;
	this.ImageDiv.appendChild(this.Image);
	if(this.Images.length < 2)
	{
		this.NextDiv.style.display = 'none';
		this.PrevDiv.style.display = 'none';
	}
	
	if(this.Captions)
	{
		cap = unescape(this.Captions[this.Index]);
		if(cap == '') cap = '<p>&nbsp;</p>';
		this.CaptionDiv.innerHTML = cap;
	}
	this.LoadNextImage();
	this.Image.onclick = function()
	{
		this.SlideShow.ShowNextImage();
	}
	this.NextLink.SlideShow = this;
	this.NextLink.onclick = function()
	{
		this.SlideShow.ShowNextImage();
	}
	
	
	if(this.Seconds)
		this.Timeout = window.setTimeout(function(s) { s.ShowNextImage(); }, this.Seconds * 1000, this);
}

SlideShow.prototype.LoadNextImage = function()
{
	i = this.Index < this.Images.length-1 ? this.Index+1 : 0;
	this.ImageLoad.src = this.UrlPrefix+this.Images[i];
}

SlideShow.prototype.ShowNextImage = function()
{
	this.Index = this.Index < this.Images.length-1 ? this.Index+1 : 0;
	this.Image.src = this.UrlPrefix+this.Images[this.Index];
	if(this.Captions)
	{
		cap = unescape(this.Captions[this.Index]);
		if(cap == '') cap = '<p>&nbsp;</p>';
		this.CaptionDiv.innerHTML = cap;
	}
	this.LoadNextImage();
	window.clearTimeout(this.Timeout);
	if(this.Seconds)
		this.Timeout = window.setTimeout(function(s) { s.ShowNextImage(); }, this.Seconds * 1000, this);
}

SlideShow.prototype.ShowPreviousImage = function()
{
	this.Index = this.Index > 0 ? this.Index-1 : this.Images.length -1;
	this.Image.src = this.UrlPrefix+this.Images[this.Index];
	if(this.Captions)
	{
		cap = unescape(this.Captions[this.Index]);
		if(cap == '') cap = '<p>&nbsp;</p>';
		this.CaptionDiv.innerHTML = cap;
	}
	window.clearTimeout(this.Timeout);
	if(this.Seconds)
		this.Timeout = window.setTimeout(function(s) { s.ShowNextImage(); }, this.Seconds * 1000, this);
}
