function openAnnPopup(annID, w)
{
	//document.write(annID)
	//alert(annID);
	//alert('a');
	if (anns[annID]!="")
	{
		txt = '<table border="0" width="100%">';
		txt += '<tr><td>&nbsp;</td></tr>';
		txt += '<tr><td>';
		txt += unescape(anns[annID]);
		txt += '</td></tr></table>';
		showHtmlbox(txt, w);
	}
}







//
// Configuration
//

// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = 'images/img_loading.gif';		
var closeButton = 'images/close.gif';	



//
// showHtmlbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showHtmlbox(objTxt, w)
{
	// prep objects
	var objOverlayHtml = document.getElementById('overlayHtml');
	var objLightboxHtml = document.getElementById('lightboxHtml');
	//var objCaption = document.getElementById('lightboxCaption');
	//var objImage = document.getElementById('lightboxImage');
	//var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetailsHtml = document.getElementById('lightboxDetailsHtml');
	var objTxtHtml = document.getElementById('textHtml');
	

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
/*
	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) - 20 + 'px');
		objLoadingImage.style.width = 160;
		objLoadingImage.style.height = 24;
		objLoadingImage.style.display = 'block';
	}
*/
	// set height of Overlay to take up whole page and show
	
	objOverlayHtml.style.height = (arrayPageSize[1] + 'px');
	objOverlayHtml.style.display = 'block';

		var lightboxTop = 50;
		var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
		
		//objLightboxDetailsHtml.style.width = '700px';
		
		objLightboxHtml.style.display = 'block';
		//alert(objTxt);
		
		
		objLightboxHtml.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightboxHtml.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		objLightboxHtml.style.width =  w+'px';
	
		objTxtHtml.innerHTML = objTxt;

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	objOverlayHtml.style.height = (arrayPageSize[1] + 'px');
	
//document.write(objTxt)
	/*
	// preload image
	imgPreload = new Image();

	imgPreload.onload=function(){
		
		//objImage.src = objLink.href;
		objImage.src = objTxt;

		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
		
		objLightboxHtml.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightboxHtml.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


		objLightboxDetailsHtml.style.width = imgPreload.width + 'px';
		
		
		objCaption.style.display = 'none';
		
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 

		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }

		// Hide select boxes as they will 'peek' through the image in IE
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

	
		objLightboxHtml.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlayHtml.style.height = (arrayPageSize[1] + 'px');

		return false;
	}

	imgPreload.src = objTxt;
	*/
	
}





//
// hideHtmlbox()
//
function hideHtmlbox()
{
	// get objects
	objOverlayHtml = document.getElementById('overlayHtml');
	objLightboxHtml = document.getElementById('lightboxHtml');

	// hide lightbox and overlay
	objOverlayHtml.style.display = 'none';
	objLightboxHtml.style.display = 'none';

	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}




//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initHtmlbox()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showHtmlbox(this); return false;}
		}
	}

	
	var objBodyHtml = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlayHtml = document.createElement("div");
	objOverlayHtml.setAttribute('id','overlayHtml');
	objOverlayHtml.onclick = function () {hideHtmlbox(); return false;}
	objOverlayHtml.style.display = 'none';
	objOverlayHtml.style.position = 'absolute';
	objOverlayHtml.style.top = '0';
	objOverlayHtml.style.left = '0';
	objOverlayHtml.style.zIndex = '90';
 	objOverlayHtml.style.width = '100%';
	objBodyHtml.insertBefore(objOverlayHtml, objBodyHtml.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();



/*
	// preload and create loader image
	var imgPreloader = new Image();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideHtmlbox(); return false;}
		objOverlayHtml.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = loadingImage;
*/
	// create lightbox div, same note about styles as above
	var objLightboxHtml = document.createElement("div");
	objLightboxHtml.setAttribute('id','lightboxHtml');
	objLightboxHtml.style.display = 'none';
	objLightboxHtml.style.position = 'absolute';
	objLightboxHtml.style.zIndex = '100';
	objBodyHtml.insertBefore(objLightboxHtml, objOverlayHtml.nextSibling);
	
	
	

	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Kliknij by zamknħa okno');
	objLink.onclick = function () {hideHtmlbox(); return false;}
	objLightboxHtml.appendChild(objLink);

	// preload and create close button image
	var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute('id','closeButton');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.zIndex = '200';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;
/*
	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	*/
	// create details div, a container for the caption and keyboard message
	var objLightboxDetailsHtml = document.createElement("div");
	objLightboxDetailsHtml.setAttribute('id','lightboxDetailsHtml');
	objLightboxHtml.appendChild(objLightboxDetailsHtml);
	
	var objTxtHtml = document.createElement("span");
	objTxtHtml.setAttribute('id','textHtml');
	objTxtHtml.setAttribute('innerHTML','');
	objLightboxDetailsHtml.appendChild(objTxtHtml);
	
/*
	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightboxDetailsHtml.appendChild(objCaption);

	// create keyboard message
	//var objKeyboardMsg = document.createElement("div");
	//objKeyboardMsg.setAttribute('id','keyboardMsg');
	//objKeyboardMsg.innerHTML = 'press <a href="#" onclick="hideHtmlbox(); return false;"><kbd>x</kbd></a> to close';
	//objLightboxDetailsHtml.appendChild(objKeyboardMsg);
	*/
}



addLoadEvent(initHtmlbox);	// run initLightbox onLoad
