var IMG_POPUP_WIDTH		= 500;
var IMG_POPUP_HEIGHT	= 500;
var IMG_POPUP_ACTIVE	= false;

var getPageSize = function() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	}
	else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	}
	else {
		pageWidth = xScroll;
	}


	var tResult = { pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight };

	return tResult;
}

function openPopup(id)
{
	oImage = document.getElementById(id);

	var testWin = window.open('','test_win','width=550,height=600,left=100,top=50,toolbar=1,status=1,scrollbars=yes');

	if(jQuery.browser.msie)
	{
		jQuery(testWin.document.body).html( jQuery(oImage).html() )
	}
	else
	{
		jQuery(testWin.document.body).html('')
		jQuery(testWin.document.body).append( jQuery(oImage).clone() )
	}

	return;

	if ( oImage.style.visibility != 'visible' )
	{
		var scroll_left	= 0;
		var scroll_top	= 0;

		if ( document.documentElement )
		{
			scroll_left	= document.documentElement.scrollLeft;
			scroll_top	= document.documentElement.scrollTop;
		}
		else if ( document.body )
		{
			scroll_left	= document.body.scrollLeft;
			scroll_top	= document.body.scrollTop;
		}


		oImage.style.width	= IMG_POPUP_WIDTH + 'px';
		oImage.style.height	= IMG_POPUP_HEIGHT + 'px';
		oImage.style.left	= ((getPageSize().pageWidth - IMG_POPUP_WIDTH)/2) + scroll_left + 'px';
		oImage.style.top	= ((getPageSize().pageHeight - IMG_POPUP_HEIGHT)/2) + scroll_top + 'px';

		oImage.style.visibility = 'visible';

		IMG_POPUP_ACTIVE = true;
	}
}

function closePopup(id)
{
	oImage = document.getElementById(id);

	if ( oImage.style.visibility != 'hidden' )
	{
		oImage.style.visibility = 'hidden';

		IMG_POPUP_ACTIVE = false;
	}
}
