//IE5+, Mozilla 1.0+, Opera 7+
function  getPageSize()
{
	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 if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight)
	{ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in 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;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function elementPosition(element)
{
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
    } while (element = element.offsetParent);
    return [offsetLeft, offsetTop];
}

function picPreviewShow(panid, picid, picsrc, pw, ph)
{
	var splashobj = uh_get_object(panid + "splash");
	var panobj = uh_get_object(panid);
	var picobj = uh_get_object(picid);
	if( panobj && picobj && splashobj )
	{
		psize = getPageSize();

		//alert( psize[0] );

		//alert( document.documentElement.scrollTop );
		//alert( document.body.scrollTop );

		splashobj.style.width = psize[0];
		splashobj.style.height = psize[1];

		showItem(panid + "splash");

		browser_w = getClientWidth();
		browser_h = getClientHeight();

		//alert("h: " + browser_w + "; h: " + browser_h + "pw: " + pw + "; ph: " + ph);

		vert_off = 0;
		if( document.body.scrollTop )
		{			vert_off = document.body.scrollTop;		}

		pan_x = Math.round( (browser_w - pw)/2 );
		pan_y = Math.round( (browser_h - ph)/2 ) + vert_off;

		//alert("pan_x: " + pan_x + "; pan_y: " + pan_y);

		showItem(panid);

		panobj.style.left = pan_x + "px";
		panobj.style.top = pan_y + "px";

		pan_w = (40 + parseInt(pw));
		pan_h = (60 + parseInt(ph));

		panobj.style.width = pan_w  + "px";
		panobj.style.height = 10  + "px";

		picobj.src = picsrc;
		picobj.style.width = pw + "px";
		picobj.style.height = ph + "px";

		setTimeout("picPreviewResize('" + panid + "', 15, "+pan_w+", 10, "+pan_w+", "+pan_h+")", 50);
	}
}

function picPreviewResize(panid, steph, w, h, maxw, maxh)
{
	var panobj = uh_get_object(panid);
	if( panobj )
	{
		if( (steph + h) < maxh )
		{
			panobj.style.height = (steph+h) + "px";
			setTimeout("picPreviewResize('" + panid + "', "+steph+", "+w+", "+(steph+h)+", "+maxw+", "+maxh+")", 50);
		}
		else
		{
			panobj.style.height = maxh + "px";
		}
	}
}

function picPreviewClose(panid)
{
	hideItem(panid);
	hideItem(panid + "splash");
}