onload = init;

function init() {
	initpopup();
	initpage();
}

function initpage() {
	oHtml = document.getElementsByTagName("HTML");
	
	if ( document.all && !window.opera ) {
		oHtmlHeight = oHtml[0].offsetHeight - 4;
	} else {
		oHtmlHeight = oHtml[0].clientHeight;
	}
	
	oDiv = document.getElementById("pg-main");
	oText = document.getElementById("pg-text");
	
	headAndFoot = 229 + 25;
	pageHeight = oDiv.offsetHeight + headAndFoot;
	if ( pageHeight < oHtmlHeight ) {
		oText.style.height = (oHtmlHeight - headAndFoot) + "px";
	}
}

function initpopup() {
	oImgA = document.getElementsByTagName("A");
	for( i=0; i<oImgA.length; i++) {
		if ( oImgA[i].className == "popup" ) {
			oImgA[i].onclick = function () {
				showImage(this);
				return false;
			}
		}
	}
}

function showImage( oObj ) {
//	alert( oObj.getAttribute("href"));
	pic = oObj.getAttribute("href");
	
	settings = 'height=100,width=100,scrollbars=no,resizable=1';

	win = window.open('','WindowImg',settings);
	win.document.open('text/html');
	win.document.write('<title>Galéria</title>');
	win.document.write('<script type="text/javascript">');
	win.document.write('onload=initpopupwindow;');
	win.document.write('function initpopupwindow() {');
	win.document.write('document.images[0].border=0;');
	win.document.write('iWidth = document.body.clientWidth;');
	win.document.write('iHeight = document.body.clientHeight;');
	win.document.write('iWidth = document.images[0].width - iWidth;');
	win.document.write('iHeight = document.images[0].height - iHeight;');
	win.document.write('window.resizeBy(iWidth, iHeight);');
	win.document.write('self.focus();');
	win.document.write('}');
	win.document.write('</script>');
	win.document.write('<body id="bodypopup" bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	win.document.write('<a href="javascript://" onClick="window.close();"><img id="popupimg" src="'+ pic +'" border="0"></a>');
	win.document.writeln('</body>');
	win.document.close();
}