// JavaScript Document "PicUtil.js"

var maxWidth= 800;	// default maximum picture width

function setWidth()
{
	if (self.innerWidth)
		frameWidth = self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		frameWidth = document.documentElement.clientWidth;
	else if (document.body)
		frameWidth = document.body.clientWidth;
	else 
		frameWidth= 0;

	if( frameWidth < 900 )
		maxWidth= 600;
}

function showPic(pic,path)
{
	if( (picPath == undefined) && (path == undefined) )
		alert('Picture path has not been set');
	else
	{
		if(path == undefined ) path= picPath;
		window.location= "showpic.php?path="+path+"&pic="+pic+"&maxw="+maxWidth;
	}
	return false;
}

function getHeight()
{
	if (self.innerHeight)
		frameHeight = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		frameHeight = document.documentElement.clientHeight;
	else if (document.body)
		frameHeight = document.body.clientHeight;
	else 
		frameHeight= 0;
	return frameHeight;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function scrollAsNeeded()
{
	// get size of client area
	var hgt= getHeight();
	// get size of image
	e_img= document.getElementById('mainImg');
	imgHeight= e_img.offsetHeight;
	imgTop= findPosY(e_img);
	// get position of menu
	e_menu= document.getElementById('menu');
	menuTop= findPosY(e_menu);
	// if pic.y + pic.height > client.height
//		scrollAmt= pic.bottom -client.height
	var scrollAmt= menuTop -(((hgt-((imgTop +imgHeight) -menuTop))/3)*2);
	if(scrollAmt > 0)
	{
	 //alert("client height:"+hgt+", imgTop:"+imgTop+", imgHeight:"+imgHeight+"\r\nmenuTop:"+menuTop+", scrollAmt:"+scrollAmt);
	//		if( scrollAmt > menu.top ) scrollAmt= menu.top
		if( scrollAmt > menuTop )
			scrollAmt= menuTop;
		window.scrollTo(0,scrollAmt);
	}
}

