function Galeria(id, zdjecia, kolumny, naStronie, css, ochrona, zaladuj)
{
//id - identyfikator galerii (unikatowy)
//zdjecia - tablica ze zdjeciami {miniaturka z sciezka dostepu, zdjecie z sciezka dostepu, nazwa zdjecia, nr kolejny}
//kolumny - liczba kolumn z miniaturkami
//naStronie - lczba miniaturek na 1 stronie

      this.kolumny = typeof kolumny != 'undefined' ? kolumny : 5;
      this.naStronie = typeof naStronie != 'undefined' ? naStronie : (this.kolumny * 3);

	this.id = id;
	this.zdjecia = zdjecia;
	this.ochrona = typeof ochrona != 'undefined' ? ochrona : true;
	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][1];
		}
	}

	this.podglad = function(nr_zdjecia)
	{
		if (typeof nr_zdjecia == 'undefined') nr_zdjecia = 0;
		var podglad = '';

//		podglad = this.zdjecia[nr_zdjecia][1].slice(this.zdjecia[nr_zdjecia][1].lastIndexOf("/")+1) + '<br>';
		podglad += podglad + '<a id="'+this.id+'podgladhref" href="' + (this.ochrona ? 'javascript:void(0)' : this.zdjecia[nr_zdjecia][1]) + '" onclick="return !' + this.id + '.pokaz(' + nr_zdjecia + ')" onkeypress="return !' + this.id + '.pokaz(' + nr_zdjecia + ')">' +
							'<img id="'+this.id+'podgladimg" class="podglad" src="' + this.zdjecia[nr_zdjecia][1] + '" 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[nr_zdjecia][2] != 'undefined' ? '<div style="font-size:15">' + this.zdjecia[nr_zdjecia][2] + '</div>' : '');
//		podglad += podglad + '<img src="' + this.zdjecia[nr_zdjecia][1] + '" width="300" align="center">';
		document.getElementById(this.id+'podglad').innerHTML = '<div class="galeria">' + podglad  + '</div>';
	}

	this.miniaturki = function(strona, nr_podgladu)
	{
		if (typeof strona == 'undefined') strona = 1;
		if (typeof nr_podgladu == 'undefined') nr_podgladu = (strona - 1) * this.naStronie;
		var html = '';

		start_ = (strona - 1) * this.naStronie;
		stop_ = Math.min(start_ + this.naStronie, this.zdjecia.length);

		for (var i = start_; i < stop_; i++)
		{
			if (i > start_ && !(i % this.kolumny)) html += '</tr><tr>';
			html +=
				'<td align="center">' +
//					'<a href="' + (this.ochrona ? 'javascript:void(0)' : this.zdjecia[i][1]) + '" onclick="return !' + this.id + '.pokaz(' + i + ')" onkeypress="return !' + this.id + '.pokaz(' + i + ')"><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 style="font-size:15">' + this.zdjecia[i][2] + '</div>' : '') +
//					'<a href="' + 'javascript:void(0)' + '" onclick="return !' + this.id+ '.podglad(' + i + ')" onkeypress="return !' + this.id + '.podglad(' + i + ')">' +
					'<a href="' + 'javascript:void(0)' + '" onclick="return !' + this.id+ '.miniaturki(' +strona+','+ i + ')" onkeypress="return !' + this.id + '.podglad(' + i + ')">' +
					'<img class="miniaturka" 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 class="galeria" style="font-size:15">' + this.zdjecia[i][2] + '</div>' : '') +
				'</td>';
		}
		if (html) html = '<table><tr>' + html + '</tr></table>';

		document.getElementById(this.id+'miniaturki').innerHTML = '<div class="galeria">' + html + '</div>';
		this.podglad(nr_podgladu);
		this.stronicowanie(strona);
	}

	this.stronicowanie = function(strona)
	{
		if (typeof strona == 'undefined') strona = 1;
		var html = '';

		if (this.zdjecia.length > this.naStronie)
		{
			html += '<div class="stronicowanie">';
			if (strona > 1) html += '<a href="javascript:void(0)" onclick="' + this.id + '.miniaturki(' + (strona - 1) + '); return false" onkeypress="' + this.id + '.miniaturki(' + (strona - 1) + '); return false">&laquo;</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 + '.miniaturki(' + i + '); return false" onkeypress="' + this.id + '.miniaturki(' + i + '); return false">' + i + '</a>');
			}
			if (strona < stop_) html += ' <a href="javascript:void(0)" onclick="' + this.id + '.miniaturki(' + (strona + 1) + '); return false" onkeypress="' + this.id + '.miniaturki(' + (strona + 1) + '); return false">&raquo;</a>';
			html += '</div>';
		}

		document.getElementById(this.id+'stronicowanie').innerHTML = '<div class="galeria">' + html + '</div>';
	}

	this.wyswietl = function(strona)
	{
		if (typeof strona == 'undefined') strona = 1;
		var html = '';

		this.miniaturki(strona);
//		this.stronicowanie(strona);
	}

	this._pokaz = function(i)
	{
		var numer = (i + 1) + '/' + this.zdjecia.length;
		if (this.zdjecia.length < 2) var stronicowanie = '';
		else
		{
			var stronicowanie =
				'<div class="stronicowanie" style="white-space: nowrap" align="center">' +
					(i > 0 ? '<a href="javascript:void(0)" onclick="setTimeout(\'document.write(window.opener.' + this.id + '._pokaz(' + (i - 1) + ')); document.close(); document.close()\', 1); return false" onkeypress="setTimeout(\'document.write(window.opener.' + this.id + '._pokaz(' + (i - 1) + ')); document.close(); document.close()\', 1); return false">&laquo;&nbsp;Wstecz</a>&nbsp;&nbsp;&nbsp;' : '') +
					numer +
					(i < this.zdjecia.length - 1 ? '&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="setTimeout(\'document.write(window.opener.' + this.id + '._pokaz(' + (i + 1) + ')); document.close()\', 1); return false" onkeypress="setTimeout(\'document.write(window.opener.' + this.id + '._pokaz(' + (i + 1) + ')); document.close()\', 1); return false">Dalej&nbsp;&raquo;</a>' : '') +
				'</div>';
		}

		var html =
			'<html>' +
				'<head>' +
					'<title>' + (typeof this.zdjecia[i][2] != 'undefined' ? this.zdjecia[i][2].replace(/<[^>]+>/g, '') + (numer ? ' (' + numer + ')' : '') : numer) + '</title>' +
					(typeof this.css != 'undefined' && this.css ? '<link rel="Stylesheet" type="text/css" href="' + this.css + '" />' : '') +
					'<'+'script type="text/javascript">' +
					'function dopasuj() { /** to zakomentowałem: window.resizeTo(Math.min(screen.availWidth, Math.max(document.getElementById(\'img\').width + 50, document.getElementById(\'body\').offsetWidth)), Math.min(screen.availHeight, document.getElementById(\'body\').offsetHeight + 80)); */}' +

					(this.ochrona ? 'window.onblur = function() { if (document.getElementById(\'body\')) document.getElementById(\'body\').style.visibility = \'hidden\'; try { clipboardData.clearData(); } catch (e) {} }; window.onfocus = function () { if (document.getElementById(\'body\')) document.getElementById(\'body\').style.visibility = \'visible\'; };'  : '') +
					'<'+'/script>' +
				'</head>' +
				'<body /*style="margin: 50; padding: 0; background-color:black; color:yellow;" onload="dopasuj()*/"' + (this.ochrona ? ' oncontextmenu="return false" onbeforeprint="document.getElementsByTagName(\'body\')[0].style.visibility = \'hidden\'; window.alert(\'Wydruk jest niedostępny!\')" onafterprint="document.getElementsByTagName(\'body\')[0].style.visibility = \'visible\'"' : '') + '>' +
					'<div id="body">' +
						'<div id="zdjecie">' +
//							(typeof this.zdjecia[i][2] != 'undefined' || numer ? '<h3 style="text-align: center">' + (typeof this.zdjecia[i][2] != 'undefined' ? this.zdjecia[i][2] : numer) + '</h3>' : '') +
							'<div style="text-align: center"><img id="img" height="80%" style="max-width:800; max-height:600;" src="' + this.zdjecia[i][1] + '" 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"' : '') + ' /></div>' +
//							(typeof this.zdjecia[i][3] != 'undefined' ? '<div style="text-align: center">' + this.zdjecia[i][3] + '</div>' : '') +
							stronicowanie +
						'</div>' +
					'</div>' +
				'</body>' +
			'</html>';

		return html;
	}

	this.pokaz = function(i)
	{
		try { okno.close() } catch (e) {}
		okno = window.open('', this.id, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
		if (!okno) return false;

		okno.document.close();
		okno.document.write(this._pokaz(i));
		okno.document.close();
		okno.focus();

		return true;
	}

	document.write('<div id="' + this.id + '"></div>');
//	document.write('<hr>');
	document.write('<div id="' + this.id + 'podglad" align="center"></div><br>');
	document.write('<div id="' + this.id + 'miniaturki" class="galeria" align="center"></div>');
	document.write('<div id="' + this.id + 'stronicowanie" align="center"></div>');
	this.wyswietl();

}

