/**
 * @author Sławomir Kokłowski {@link http://www.kurshtml.boo.pl}
 * @copyright NIE usuwaj tego komentarza! (Do NOT remove this comment!)
 * Adaptacja: Marek Bakalarczuk
 */

function Galeria(id, zdjecia, css, ochrona, zaladuj)
{
	this.kolumny = 2;
	this.naStronie = 6;
	
	
	this.id = id;
	this.zdjecia = zdjecia;
	this.ochrona = typeof ochrona != 'undefined' ? ochrona : false;
	this.css = css;
	
	var okno = null;
	
	if (typeof zaladuj != 'undefined' && zaladuj)
	{
		for (var i = 0; i < this.zdjecia.length; i++)
		{
			new Image().src = this.zdjecia[i][0];
		}
	}
	
	
	
	this.wyswietl = function(strona)
	{
	
		if (typeof strona == 'undefined') strona = 1;
		var html = '';
		
		for (var i = start_ = (strona - 1) * this.naStronie, stop_ = Math.min(start_ + this.naStronie, this.zdjecia.length); i < stop_; i++)
		{
			if (i > start_ && !(i % this.kolumny)) html += '</tr><tr>';
			html +=
				'<td>' +
					'<a href="javascript:openwin(\''+this.zdjecia[i][1]+'\',\''+this.zdjecia[i][2]+'\','+this.zdjecia[i][3]+','+this.zdjecia[i][4]+')"><img src="' + this.zdjecia[i][0] + '" alt=""' + (this.ochrona ? ' onmousedown="return false" oncontextmenu="return false" onselectstart="return false" onselect="return false" oncopy="return false" ondragstart="return false" ondrag="return false" galleryimg="no"' : '') + ' /></a>' +
					(typeof this.zdjecia[i][2] != 'undefined' ? '<div></div>' : '') +
				'</td>';
		}
		if (html) html = '<table><tr>' + html + '</tr></table>';
		
		if (this.zdjecia.length > this.naStronie)
		{
			html += '<div class="stronicowanie">Strona : ';
			if (strona > 1) html += '<a href="javascript:void(0)" onclick="' + this.id + '.wyswietl(' + (strona - 1) + '); return false" onkeypress="' + this.id + '.wyswietl(' + (strona - 1) + '); return false">Poprzednia</a>';
			for (var i = 1, stop_ = Math.ceil(this.zdjecia.length / this.naStronie); i <= stop_; i++)
			{
				html += ' ' + (i == strona ? i : '<a href="javascript:void(0)" onclick="' + this.id + '.wyswietl(' + i + '); return false" onkeypress="' + this.id + '.wyswietl(' + i + '); return false">' + i + '</a>');
			}
			if (strona < stop_) html += ' <a href="javascript:void(0)" onclick="' + this.id + '.wyswietl(' + (strona + 1) + '); return false" onkeypress="' + this.id + '.wyswietl(' + (strona + 1) + '); return false">Następna</a>';
			html += '</div>';
		}
		
		document.getElementById(this.id).innerHTML = '<div class="galeria">' + html + '</div>';
	}
	
	document.write('<div id="' + this.id + '"></div>');
	this.wyswietl();
}