var shadowDiv = null;
var viewDiv = null;

function onGalleryViewClose()
{
	if( shadowDiv != null ) {
    	document.body.style.overflow = "";
    	document.body.removeChild( shadowDiv );
    	shadowDiv = null;
    }

	if( viewDiv != null ) {
		document.body.removeChild( viewDiv );
		viewDiv = null;
	}
}

function onGalleryView(link)
{
	var imgWidth = link.getAttribute( "lw" );
	var imgHeight = link.getAttribute( "lh" );

	shadowDiv = document.createElement( "DIV" );
	viewDiv = document.createElement( "DIV" );
	
    shadowDiv.style.position = "absolute";
    shadowDiv.style.display = "block";
    shadowDiv.style.background = "#1e1e4e";
    shadowDiv.style.opacity = 0.7;
    shadowDiv.style.filter = "alpha(opacity=70)";
    if( shadowDiv.style.setAttribute )
		shadowDiv.style.setAttribute( "-moz-opacity", "0.7" );
    shadowDiv.style.width = "1px";
    shadowDiv.style.height = "1px";
    shadowDiv.style.zIndex = 100;
    document.body.appendChild( shadowDiv );
    document.body.style.overflow = "hidden";
	setEventHandler( shadowDiv, "click", onGalleryViewClose );
	
    var mtx = this.getDocMetrics();

	viewDiv.style.position = "absolute";
	viewDiv.style.display = "block";
	viewDiv.style.background = "#ffffff";
	viewDiv.style.left = (mtx.offX + Math.round((mtx.width - (new Number( imgWidth ) + 60)) / 2)) + "px";
	viewDiv.style.top = (mtx.offY + Math.round((mtx.height - (new Number( imgHeight ) + 60)) / 2)) + "px";
	viewDiv.style.height = imgHeight + "px";
	viewDiv.style.width = imgWidth + "px";
	viewDiv.style.padding = "30px 30px 30px 30px";
	viewDiv.style.zIndex = 101;
	viewDiv.innerHTML = "<IMG src=\"" + link.href + "\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" border=\"0\" /><span style=\"display: block; padding-top: 6px; clear: both; float: right;\"><A href=\"javascript:onGalleryViewClose();\" style=\"color: red; font-weight: bold; font-size: 13px; text-decoration: none;\">X</A></span>";
	
    document.body.appendChild( viewDiv );

    // full
    shadowDiv.style.left = mtx.offX + "px";
    shadowDiv.style.top = mtx.offY + "px";
    shadowDiv.style.width = mtx.width + "px";
    shadowDiv.style.height = mtx.height + "px";

	return false;
}