// Define global constants
var intLeft = 0, intRight = 1;

// Initialise viewer
function body_onload()
{
	// Stop panning if in VAS
	stopVASAutoPan();

	// Set image to first
	document.getElementById("menu").selectedIndex = 3;
}

// Stops viewer auto panning if in run within VAS
function stopVASAutoPan()
{
	// Attempt to access parent page
	try
	{
		// Check if viewer is being run within VAS
		if (parent.document.title == "Viewer Container")
			{ document.ptviewer.stopAutoPan(); }
	}
	catch (varErr)
	{
		// Do nothing - keeps code running
	}
}

// Starts viewer auto panning in specified direction
function startAutoPan(intDirection)
{
	// Get pan control spin speed setting
	var intSpinSpeed = document.getElementById("pancontrolsspinspeed").childNodes[0].nodeValue;

	// Determine direction
	if (intDirection == intLeft)
		{ intSpinSpeed -= (intSpinSpeed * 2); }
	
	// Start image panning
	document.ptviewer.startAutoPan(parseFloat(intSpinSpeed), 0, 1);
}

// Change image
function changeImage(intImageID)
{
	//Set new image
	document.ptviewer.newPanoFromList(parseInt(intImageID));

	//Stop viewer panning if run in VAS
	stopVASAutoPan();
}

// Open link if not being run within VAS
function openLink(strURL, strWinName, intWidth, intHeight, strSettings)
{
	// Initialise variables
	var inVAS = false;

	// Attempt to access parent page
	try
	{
		// Check if viewer is being run within VAS
		if (parent.document.title == "Viewer Container")
		{
			// Set flag - running in VAS
			inVAS = true;
		}
	}
	catch (varErr)
	{
		// set flag = not in VAS
		inVAS = false;
	}

	// Check result of VAS test
	if (inVAS)
	{
		//Inform user that link will only work outside of VAS
		alert('This hyperlink is disabled within VAS.', 0 + 64, "Hyperlink Disabled");
		var blnReturn = false;
	}
	else
	{
		// Check if window name was specified
		if (strWinName == "") { strWinName = "_blank"; }

		// Open link
		window.open(strURL, strWinName, "width=" + intWidth + ",height=" + intHeight + "," + strSettings);
		var blnReturn = true;
	}

	try
	{
		// Stop panning if set
		if (document.ptviewer.getAutoPan()) { document.ptviewer.stopAutoPan(); }
	}
	catch(varErr)
	{
		// Do nothing - this keeps the code running
	}


	// Return value
	return blnReturn;
}

// Submit Email a Friend form
function submitEaF()
{
	// Check if running from website
	if (document.domain == "" || document.domain == null)
	{
		// Not running from website - show message
		openLink("../vhelp.html?v=eaf", "", 355, 270, "");
	}
	else
	{
		// Open new window
		if (openLink("", "eaf", 355, 430, ""))
		{
			// Update form fields and submit form
			var strViewer = document.eafform.v.value;
			var strURL = document.location.href;
			var objRegExp = new RegExp(strViewer + "\/" + strViewer + ".html.?", "i");
			var strViewerURL = strURL.replace(objRegExp, "default.html");
			var strProject = document.location.search;
			document.eafform.vurl.value = strViewerURL;
			document.eafform.vname.value = unescape(strProject.substring(6));
			document.eafform.submit();
		}
	}
}