function _NGM()
{
	this.objectName		= "NXCOM.NxGameControl.JP.2";
	this.oNxGameObj		= null;
	this.strServerHost	= "platform.nexon.co.jp/Auth/NGM/Bin/NGMDll.dll";
	this.strNGMDllCRC	= "";
	this.strGameDatas	= "";

	this.strPluginName	= "application/x-npnxgame-jp"
	this.strInstallPage = "pop_ngm_guide.html";
	
	// Browser Info Setting
	if (window.navigator.appName == "Microsoft Internet Explorer")
	{
		this.BrowserInfo= "IE";
	}
	else if (window.navigator.userAgent.indexOf("Firefox") != -1)
	{
		this.BrowserInfo= "FF";
	} 
	else 
	{
		this.BrowserInfo= "Unknown";
	}

	this.ErrorHandler = function NGM_ErrorHandler()
	{
		alert( "NGM Not Installed" );
	}

	this.installXPI = function NGM_installXPI(href)
	{
		var param = new Array();
		param["NxGame"] = href;
		InstallTrigger.install(param);
		
		return false;
	}
  
	if (this.BrowserInfo == "FF")
	{
		navigator.plugins.refresh(false);
		
		var mimetype = navigator.mimeTypes[ this.strPluginName ];
		
		if (mimetype && mimetype.enabledPlugin)
		{
			document.write("<span style='position:absolute;top:100px;left:100px;z-index:1'><embed id=\"npnxgame\" type=\"" + this.strPluginName + "\" pluginspage=\"" + this.strInstallPage + "\" HIDDEN=\"true\"/></span>");
		}
	}
	
	this.LoadModuleInfo = function NGM_LoadModuleInfo()
	{
		if (this.BrowserInfo == "IE")
		{
			var xmlDoc	= null;
			var xmlObj	= null;
						
			try
			{
				xmlDoc	= new ActiveXObject( "Microsoft.XMLDOM" );
			}		
			catch( ex )
			{
			}
			
			if ( xmlDoc != null )
			{
				xmlDoc.async="false";
				
				if ( xmlDoc.loadXML( NGMModuleInfo ) )
				{
					xmlObj	= xmlDoc.documentElement;
					
					var nodeNGMDll		= xmlObj.getElementsByTagName( "NGMDll" )[0];
					
					this.strServerHost	= nodeNGMDll.getAttribute( "host" );
					this.strNGMDllCRC	= nodeNGMDll.getAttribute( "crc" );
					this.strGameDatas	= "";
				}
			}
		}
		else if (this.BrowserInfo == "FF")
		{
			var parser=new DOMParser();
	 		var doc = parser.parseFromString(NGMModuleInfo,"text/xml");
			var xmlObj=doc.documentElement;

			var nodeNGMDll		= xmlObj.getElementsByTagName( "NGMDll" )[0];
			
			this.strServerHost	= nodeNGMDll.getAttribute( "host" );
			this.strNGMDllCRC	= nodeNGMDll.getAttribute( "crc" );
			this.strGameDatas	= "";
		} 
		
	}
	
	this.Init = function NGM_Init()
	{		
		if( this.oNxGameObj == null )
		{
			try
			{
				if ( this.BrowserInfo == "IE")
				{
					this.oNxGameObj = new ActiveXObject( this.objectName );
				}
				else if ( this.BrowserInfo == "FF")
				{
					this.oNxGameObj = document.getElementById('npnxgame');
				}				
			}
			catch( ex )
			{
			}

			if ( this.oNxGameObj != null )
			{
				this.LoadModuleInfo();
				
				this.oNxGameObj.ServerHost	= this.strServerHost;
				this.oNxGameObj.NGMDllCRC	= this.strNGMDllCRC;
				this.oNxGameObj.GameDatas	= this.strGameDatas;
			}
		}
	}

	this.GxForceInstall = function NGM_GxForceInstall( game, arg, passport )
	{
		this.Init();
		
		try
		{
			var ret		= this.oNxGameObj.ForceInstall( String( game ), String( passport ), String( arg ) );

			if( 2 == ret )
			{
				this.ErrorHandler();
			}
			else if ( 0 != ret )
			{
				alert( "Cannot Launch NGM! error code=" + ret );
			}
		}
		catch( ex )
		{
			this.ErrorHandler();
		}

	}
	
	this.GxLaunchGame = function NGM_GxLaunchGame( game, arg, passport )
	{
		this.Init();
	
		try
		{
			var ret		= this.oNxGameObj.Launch( String( game ), String( passport ), String( arg ) );
			
			if( 2 == ret )
			{
				this.ErrorHandler();
			}
			else if ( 0 != ret )
			{
				alert( "Cannot Launch NGM! error code=" + ret );
			}
		}
		catch( ex )
		{
			this.ErrorHandler();
		}
	}
	
	this.DownloadNGM = function NGM_DownloadNGM()
	{
		var DownloadURL = "http://platform.nexon.co.jp/Auth/NGM/Bin/Setup.exe";
		
		location.href = DownloadURL;	
	}
}

var NGM = new _NGM();