function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) oldonload();
		func();
		}
	}
}

function prepareGallery() {
	var gallery = document.getElementById('gal_tbl');
	var links = gallery.getElementsByTagName('a');
	for (var i=0; i < links.length; i++) {
		links[i].onclick = function() {
			return showPreview(this);
		};
	}
}

function getDocumentHeight() {
  return (document.body.scrollHeight > document.body.offsetHeight ) ? document.body.scrollHeight : document.body.offsetHeight;
}

function showPreview() {
	var previewbg = document.getElementById('previewbg');
	var preview = document.getElementById('preview');
	var foto = document.getElementById('table1');

	previewbg.style.display = 'block';
	previewbg.style.height = getDocumentHeight();
	preview.style.display = 'block';
	(document.all && !window.opera) ? foto.style.display = 'block' : foto.style.display = 'table';
}

function closePreview() {
	var previewbg = document.getElementById('previewbg');
	var preview = document.getElementById('preview');

	previewbg.style.display = 'none';
	preview.style.display = 'none';
}


addLoadEvent(prepareGallery);