function $(id)
{
	return document.getElementById(id);
}
//
//
// Galeria (c) 2007 Marek Robak
//
//


function Gallery()
{
	// konfiguracja
	this.picturePath = '/path/to/pictures/';
	
	// 
	this.active = 1;
	this.pictures = new Array();
	this.interval = 2000; // milisekundy przy automatycznym pokazie
	this.slideTimer = '';
	this.effectTimer = ''; // dodatek
	this.effectStep = 0.1;
	this.effectFreq = 40; 
	this.transparency = 1.00;
	this.incomming = '';
	this.ids = [];
	
	this.addPicture = function(p)
	{
		this.pictures.push(p);
		// preloader
		var i = new Image;
		i.src = this.getPicturePath(p.mediumID);
	}
	
	this.getPicturePath = function(mediumID)
	{
		return this.picturePath + mediumID + '.jpg';
	}
	
	this.hop = function(id)
	{
		this.active = id;
		var p = this.pictures[id];
		$('gallery_picture').src = this.getPicturePath(p.mediumID);
		$('gallery_text').innerHTML = (id + 1) + ' / ' + (this.pictures.length);
	}
	
	this.eswitch = function(id)
	{
		this.incomming = id;
		this.fadeOut();
	}
	
	this.next = function()
	{
		var id = this.active + 1;
		if(id >= this.pictures.length) id = 0; 
		this.hop(id); 
	}
	
	this.prev = function()
	{
		var id = this.active - 1;
		if(id < 0) id = this.pictures.length - 1; 
		this.hop(id); 
	}
	
	this.slideshow = function(status)
	{
		if(status == 1)
		{
			this.slideTimer = setInterval('g.next()',this.interval);
		}
		else
		{
			clearInterval(g.slideTimer);
			$('autoslideshow').checked = false; 
		}
	}
	
	this.setTransparency = function(t)
	{
		$('gallery_picture').style.opacity = t;
		this.transparency = parseFloat(t);
	}
	
	this.fadeOut = function()
	{
		if(this.transparency >= 0.05)
		{
			var t = this.transparency - this.effectStep; 
			this.setTransparency(this.transparency - this.effectStep);
			this.effectTimer = setTimeout('g.fadeOut()',this.effectFreq);
		}
		else
		{
			if(this.incomming != '')
			{
				this.hop(this.incomming);
				this.incomming = '';
				this.effectTimer = setTimeout('g.fadeIn()',this.effectFreq);
			}
		}
	}
	
	this.fadeIn = function()
	{
		if(this.transparency < 0.90)
		{
			this.setTransparency(this.transparency + this.effectStep);
			this.effectTimer = setTimeout('g.fadeIn()',this.effectFreq);
		}
		else
		{
			this.setTransparency(1.00);
			// koniec
		}
	}	
}
