var app = navigator.appName;
var OSName="Unknown OS";
var browser = "";
var appID;


function SetupVisuAll(container, applicationID, width, height, applicationDLL, altURL, param1, param2, firstperson, custom)
{
	SetupPlugin(container, applicationID, width, height, applicationDLL, altURL, param1, param2);
	
	InstallStart();
	
	appID = applicationID;	
	
	var codestring;/* = '<p>When the application has loaded - click to interact with it. <BR>Walk with the arrow keys and use the mouse to control your direction. <BR> Press ESC to get your mouse back and to exit full-screen mode. </p><input type=image src= "http://www.digitalarts.dk/VisuAll/fullscreen.gif" alt="Click to view in fullscreen" OnClick=Command("fullscreen","1024","768");><input type=image src= "http://www.digitalarts.dk/VisuAll/colorcode.gif" alt="Click to view in Color Code 3-D" OnClick=Command("stereo","","");>';*/
	
	if(firstperson == null || firstperson == true)
	{
		/*document.getElementById("plugininfo").innerHTML = '<p>When the application has loaded - click to interact with it. <BR>Walk with the arrow keys and use the mouse to control your direction. <BR> Press ESC to get your mouse back and to exit full-screen mode. </p><input type=image src= "http://www.digitalarts.dk/VisuAll/fullscreen.gif" alt="Click to view in fullscreen" OnClick=Command("fullscreen","1024","768");><input type=image src= "http://www.digitalarts.dk/VisuAll/colorcode.gif" alt="Click to view in Color Code 3-D" OnClick=Command("stereo","","");>';*/
		codestring = '<p>When the application has loaded - click to interact with it. <BR>Walk with the arrow keys and use the mouse to control your direction. <BR> Press ESC to get your mouse back and to exit full-screen mode. </p>';
		/*document.getElementById("plugininfo").innerHTML = codestring + '<input type=image src= "http://www.digitalarts.dk/VisuAll/fullscreen.gif" alt="Click to view in fullscreen" OnClick=Command("fullscreen","1024","768");><input type=image src= "http://www.digitalarts.dk/VisuAll/colorcode.gif" alt="Click to view in Color Code 3-D" OnClick=Command("stereo","","");>';*/
		codestring = codestring + '<a class="btn_case" OnClick=Command("fullscreen","auto","");>Fullscreen</a><a class="btn_case" OnClick=Command("stereo","","");>Stereo</a>';
		document.getElementById("plugininfo").innerHTML = codestring;/* + '<a class="btn_case" OnClick=Command("fullscreen","1024","768");>Fullscreen</a> <a class="btn_case" OnClick=Command("stereo","","");>Stereo</a>';*/
	}
	else
	{
		codestring = '<p>When the application has loaded - click and drag to interact with it. Press ESC to exit full-screen mode. </p>';
		codestring = codestring + '<a class="btn_case" OnClick=Command("fullscreen","auto","");>Fullscreen</a><a class="btn_case" OnClick=Command("stereo","","");>Stereo</a>';
		document.getElementById("plugininfo").innerHTML = codestring; /*+ '<a class="btn_case" OnClick=Command("fullscreen","1024","768");>Fullscreen</a> <a class="btn_case" OnClick=Command("stereo","","");>Stereo</a>';*/
	}
		
	if(custom != null)
		document.getElementById("plugininfo").innerHTML = codestring + custom;
			
}

function SetupPlugin(container, applicationID, width, height, applicationDLL, altURL, param1, param2)
{
	
	navigator.plugins.refresh();

	
	if (app == 'Microsoft Internet Explorer') 
	{
		document.getElementById(container).innerHTML = '<OBJECT CLASSID="CLSID:7D8F751B-659E-4406-AB70-5E049C52DD67", codebase="http://www.visuall3d.com/Player2.0.1.x/VisuAll2.cab#version=2,0,0,0", ID="'+applicationID+'", WIDTH="'+width+'", HEIGHT="'+height+'"> <param name="Application", value="'+applicationDLL+'"> <param name="Param1", value="'+param1+'"> <param name="Param2", value="'+param2+'"> </OBJECT>';
			
		browser = "IE";
	}
	else if (app == 'Netscape' && (navigator.userAgent.indexOf("Netscape")!=-1)) 
	{
		if(navigator.mimeTypes && navigator.mimeTypes["application/x-visuall2"] && navigator.mimeTypes["application/x-visuall2"].enabledPlugin)
		{
			if (navigator.appVersion.indexOf("Win")!=-1)
			{
				document.getElementById(container).innerHTML = '<embed id="'+applicationID+'", SRC="'+applicationDLL+'", TYPE="application/x-visuall2", WIDTH="'+width+'", HEIGHT="'+height+'", ALTURL="'+altURL+'", param1="'+param1+'", param2="'+param2+'", pluginspage="http://www.digitalarts.dk/VisuAll/VisuAll2.xpi">';
				/*document.write('<embed id="'+applicationID+'"',
							'SRC="'+applicationDLL+'"',
							'TYPE="application/x-visuall2"',
							'WIDTH="'+width+'"',
							'HEIGHT="'+height+'"',
							'ALTURL="'+altURL+'"',
							'param1="'+param1+'"',
							'param2="'+param2+'"',
							'pluginspage="http://www.visuall3d.com/Player2.0.1.x/VisuAll2.xpi">');*/
			}
			else
			{
				document.getElementById(container).innerHTML = '<p>Sorry, this operating system is not supported.</p>';
			}
		}
		
		browser = "Netscape";
	}
	else if (app == 'Netscape' && (navigator.userAgent.indexOf("Firefox")!=-1)) 
	{
		
		if(navigator.mimeTypes && navigator.mimeTypes["application/x-visuall2"] && navigator.mimeTypes["application/x-visuall2"].enabledPlugin)
		{
			if (navigator.appVersion.indexOf("Win")!=-1)
			{
				document.getElementById(container).innerHTML = '<embed id="'+applicationID+'", SRC="'+applicationDLL+'", TYPE="application/x-visuall2", WIDTH="'+width+'", HEIGHT="'+height+'", ALTURL="'+altURL+'", param1="'+param1+'", param2="'+param2+'", pluginspage="http://www.digitalarts.dk/VisuAll/VisuAll2.xpi">';
				/*document.write('<embed id="'+applicationID+'"',
							'SRC="'+applicationDLL+'"',
							'TYPE="application/x-visuall2"',
							'WIDTH="'+width+'"',
							'HEIGHT="'+height+'"',
							'ALTURL="'+altURL+'"',
							'param1="'+param1+'"',
							//'param2="'+param2+'">');
							'param2="'+param2+'"',
							'pluginspage="http://www.visuall3d.com/Player2.0.1.x/VisuAll2.xpi">');*/
			}
			else
			{
				document.getElementById(container).innerHTML = '<p>Sorry, this operating system is not supported.</p>';
			}
		}

		browser = "Firefox";
	}
	
	else if (app == 'Netscape' && (navigator.userAgent.indexOf("Safari")!=-1)) 
	{
		if (navigator.appVersion.indexOf("Win")!=-1)
		{
			document.getElementById(container).innerHTML = '<embed id="'+applicationID+'", SRC="'+applicationDLL+'", TYPE="application/x-visuall2", WIDTH="'+width+'", HEIGHT="'+height+'", ALTURL="'+altURL+'", param1="'+param1+'", param2="'+param2+'", pluginspage="http://www.digitalarts.dk/VisuAll/npvisuall2.dll">';
			/*document.write('<embed id="'+applicationID+'"',
						'SRC="'+applicationDLL+'"',
						'TYPE="application/x-visuall2"',
						'WIDTH="'+width+'"',
						'HEIGHT="'+height+'"',
						'ALTURL="'+altURL+'"',
						'param1="'+param1+'"',
						'param2="'+param2+'"',
						'pluginspage="http://www.visuall3d.com/Player2.0.1.x/npvisuall2.dll">');*/
		}
		else
		{
			document.getElementById(container).innerHTML = '<p>Sorry, this operating system is not supported.</p>';
		}
		
		browser = "Safari";
	}
	else if (app == 'Opera') 
	{
		if(navigator.appVersion.indexOf("Win")!=-1)
		{
			document.getElementById(container).innerHTML = '<embed id="'+applicationID+'", SRC="'+applicationDLL+'", TYPE="application/x-visuall2", WIDTH="'+width+'", HEIGHT="'+height+'", ALTURL="'+altURL+'", param1="'+param1+'", param2="'+param2+'", pluginspage="http://www.digitalarts.dk/VisuAll/npvisuall2.dll">';
			/*document.write('<embed id="'+applicationID+'"',
						'SRC="'+applicationDLL+'"',
						'TYPE="application/x-visuall2"',
						'WIDTH="'+width+'"',
						'HEIGHT="'+height+'"',
						'ALTURL="'+altURL+'"',
						'param1="'+param1+'"',
						'param2="'+param2+'"',
						'pluginspage="http://www.visuall3d.com/Player2.0.1.x/npvisuall2.dll">');*/
		}
		else
		{
			document.getElementById(container).innerHTML = '<p>Sorry, this operating system is not supported.</p>';
		}
		
		browser = "Opera";
	}

	else 
	{
		document.getElementById(container).innerHTML = '<p>Sorry, this browser is not supported.</p>';
	}
}

/*
------------------------------------------
  Function for sending command to plugin
-------------------------------------------
*/
function Command(command, param1, param2)
{
	document.getElementById(appID).Command(command, param1, param2);
	//appID.Command(command, param1, param2);
}

/*
--------------------------------------------------------------
  Function for letting plugin know of new application to load
---------------------------------------------------------------
*/
function SetApplication(app,param1,param2)
{
	document.getElementById(appID).SetApplication(app,param1,param2);
}

/*
--------------------------------------------------------------
  Function for installing by clicking button (if wanted)
  Could be used by Firefox and Netscape
-------------------------------------------------------------
*/
function InstallXPI()
{
	xpi={'VisuAll viewer plugin':'http://www.visuall3d.com/Player2.0.1.x/VisuAll2.xpi'};

	InstallTrigger.install(xpi);
}

/*
--------------------------------------------------------------
  Mozilla version of taking care of commands sent from plugin
---------------------------------------------------------------
*/
function OnCommand(command, param1, param2)
{
	if (command=="playerpos")
	{
		// Take care of the command sent from the plugin
		//alert("Player position: " + param1 + " " + param2)
	} 
	else
	{
		// Take care of the command sent from the plugin
		//alert(command + " using: " + param1 + " " + param2)
	}
}

/*
-------------------------------------------------------------------
  Setup install link (will only be visible for firefox or netscape
--------------------------------------------------------------------
*/
function InstallLink(container)
{
    //---------------------------------------------------------------
	// This code could be included to provide a download link if the 
	// plugin is not installed and it the download for some reason 
	// isn't triggered automativally.
	//---------------------------------------------------------------
	if(browser == 'Netscape' || browser == 'Firefox' && !(navigator.mimeTypes && navigator.mimeTypes["application/x-visuall2"] && navigator.mimeTypes["application/x-visuall2"].enabledPlugin))
	{   
		document.getElementById(container).innerHTML = '<p>You need the VisuAll viewer plugin. If installation does not start automatically - <a href="">click here.</a></p><br>';
		//document.write('<p>You need the VisuAll viewer plugin. If installation does not start automatically - <a href="">click here.</a></p><br>');
	}	
	//---------------------------------------------------------------	
	//if(browser == 'Netscape' || browser == 'Firefox')
	//	document.write('<BUTTON onclick="InstallXPI();">Install plugin</BUTTON>');
}

function InstallStart()
{
    //---------------------------------------------------------------
	// This code calls function that triggers install of plugin
	// (if firefox or netscape)
	//---------------------------------------------------------------
    if(browser == 'Netscape' || browser == 'Firefox' && !(navigator.mimeTypes && navigator.mimeTypes["application/x-visuall2"] && navigator.mimeTypes["application/x-visuall2"].enabledPlugin))
    {		
		InstallXPI();
	}
}