// Global variables
var intHeight;
var intWidth;
//var	objTimer;
var	IsTimeOut = false;

// Set a string for use in browsers requiring "px" if necessary.
var strPx = document.childNodes ? 'px' : 0;

// Events to look out for
window.onload = initialise;
window.onresize = initialise;
//window.onfocus = reload;

// Initialise takes care of processes that must run during page loading and/or resizing.
function initialise()
{
	// Only carry out the processes within initialise where browsers support getElementById,
	// otherwise the results can not be predicted.
	if (document.getElementById)
	{
		getWindowSize();
		reposition();
		//if(isPNG()) usePNG();
		//objTimer = window.setTimeout("IsTimeOut = true;", 1000);
	}
}

// isPNG checks the browser name to determine likelyhood of PNG transparency compatibility
function isPNG()
{
	if (navigator.product)
	{
		if(navigator.product == "Gecko")
		{
			return true;
		}
	}
	else
	{
		if (navigator.userAgent.indexOf("MSIE") != -1)
		{
			var version = navigator.userAgent.indexOf("MSIE") + 5;
			if (parseInt(navigator.userAgent.charAt(version)) >= 7)
			{
				return true;
			}
		}
		if (navigator.userAgent.indexOf("Opera") != -1)
		{
			var version = navigator.userAgent.indexOf("Opera") + 6;
			if (parseInt(navigator.userAgent.charAt(version)) >= 8)
			{
				return true;
			}
		}
		return false;
	}
}

// usePNG substitutes
function usePNG()
{
	if (document.getElementById("JPGLogo"))
	{
		document.getElementById("JPGLogo").style.display = "none";
	}
	if (document.getElementById("Logo"))
	{
		document.getElementById("Logo").style.display = "block";
	}
}

// Reload tests to see if the window has just received focus
function reload()
{
	if (IsTimeOut == true)
	{
		document.location = this.location;
	}
}

function showPopUp(object, posX, posY)
{
	var info = object + 'Info';
	document.getElementById(info).style.left = parseInt(posX) - 65 + strPx;
	document.getElementById(info).style.top = parseInt(posY) - 105 + strPx;
	document.getElementById(info).style.visibility = 'visible';
}

function hidePopUp(object)
{
	var info = object + 'Info';
	document.getElementById(info).style.visibility = 'hidden';
}

// GetWindowSize simply tests to see how large the viewing area is
function getWindowSize()
{
	if(typeof(window.innerWidth) == "number" )
	{
		//Non-IE
		intWidth = window.innerWidth;
		intHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		intWidth = document.documentElement.clientWidth;
		intHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		intWidth = document.body.clientWidth;
		intHeight = document.body.clientHeight;
	}
}

// Reposition moves and/or resizes screen elements to fill the user's viewport.
function reposition()
{
	if (document.getElementById("Container") && document.getElementById("RightSide"))
	{
		document.getElementById("Container").style.width = "100%";
		if (parseInt(document.getElementById("Container").offsetWidth) <= 760)
		{
			document.getElementById("Container").style.width = 760 + strPx;
		}
		document.getElementById("RightSide").style.width = parseInt(document.getElementById("Container").offsetWidth) - 310 + strPx;
	}
	//if (document.getElementById("Container"))
	//{
		// if (parseInt(document.getElementById("Container").offsetHeight) <= parseInt(intHeight))
		// {
			// document.getElementById("Container").style.top = (parseInt(intHeight) - parseInt(document.getElementById("Container").offsetHeight)) / 2 + strPx;
			// document.getElementById("Container").style.height = parseInt(intHeight) - 20 + strPx;
		// }
		//if (parseInt(document.getElementById("Container").offsetWidth) <= parseInt(intWidth))
		//{
		//	document.getElementById("Container").style.left = (parseInt(intWidth) - parseInt(document.getElementById("Container").offsetWidth)) / 2 + strPx;
		//}
	//}
}

// openWindow opens a windows of the specified size with the options as specified
function openWindow(windowURL, windowName, windowFeatures, originalWindowName)
{
	var remote = open(windowURL, windowName, windowFeatures);
	if (remote.opener == null) // if something went wrong
		remote.opener = window;
	remote.opener.name = originalWindowName;
	return remote;
}

function beforePrint()
{
	if (document.getElementById)
	{
		if (document.getElementById("Container") && document.getElementById("RightSide"))
		{
			document.getElementById("Container").style.width = "100%";
			document.getElementById("RightSide").style.width = "100%";
		}
	}
}

function afterPrint()
{
	reposition();
}

function email(name, description)
{
	document.write('<a href="mailto:' + name + '@' + 'pannone.co.uk' + '" title="' + description + '">' + name + '@' + 'pannone.co.uk' + '</a>');
}
