var slideshow = {
	ile : galleryCount + 1,
	showNavigation : galleryType,
	start : 1,
	temp : 1,
	slidet: 5,
	running: null,
	old: null,
	dirs: 'a',
	clicked: false,
	zindex: 40,
	
	start: function()
	{
		this.startshow();
		this.duration = 1;
	},
	
	startshow: function()
	{
		this.running = true;
		this.slideS = new PeriodicalExecuter(function(pex){ slideshow.Next(); pex.stop(); },this.slidet);
	},
	
	stopshow: function()
	{
		this.running = false;
		if(this.slideS)
		{
			this.slideS.stop();
		}
	},
	
	stopshowf: function()
	{
		this.stopshow();
		if (this.showNavigation == 1)
		{
			document.getElementById('pause').style.display = "none";
			document.getElementById('play').style.display = "";
		}
	},
	
	hidetext: function(tval)
	{
		this.dirs =	document.getElementById('dire').innerHTML;
		document.getElementById('dire').innerHTML = "";
	},
	
	showtext: function(tval)
	{
	},
	
	Effect : function(before, after)
	{
		$(after).setOpacity(1);
		$(before).removeClassName("top");
		$(after).addClassName("top");
		
		new Effect.Fade('whole'+this.old, 
		{
			duration: this.duration,
			position: 'front', 
			scope: 'gallery',
			afterFinish: function()
			{
				//slideshow.hidetext(slideshow.old);
				//slideshow.showtext(slideshow.temp);
			}
		});
		
		new Effect.SlideDown(after,
		{
			duration:this.duration,
			position: 'front', 
			scope: 'gallery',
			afterFinish: function()
			{
				slideshow.clicked = false;
				slideshow.toggleshow();
			}
		});
	},
	
	Next : function()
	{
		this.clicked = true;
		this.old = this.temp;
		slideshow.temp++;

		if (this.temp > this.ile) 
			this.temp=1;

		var image = document.getElementById("galleryImage" + slideshow.temp);
		if (image)
		{
		    image.style.display = "inline";
		    image.src = image.getAttribute("rel");
		}
		
		this.Effect('whole'+this.old, 'whole'+this.temp);
	},
	
	butPrev : function()
	{
		if(this.clicked==true)
		{
			return false;
		}
		
		this.clicked = true;
		this.stopshowf();
		this.old = this.temp;
		this.temp--;
		if (this.temp < 1)
			this.temp=this.ile;

		var image = document.getElementById("galleryImage" + slideshow.temp);
		if (image)
		{
		    image.style.display = "inline";
		    image.src = image.getAttribute("rel");
		}
		this.Effect('whole'+this.old, 'whole'+this.temp);
	},
	
	butNext : function() 
	{
		if(this.clicked==true)
		{
			return false;
		}
		
		this.clicked = true;
		this.stopshowf();
		this.old = this.temp;
		slideshow.temp++;
		if (this.temp > this.ile) 
		{
		    this.temp=1;
		}
		
		var image = document.getElementById("galleryImage" + slideshow.temp);
		if (image)
		{
		    image.style.display = "inline";
		    image.src = image.getAttribute("rel");
		}
		
		this.Effect('whole'+this.old, 'whole'+this.temp);
	},
	
	toggleshow: function()
	{
		if(this.running)
		{
			this.startshow();
		}
		else
		{
			this.stopshow();
		}
	},
	
	toggleshowbut: function()
	{
		if (this.running)
		{
			this.stopshowf();
		}
		else
		{
			this.startshow();
			
			if (this.showNavigation == 1)
			{
				document.getElementById('play').style.display = "none";
				document.getElementById('pause').style.display = "";
			}
		}
	},
	
	togglelight : function()
	{
		if (this.running)
		{
			if (this.slideS)
			{
				this.slideS.stop();
			}
		}
	},
	
	togglelightclose : function()
	{
		if (this.running)
		{
			if (this.slideS)
			{
				this.startshow();
			}
		}
	}
};

