//
// inDuality.js
//
// Support routines for embedding inDuality into web pages
//


var iPosition, sTemp, gsBrowserName;

//
// validateBrowserOS()
//
function validateBrowserOS()
{
	var sDetect = navigator.userAgent.toLowerCase();
	var sOS, sBrowser, sVersion;

	if ( checkIt( sDetect, 'konqueror' ))
	{
		sBrowser = 'Konqueror';
		sOS = 'Linux';
	}
	else if ( checkIt( sDetect, 'safari' ))
		sBrowser = 'Safari';
	else if ( checkIt( sDetect, 'omniweb' ))
		sBrowser = 'OmniWeb';
	else if ( checkIt( sDetect, 'opera' ))
		sBrowser = 'Opera';
	else if ( checkIt( sDetect, 'webtv' ))
		sBrowser = 'WebTV';
	else if ( checkIt( sDetect, 'icab' ))
		sBrowser = 'iCab';
	else if ( checkIt( sDetect, 'msie' ))
		sBrowser = 'Internet Explorer';
	else if ( !checkIt( sDetect, 'compatible' ))
	{
		sBrowser = 'Netscape Navigator';
		sVersion = sDetect.charAt( 8 );
	}
	else
		sBrowser = 'An unknown browser';

	if ( !sVersion )
		sVersion = sDetect.charAt( iPosition + sTemp.length );

	if ( !sOS )
	{
		if ( checkIt( sDetect, 'linux' ))
			sOS = 'Linux';
		else if ( checkIt( sDetect, 'x11' ))
			sOS = 'Unix';
		else if ( checkIt( sDetect, 'mac' ))
			sOS = 'Mac';
		else if ( checkIt(  sDetect,'win' ))
			sOS = 'Windows';
		else 
			sOS = 'an unknown operating system';
	}

	if ( (sBrowser != 'Internet Explorer' && sBrowser != 'Netscape Navigator' && sBrowser != 'Opera') || sOS != 'Windows' )
	{
		alert( 'This page uses the inDuality Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Internet Explorer, Firefox or Opera running on Windows. The page can not be displayed as you are not using Internet Explorer, Firefox or Opera on Windows.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Internet Explorer' && sOS == 'Windows' && parseInt( sVersion ) < 6 )
	{
		alert( 'This page uses the inDuality Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Internet Explorer Version 5.0 or above. The page can not be displayed as you are using version '+sVersion+' of Internet Explorer.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Netscape Navigator' && sOS == 'Windows' && parseInt( sVersion ) < 1 )
	{
		alert( 'This page uses the inDuality Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Firefox Version 1.0 or above. The page can not be displayed as you are using version '+sVersion+' of Firefox.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Opera' && sOS == 'Windows' && parseInt( sVersion ) < 9 )
	{
		alert( 'This page uses the inDuality Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Opera Version 9.0 or above. The page can not be displayed as you are using version '+sVersion+' of Opera.' );
		location = document.referer;
	}

	gsBrowserName = sBrowser;
}


//
// checkIt()
//
function checkIt( sDetect, sParam )
{
	iPosition = sDetect.indexOf( sParam ) + 1;
	sTemp = sParam;
	return ( iPosition );
}


//
// inDualityControl Constructor
//
function inDualityControl()
{
	this.pluginVersion = '2,0,0,148';
	this.width = '100%';
	this.height = '100%';
	this.contentType = 'Blink3D';
	this.oProperties = new Object();
}


//
// inDualityControl.addProperty
//
inDualityControl.prototype.addProperty = function( sPropertyName, sValue )
{
	this.oProperties[sPropertyName] = sValue;
}


//
// inDualityControl.create
//
inDualityControl.prototype.create = function()
{
	if ( window.ActiveXObject )
{	
		document.write( '<object ID="InDualityCtl" classid="CLSID:65A0276F-A5C2-4BA2-82DA-BC4AF3250F9E"' );
		document.write( ' CODEBASE="http://www.pelicancrossing.com/install/indualityplugin/indualityplugin.cab#version='+this.pluginVersion+'"' );
		document.write( ' width = "'+this.width+'"' );
		document.write( ' height = "'+this.height+'">' );

		for ( sPropertyName in this.oProperties )
		{
			document.write( ' <PARAM name="'+sPropertyName+'" value="'+this.oProperties[sPropertyName]+'">' );
		}

		document.write( '</object>' );
	}
	else
	{
		if ( gsBrowserName == 'Netscape Navigator' )
		{	
			document.write( '<object ID="InDualityCtl"' );
			document.write( ' TYPE = "application/x-induality"' );
			document.write( ' CODEBASE = "http://www.pelicancrossing.com/install/indualityplugin/indualityinstall.xpi"' );
			document.write( ' width = "'+this.width+'"' );
			document.write( ' height = "'+this.height+'">' );

			for ( sPropertyName in this.oProperties )
			{
				document.write( ' <PARAM name="'+sPropertyName+'" value="'+this.oProperties[sPropertyName]+'">' );
		}

		document.write( '</object>' );
	}
	else
	{
		document.write( '<embed name="InDualityCtl"' );
		document.write( ' type="application/x-induality"' );
		document.write( ' PluginsPage="http://www.pelicancrossing.com/install.htm"' );
		document.write( ' width="'+this.width+'"' );
		document.write( ' height="'+this.height+'"' );

		for ( sPropertyName in this.oProperties )
		{
			document.write( ' '+sPropertyName+'="'+this.oProperties[sPropertyName]+'"' );
		}

		document.write( '</embed>' );
		}
	}
}
//
// inDualityControl.getControl
//
inDualityControl.prototype.getControl = function()
{
	if ( window.document["inDualityCtl"] )
{	
		return window.document["inDualityCtl"];
	}
	else if ( navigator.appName.indexOf( "Microsoft Internet" ) == -1 )
	{
		if ( document.embeds && document.embeds["inDualityCtl"] )
			return document.embeds["inDualityCtl"];
	}
	else // if ( navigator.appName.indexOf( "Microsoft Internet" ) != -1 )
	{
		return document.getElementById("inDualityCtl");
	}
}


//
// inDualityControl.goHome
//
inDualityControl.prototype.goHome = function()
{
	this.getControl().PluginHome();
}


//
// inDualityControl.goBack
//
inDualityControl.prototype.goBack = function()
{
	this.getControl().PluginBack();
}


//
// inDualityControl.goForward
//
inDualityControl.prototype.goForward = function()
{
	this.getControl().PluginForward();
}




