// igl_Prototype 2.0 - igLoader Javascript Comms
// All code copyright (c)2005-2006 Indiepath Ltd All rights reserved. 
// Steal this and we'll publically humiliate you.

// Global Variables

var igVersion_Required	= "3004";
var Plugin_Object		= null;
var	ig_Width;
var ig_Height;

// Main Plugin Detection Function, Will detect Mozilla and ActiveX versions
function detectPlugin(Install_File) 
{
	navigator.plugins.refresh( false );
	Lightbox.showig('', 'Please be patient whilst the game is downloaded and prepared for launch.', ig_Width, ig_Height, 'initLoader()');
}

// Initialise the Plugin
function initLoader()
{
	$('igLoader').innerHTML = '';
	var replace 	= document.getElementById( "igL" );
	var output 		= "";
	output = output + "<object id='igl_embed' classid='CLSID:D1548A26-B8F6-4e86-AE74-E7062CCC2E2A'";
	output = output + "codebase='http://www.pjio.com/download/pjio_gamelauncher.CAB#Version=-1,-1,-1,-1'";
	output = output + "width='" + ig_Width + "' height='" + ig_Height + "'>\n";
	output = output + "<param name='type' value='application/vnd.igloader' />\n";
	output = output + "<param name='width' value='" + ig_Width + "' />\n";
	output = output + "<param name='height' value='" + ig_Height + "' />\n";
	output = output + "<param name='config_url' value='" + ig_location + "'/>\n";
	output = output + "<embed  id='igl_embed' name='igl_embed' type='application/vnd.igloader' PLUGINSPAGE='http://www.pjio.com/download/pjio_gamelauncher.xpi' PLUGINURL='http://www.pjio.com/download/pjio_gamelauncher.xpi'";
	output = output + "width='" + ig_Width + "' ";
	output = output + "height='" + ig_Height + "' ";
	output = output + "config_url='" + ig_location + "'>\n";
	output = output + "</embed>";
	output = output + "</object>\n";

	replace.innerHTML 	= output;
	Plugin_Object 		= document.igl_embed;
	
	setTimeout("igl_VersionValid()",50);

	return;
}

// *************************************************************************************************************************
// igLoader Specific Functions, these are called by the plugin - the function names must remain, the content can be changed
// *************************************************************************************************************************


function igl_DownloadPercent(percent)
{
	Lightbox.caption.setHTML(percent+"% Downloaded");
	return 4;
}
// *************************************************************************************************************************
function igl_DownloadComplete(arg)
{
	Lightbox.caption.setHTML("Preparing to launch, please wait.");
	return 4;
}
// *************************************************************************************************************************
function igl_AppLaunched()
{
	Lightbox.caption.setHTML("Launched! Click the close button when finished.");
	return 4;
}
// *************************************************************************************************************************
function igl_AppTerminated()
{
	$('igLoader').innerHTML = '';
	Lightbox.close();
	return 4;
}
// *************************************************************************************************************************
function igl_LaunchApplication()
{
	//Plugin_Object.Launch();
}
// *************************************************************************************************************************
function igl_Debug(message, alt)
{
	return 4;
}
// *************************************************************************************************************************
function igl_VersionValid()
{
	if (navigator.appVersion.indexOf("MSIE")!=-1) 
	{
		$('igLoader').innerHTML = '';
		return;
	}
	//alert(Plugin_Object.Version());
	if ( igVersion_Required == Plugin_Object.Version() )
	{
		$('igLoader').innerHTML = '';
		return;
	}
	else
	{
		igl_AppTerminated();
		alert("The GameLoader requires an update, you will now be prompted to download and run the update application.");
		window.location.href = "http://www.pjio.com/download/pjio_gamelauncher.xpi";
	}
}

