var OberonGameImplanter = {
	chatObjectPreparedHtml : "",
	gameObjectPreparedHtml : "",
	
	OGH_ACTIVEX_IE_CLASSID	: "CLSID:1D6E056F-D1BB-40F6-88E4-11EE98056FD2",
	OGH_FLASH_IE_CLASSID	: "CLSID:D0C0F75C-683A-4390-A791-1ACFD5599AB8",

	setChatObjectParamsHtml : function(inputHtml)
	{
		var oChatTag = new OberonGameImplanter.ObjectTag();
		oChatTag.id = ChatProperties.id;
		oChatTag.width = ChatProperties.width;
		oChatTag.height = ChatProperties.height;
		oChatTag.classid = this.OGH_FLASH_IE_CLASSID;
		oChatTag.codebase = "/Gameshell/GameHost/1.0/OberonGameHost.cab#version=" + GameShellDefinitions.oghVersion;
		oChatTag.paramsHtml = inputHtml;
	
		this.chatObjectPreparedHtml = oChatTag.toHTML();
	},

	setGameObjectParamsHtml : function(inputHtml)
	{
		if(GameShellDefinitions.isTier0)
		{
			this.gameObjectPreparedHtml = inputHtml;
		}
		else
		{
			var oGameTag = new OberonGameImplanter.ObjectTag();
			oGameTag.id = OnlineGameProperties.id;
			oGameTag.width = OnlineGameProperties.width;
			oGameTag.height = OnlineGameProperties.height;
			oGameTag.codebase = "/Gameshell/GameHost/1.0/OberonGameHost.cab#version=" + GameShellDefinitions.oghVersion;
			
			// OnlineGameProperties.playerVersion == "777" is patch for tracking ActiveX games, changed by using player = activex
			if(OnlineGameProperties.player == "activex" || OnlineGameProperties.playerVersion == "777")
				oGameTag.classid = this.OGH_ACTIVEX_IE_CLASSID;
			else
				oGameTag.classid = this.OGH_FLASH_IE_CLASSID;

			oGameTag.paramsHtml = inputHtml;
			this.gameObjectPreparedHtml = oGameTag.toHTML();
		}
	},

	injectGameHost : function()
	{
		$("OberonGameHost").innerHTML = this.gameObjectPreparedHtml;
	},

	// this method foe IE and may be overridden for Firefox
	injectChat : function()
	{
		$("ChatComponent").innerHTML = this.chatObjectPreparedHtml;
	},
	
	getGameHostObject : function(){return $("OberonGameHost").childNodes[0]},
	getChatHostObject : function(){return $("ChatComponent").childNodes[0]}
}

OberonGameImplanterFirefoxImplementation = {
	OGH_OBJECT_TYPE_FIREFOX : "application/OberonGameHost-plugin",
	
	setGameObjectParamsHtml : function(inputHtml)
	{
		if(GameShellDefinitions.isTier0)
		{
			this.gameObjectPreparedHtml = inputHtml;
		}
		else
		{
			var oGameTag = new OberonGameImplanter.ObjectTag();
			oGameTag.id = OnlineGameProperties.id;
			oGameTag.width = OnlineGameProperties.width;
			oGameTag.height = OnlineGameProperties.height;
			oGameTag.type = this.OGH_OBJECT_TYPE_FIREFOX;
			oGameTag.codebase = "/Gameshell/GameHost/1.0/OberonGameHost.XPI";
			oGameTag.paramsHtml = inputHtml;
			
			this.gameObjectPreparedHtml = oGameTag.toHTML();
		}
	},

	setChatObjectParamsHtml : function(inputHtml)
	{
		var oChatTag = new OberonGameImplanter.ObjectTag();
		oChatTag.id = ChatProperties.id;
		oChatTag.width = ChatProperties.width;
		oChatTag.height = ChatProperties.height;
		oChatTag.type = this.OGH_OBJECT_TYPE_FIREFOX;
		oChatTag.codebase = "/Gameshell/GameHost/1.0/OberonGameHost.XPI";
		oChatTag.paramsHtml = inputHtml;
	
		this.chatObjectPreparedHtml = oChatTag.toHTML();
					
	}
}

OberonGameImplanter.ObjectTag = function(){
				this.id			=	"";
				this.width		=	"";
				this.height		=	"";
				this.type		=	"";
				this.classid	=	"";
				this.codebase	=	"";
				this.paramsHtml	=	"";
				
				this.toHTML = function()
				{
					var returnVal = "<object width='" + this.width + "' height='" + this.height + "' ";
					returnVal += this.id ? "id='" + this.id + "' " : "";
					returnVal += this.type ? "type='" + this.type +"' " : "";
					returnVal += this.classid ? "classid='" + this.classid + "' " : "";
					returnVal += "codebase='" + this.codebase + "' >" + this.paramsHtml + "</object>";
					return returnVal;
				}
}

if(navigator.userAgent.indexOf("Firefox")!=-1)
	Object.extend(OberonGameImplanter, OberonGameImplanterFirefoxImplementation);

var GameShellFlowManager = {
	init : function()
	{
		//OberonGameImplanter.injectChat();

/////////// This change is for mute game before show, also affected on webPageScripts.js OnAdEnd() function
//		OberonGameImplanter.injectGameHost();
//		
//		gameHostContainer = $("OberonGameHost");
//		GameHostObj = OberonGameImplanter.getGameHostObject();
///////////////////////////////////////////////////////////////////

		//ChatHostObj = OberonGameImplanter.getChatHostObject();
		
		//iChatInitPollingId = window.setInterval(ChatInitPolling, 1000);
		
		ShowAd();
	}

}

var ChatObjectManager = {
	disableChat : function()
	{
		ChatHostObj.SendMessageToGame("Chat_Disable", "true");
	},
	
	enableChat : function()
	{
		ChatHostObj.SendMessageToGame("Chat_Disable", "false");
	}
};

Event.observe(window, "load", GameShellFlowManager.init, false);