	function SlideShow(destination, images, delay, fadespeed)
	{

		this.destination = $("#" + destination);
		this.delay = delay;
		this.fadespeed = fadespeed;
		this.currentindex = 0;
		this.images = Array();
		for(i = 0; i < images.length; i++)
		{
			this.images[i] = new Image();
			this.images[i].src = images[i];
		}

		this.Proxy = function(self, pfunc)
		{
			return function()
			{
				pfunc.apply(self);
			}
		}
		
		this.SetImage = function(index)
		{
			this.destination.attr("src", this.images[index].src);
			this.destination.attr("width", this.images[index].width);
			this.destination.attr("height", this.images[index].height);
		}
		
		this.ShowNext = function()
		{
			next = (this.currentindex + 1 >= this.images.length) ? 0 : this.currentindex + 1;

			if( !this.images[next] )
			{ // Pokud není obrázek načten, animace se pozdrží
				setTimeout( this.Proxy(this, this.ShowNext), 500);					
				return;
			}
			this.currentindex = next;
			this.destination.fadeOut(this.fadespeed, this.Proxy(this, this.FadeIn));
		}
		this.FadeIn = function()
		{
			this.SetImage(this.currentindex);
			this.destination.fadeIn(this.fadespeed);
			setTimeout( this.Proxy(this, this.ShowNext), this.delay);
		}
	
		//this.ShowNext();
		//this.SetImage(this.currentindex);
		setTimeout( this.Proxy(this, this.ShowNext), this.delay);
	}
	
	
	function MultiSlideShow(destination, images, delay, fadespeed)
	{

		//this.destination = $("#" + destination);
		this.destination = new Array();
		this.index = new Array();
		for(i = 0; i < destination.length; i++)
		{
			this.destination[i] = $("#" + destination[i]);
			this.index[i] = 0;
		}
		this.delay = delay;
		this.fadespeed = fadespeed;
		this.currentindex = -1; // index aktuálního img tagu (v destination)
		this.images = Array();
		for(i = 0; i < images.length; i++)
		{
			this.images[i] = new Array();
			for(j = 0; j < images[i].length; j++)
			{
				this.images[i][j] = new Image();
				this.images[i][j].src = images[i][j];
			}
		}

		this.Proxy = function(self, pfunc)
		{
			return function()
			{
				pfunc.apply(self);
			}
		}
		
		this.SetImage = function(index)
		{
			for(i = 0; i < this.images.length; i++)
			{
				this.destination[i].attr("src", this.images[i][index].src);
				this.destination[i].attr("width", this.images[i][index].width);
				this.destination[i].attr("height", this.images[i][index].height);
			}
		}
		this.SetImageSolo = function()
		{
			
			this.destination[this.currentindex].attr("src", this.images[this.currentindex][this.index[this.currentindex]].src);
			this.destination[this.currentindex].attr("width", this.images[this.currentindex][this.index[this.currentindex]].width);
			this.destination[this.currentindex].attr("height", this.images[this.currentindex][this.index[this.currentindex]].height);
		}
		
		this.ShowNext = function()
		{
			next = (this.currentindex + 1 >= this.destination.length) ? 0 : this.currentindex + 1;
			nextImageIndex = (this.index[next] + 1 >= this.images[next].length) ? 0 : this.index[next] + 1;
			
			/*nacteno = true;
			for(i = 0; i < this.images.length; i++)
				if( !this.images[i][next] )
					nacteno = false;*/
			nacteno = (this.images[next][nextImageIndex]) ? true : false;
					
			if( !nacteno )
			{ // Pokud není obrázek načten, animace se pozdrží
				setTimeout( this.Proxy(this, this.ShowNext), 500);					
				return;
			}
			this.currentindex = next;
			this.index[next] = nextImageIndex;
			
			
			/*for(i = 0; i < this.images.length; i++)
			{
				if(i == 0)
					this.destination[i].fadeOut(this.fadespeed, this.Proxy(this, this.FadeIn));
				else
					this.destination[i].fadeOut(this.fadespeed);
			}*/
			this.destination[next].fadeOut(this.fadespeed, this.Proxy(this, this.FadeIn));
		}
		this.FadeIn = function()
		{
			this.SetImageSolo();
			//for(i = 0; i < this.images.length; i++)
			this.destination[this.currentindex].fadeIn(this.fadespeed);
			setTimeout( this.Proxy(this, this.ShowNext), this.delay);
		}
	
		//this.ShowNext();
		//this.SetImage(this.currentindex);
		setTimeout( this.Proxy(this, this.ShowNext), this.delay);
	}