/* position footer
**********************/
function getAbsPos(obj)
{
	var x = 0;
	var y = 0;
	while(obj.offsetParent)
	{
		y += obj.offsetTop;
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	var rtn = {X:x,Y:y}
	return rtn;
}
function getInnerHeight()
{
//  alert(document.body.scrollHeight);
	if (self.innerHeight) // all except Explorer
	{
		innerY = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		innerY = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		innerY = document.body.clientHeight;
	}
	return innerY
}
///
///
///
function getScrollHeight()
{
	return document.body.scrollHeight;
}
///
///
///
function sizePage()
{
	var cont = document.getElementById('content');
	var foot = document.getElementById('footer')
	var footH = foot.offsetHeight;
	var winH = getInnerHeight();
	var headH = getAbsPos(cont).Y;
	
	var theSize = winH - headH - footH - 29;
	
	if (cont.offsetHeight < theSize) {
		cont.style.height = theSize + 'px';
	}
	else {
		document.getElementById('container').style.height = document.getElementById('container').offsetHeight + 'px';
	}
	
	document.getElementById('wrapper').style.height = document.getElementById('container').offsetHeight + 'px';
	
}
//window.onresize = sizePage;
window.onload = sizePage;

// pop-up for opening news and project images
var popwin = null;
function popImage(imagesrc,imgwidth,imgheight,alt)
{
	var maxWidth = screen.width - 30;
	var maxHeight = screen.height - 70;
	var winwidth = (imgwidth) ? imgwidth : 500;
	var winheight = (imgheight) ? imgheight : 500;
	var look = '';
	var left = (screen.width/2) - winwidth/2;
 	var top = (screen.height/2) - winheight/2;
	
	// resize window if too large
	if(imgwidth > maxWidth) {
		winwidth = maxWidth;
		look += 'resizable,scrollbars,';	
		left = 0;
	}
	if(imgheight > maxHeight) {
		winheight = maxHeight;
		if(!look) look += 'resizable,scrollbars,';
		top = 0;
	}
	
	look +='width='+winwidth+',height='+winheight+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	if(alt==null) alt = 'Image';
	if (popwin != null && !popwin.closed) popwin.close();
	popwin=window.open("","imgWin",look);
	popwin.document.open();
	popwin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n');
	popwin.document.write('<html>\n<head>\n');
	popwin.document.write('<title>'+alt+'</title>\n');
	popwin.document.write('<style type="text/css">\n');
	popwin.document.write('body { margin:0; padding:0; background-color:black; background-image:url(../images/loading.gif);	background-repeat:no-repeat; background-position:center center; }\n');
	popwin.document.write('img { display:block; border:none; }\n');
	popwin.document.write('</style>\n');
	popwin.document.write('</head>\n<body>\n');
	popwin.document.write('<a href="javascript:;" alt="close" onclick="window.close()">');
	popwin.document.write('<img src="'+imagesrc+'" alt="'+alt+'"');
	if(imgwidth) popwin.document.write(' width="'+imgwidth+'"');
	if(imgheight) popwin.document.write(' height="'+imgheight+'"');
	popwin.document.write('></a>\n');
	popwin.document.write('</body>\n</html>');
	popwin.document.close();
	return true;
}

function forwardToMap(from,to){
	window.open("http://maps.google.co.uk/maps?saddr="+from+"&daddr="+to+"&hl=en","imgWin","");
}

// generic multi use pop-up with pre-programmed 'type'
newWin = null;
function openNewWindow(strURL, strType, strWidth, strHeight){
	if (newWin != null && !newWin.closed) newWin.close();
	var left = (screen.width/2) - strWidth/2;
	var top = (screen.height/2) - strHeight/2;
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="console-scroll") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,"+"resizable,location,height="+strHeight+",width="+strWidth;
	strOptions+=',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();	
	return true;
}
