
/******************************************************************************
*     GAME SETTINGS
*******************************************************************************/
var zoo_game_no = 17;

// Upsell Settings
var Enable_Upsell = true;
var Upsell_Url = 'http://www.popcap.jp/game_detail.php?game_no=17'; // This doesn't get used if Enable_Upsell = false

// Absolute Path to Game Files
// (If left blank, it will be assumed that the game files are in the same folder as this include file.)
var Base_Path = '/webgames/peggle/';

// Paths to ActiveX Loader Files
var Logo_Cab_Path = '/webgames/logo.cab';
var IE_Plugin_Path = '/webgames/popcaploader_v10.cab#version=1,0,0,10';
var FireFox_Plugin_Path = '/webgames/PopCapPluginInstaller_v2.exe';

var Upsell_Ad_Frequency = 4;
  
/******************************************************************************
*     POPCAPGAME BASE
*******************************************************************************/

var thePopCapGame = null;

function popCapGame(gameName, id, gameWidth, gameHeight)
{
    popCapGame.prototype.displayName = gameName;
    popCapGame.prototype.id = id;
    popCapGame.prototype.width = gameWidth;
    popCapGame.prototype.height = gameHeight;
    
    popCapGame.prototype.paramNames = new Array();
    popCapGame.prototype.params = new Array();	
    popCapGame.prototype.hosts = new Array();
    popCapGame.prototype.signatures = new Array();
	
    popCapGame.prototype.partnerName = '';
	popCapGame.prototype.basePath = '';
    popCapGame.prototype.upsellUrl = '';
	popCapGame.prototype.objectSetup = '';
	popCapGame.prototype.containerId = 'gamediv';
	
	popCapGame.prototype.LoadBroadcast = 'LoadBroadcast';
	popCapGame.prototype.SessionReady = 'SessionReady';
	popCapGame.prototype.GameReady = 'GameReady';
	popCapGame.prototype.ScoreBroadcast = 'ScoreBroadcast';
	popCapGame.prototype.GameBreak = 'GameBreak';
	popCapGame.prototype.ScoreSubmit = 'ScoreSubmit';
	popCapGame.prototype.GameEnd = 'GameEnd';
	popCapGame.prototype.CustomEvent = 'CustomEvent';

    popCapGame.prototype.levelCount = 0;
	popCapGame.prototype.gameObject = null;
    popCapGame.prototype.hide = false;
}

popCapGame.prototype.pathConcat = function(first,last)
{
	if (first == '') return last;
	if (first.search(/\/$/) == -1) return first + '/' + last;
	return first + last;
}

popCapGame.prototype.applyBasePath = function()
{
}

popCapGame.prototype.write = function()
{
}

popCapGame.prototype.getParams = function()
{
}

popCapGame.prototype.sendNotification = function(method)
{
}

/*---- CALLS TO GAME ----*/

popCapGame.prototype.SessionStart = function()
{
	this.sendNotification('SessionStart');
}

popCapGame.prototype.GameStart = function()
{
	this.sendNotification('GameStart');
}

popCapGame.prototype.GameMenu = function()
{
	this.sendNotification('GameMenu');
}

popCapGame.prototype.GameContinue = function()
{
	this.sendNotification('GameContinue');
}

popCapGame.prototype.CustomReturn = function()
{
	this.sendNotification('CustomReturn');
}

popCapGame.prototype.Mute = function(isMute)
{
	this.sendNotification(isMute ? 'MuteOn' : 'MuteOff');
}

popCapGame.prototype.Pause = function(isPause)
{
	this.sendNotification(isPause ? 'PauseOn' : 'PauseOff');
}

/*---- EVENT HANDLING ----*/

popCapGame.prototype.OnLoadBroadcast = function(params)
{
}

popCapGame.prototype.OnSessionReady = function(params)
{

	this.SessionStart();

}

popCapGame.prototype.OnGameReady = function(params)
{
	this.GameStart();
}

popCapGame.prototype.OnScoreBroadcast = function(params)
{    
}

popCapGame.prototype.OnGameBreak = function(params)
{

	this.GameContinue();

}

popCapGame.prototype.OnScoreSubmit = function(params)
{
}

popCapGame.prototype.OnGameEnd = function(params)
{

	this.GameMenu();

}

popCapGame.prototype.OnCustomEvent = function(params)
{
    if (Enable_Upsell) window.open(this.upsellUrl);
    this.CustomReturn();
}

popCapGame.prototype.receiveNotification = function(method,params)
{
    if(typeof(Zoo_receiveNotification) == 'function'){
      Zoo_receiveNotification(method, params);
		}
    if (method == this.GameEnd)
    {
        this.OnGameEnd(params);
    }
    else if (method == this.LoadBroadcast)
    {
        this.OnLoadBroadcast(params);
    }
    else if (method == this.SessionReady)
    {
        this.OnSessionReady(params);
    }
    else if (method == this.GameReady)
    {
        this.OnGameReady(params);
    }
    else if (method == this.ScoreBroadcast)
    {
        this.OnScoreBroadcast(params);
    }
    else if (method == this.GameBreak)
    {
        this.OnGameBreak(params);
    }
    else if (method == this.ScoreSubmit)
    {
        this.OnScoreSubmit(params);
    }
    else if (method == this.CustomEvent)
    {
        this.OnCustomEvent(params);
    }
}

/******************************************************************************
*     ACTIVEX : POPCAPGAME
*******************************************************************************/

popCapAXGame.prototype = popCapGame.prototype;
popCapAXGame.prototype.constructor = popCapAXGame;
popCapAXGame.prototype.baseClass = popCapGame.prototype.constructor;

function popCapAXGame(gameName, id, gameWidth, gameHeight, gameDll, gameCab)
{	
    popCapGame(gameName, id, gameWidth, gameHeight);

    popCapAXGame.prototype.gameDll = gameDll;
    popCapAXGame.prototype.gameCab = gameCab;
	
    popCapAXGame.prototype.logoCab = 'logo.cab';
    popCapAXGame.prototype.loaderCab = 'popcaploader_v10.cab#version=1,0,0,10';
    popCapAXGame.prototype.plugin = 'PopCapPluginInstaller_v2.exe';
	popCapAXGame.prototype.isInIE = (document.all != null);
}

popCapAXGame.prototype.applyBasePath = function()
{

	this.gameCab = this.pathConcat(this.basePath, this.gameCab);
}

popCapAXGame.prototype.write = function()
{
	if (this.isInIE || this.checkForPlugin())
	{

		this.applyBasePath();

		this.objectSetup = '<!--[if !IE]><!-->\r\n';
	    this.objectSetup += '<div id="' + this.containerId + '"';
	    if (this.hide) this.objectSetup += ' style="visibility: hidden;"';
		this.objectSetup += '>\r\n';
		this.objectSetup += '<embed type="application/x-popcaploader;version=1.0.0.1" ';
		this.objectSetup += 'id="'+this.id+'" ';
		this.objectSetup += 'numhosts="'+this.hosts.length+'" ';
		for(var i = 0; i < this.hosts.length; i++)
		{
			this.objectSetup += 'host'+(i+1)+'="' + this.hosts[i] + '" ';
			this.objectSetup += 'hostsig' + (i+1) + '="' + this.signatures[i] + '" ';
		}
		this.objectSetup += 'gamename="'+this.gameDll+'" ';
		this.objectSetup += 'partnername="'+this.partnerName+'" ';
		this.objectSetup += 'displayname="'+this.displayName+'" ';
		this.objectSetup += 'gamecab="'+this.gameCab+'" ';
		this.objectSetup += 'logocab="'+this.logoCab+'" ';
		this.objectSetup += this.getParams();
		this.objectSetup += 'height="'+this.height+'" ';
		this.objectSetup += 'width="'+this.width+'"></embed>\r\n';
		this.objectSetup += '</div>\r\n';
		this.objectSetup += '<script language="JavaScript" type="text/javascript">\r\n';
		this.objectSetup += 'function PopcapNotification_'+this.id+'(method,param)\r\n';
		this.objectSetup += '{\r\n';
		this.objectSetup += '  thePopCapGame.receiveNotification(method,param);\r\n';
		this.objectSetup += '}\r\n';
		this.objectSetup += '</script>\r\n';
		this.objectSetup += '<!--<![endif]-->\r\n';
		this.objectSetup += '<!--[if IE]>\r\n';
	    this.objectSetup += '<div id="' + this.containerId + '"';
	    if (this.hide) this.objectSetup += ' style="visibility: hidden;"';
		this.objectSetup += '>\r\n';
		this.objectSetup += '<object ';
		this.objectSetup += 'id="'+this.id+'" ';
		this.objectSetup += 'classid="clsid:DF780F87-FF2B-4DF8-92D0-73DB16A1543A" ';
		this.objectSetup += 'codebase="'+this.loaderCab+'" ';
		this.objectSetup += 'width='+this.width+' ';
		this.objectSetup += 'height='+this.height+'>\r\n';
		for(i = 0; i < this.hosts.length; i++)
		{
			this.objectSetup += '<param name="host' + (i+1) + '" value="' + this.hosts[i] + '"/>\r\n';
			this.objectSetup += '<param name="hostsig' + (i+1) + '" value="' + this.signatures[i] + '"/>\r\n';
		}
		this.objectSetup += '<param name="hosts" value="' + this.hosts.length + '">\r\n';
		this.objectSetup += '<param name="gamename" value="'+this.gameDll+'">\r\n';
		this.objectSetup += '<param name="partnername" value="'+this.partnerName+'">\r\n';
		this.objectSetup += '<param name="displayname" value="'+this.displayName+'">\r\n';
		this.objectSetup += '<param name="gamecab" value="'+this.gameCab+'">\r\n';
		this.objectSetup += '<param name="logocab" value="'+this.logoCab+'">\r\n';
		this.objectSetup += this.getParams();
		this.objectSetup += '</object>\r\n';
		this.objectSetup += '</div>\r\n';
		this.objectSetup += '<script for="'+this.id+'" event="PopcapNotification(method,param)" language="JavaScript">\r\n';
		this.objectSetup += 'thePopCapGame.receiveNotification(method,param);\r\n';
		this.objectSetup += '</script>\r\n';
		this.objectSetup += '<![endif]-->\r\n';
		
		document.write(this.objectSetup);
		this.gameObject = document.getElementById(this.id);
	}
}

popCapAXGame.prototype.getParams = function()
{
    var tags = '';

	if (this.isInIE)
	{
		for(var i = 0; i < this.paramNames.length; i++)
		{
			if (this.params[i].toString().search(/\.cab/) == -1)
				tags += '<param name="'+this.paramNames[i]+'" value="'+this.params[i]+'">\r\n';
			else
				tags += '<param name="'+this.paramNames[i]+'" value="'+this.pathConcat(this.basePath, this.params[i])+'">\r\n';
		}
	}
	else
	{
		for(var i = 0; i < this.paramNames.length; i++)
		{
			if (this.params[i].toString().search(/\.cab/) == -1)
				tags += this.paramNames[i]+'="'+this.params[i]+'"\r\n';
			else
				tags += this.paramNames[i]+'="'+this.pathConcat(this.basePath, this.params[i])+'"\r\n';
		}
	}

    return tags;
}

popCapAXGame.prototype.sendNotification = function(method)
{
    this.gameObject.PopcapNotify(method,'');
}

popCapAXGame.prototype.reloadPlugin = function()
{
    navigator.plugins.refresh(true);
    window.location.href = window.location.href;
}

popCapAXGame.prototype.checkForPlugin  = function()
{
	try
	{
		var pluginType = 'application/x-popcaploader;version=1.0.0.1';
		mimetype = navigator.mimeTypes[pluginType];

		if (!(mimetype && mimetype.enabledPlugin && mimetype.type==pluginType))
		{
			document.write('<br>You need to get the PopCap Plugin to run this game.<br>');
			document.write('Get the PopCap Plugin <a href="'+this.plugin+'">here</a>!<br>');
			document.write('After installing the plugin, launch the game <a href="javascript:;" onclick="thePopCapGame.reloadPlugin()">here</a>!<br>');
			
			return false;
		}
		else return true;
	}
	catch (e) { }
}

popCapAXGame.prototype.OnGameBreak = function(params)
{
	this.levelCount++;
	if (Enable_Upsell && this.levelCount % Upsell_Ad_Frequency == 0)
		this.sendNotification('GameUpsell');
	else if (typeof(theAdSpot) != 'undefined')
		theAdSpot.display('GameBreak');
	else
		this.GameContinue();
}

/******************************************************************************
*     INSTANTIATE GAME
*******************************************************************************/

thePopCapGame = new popCapAXGame("Peggle",
	'GameObject',
	'540',
	'405',
	'peggle',
	'peggle_1_1.cab');

/******************************************************************************
*     GAME PARAMETERS
*******************************************************************************/

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'params';
thePopCapGame.params[thePopCapGame.params.length] = 'ShowUpsell,ExtrasURL0,ExtrasURL1,ExtrasURL2,focuspause,ZoneScript,updatecab';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'ShowUpsell';
thePopCapGame.params[thePopCapGame.params.length] = Enable_Upsell;

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'ExtrasURL0';
thePopCapGame.params[thePopCapGame.params.length] = 'pegextras0.cab';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'ExtrasURL1';
thePopCapGame.params[thePopCapGame.params.length] = 'pegextras1.cab';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'ExtrasURL2';
thePopCapGame.params[thePopCapGame.params.length] = 'pegextras2.cab';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'focuspause';
thePopCapGame.params[thePopCapGame.params.length] = 'true';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'ZoneScript';
thePopCapGame.params[thePopCapGame.params.length] = 'true';

thePopCapGame.paramNames[thePopCapGame.paramNames.length] = 'updatecab';
thePopCapGame.params[thePopCapGame.params.length] = 'peggle_1_1_update.cab';

/******************************************************************************
*     PARTNER-SPECIFIC SETTINGS
*******************************************************************************/

thePopCapGame.partnerName = 'ZooCorp';

thePopCapGame.basePath = Base_Path;
thePopCapGame.upsellUrl = Upsell_Url;
  
thePopCapGame.logoCab = Logo_Cab_Path;
thePopCapGame.loaderCab = IE_Plugin_Path;
thePopCapGame.plugin = FireFox_Plugin_Path;

/*---- PARTNER-SPECIFIC SETTINGS : DOMAIN HASHES ----*/

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.popcap.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = '0eCdKA26AKTR6RPBcEPH+v7fOaHqVtcBpHZ0dh3Cs/+qcGJujMGKzdvdUUhh+QV3hmywDtIrQxo17y/LEsV3o5yfLcqBTn2+uUZ+Ey9Iyccf5sr66qFdWUlOriaPmEhG/xqlbrsKGzRC43ahXARGWOSgbgkntJ0HMDL7CYwQrIs=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.jp.popcap.zoo.co.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = '2sn2pcCg5yTrfDgOsUg0ZEUu1aNqRkuBTOT7ApVLkYXnzOPDWC+Hv0sAb9N7m/mdMIGSWvsrCNWV0v8sOCVGxkMvZW+th3Xsyb4R/LPAscrMtwojx7nd6slFiAuw4zh5sXHRq+SOD9zC3WE/B4b1kxQSNUqGKxWLgGviDRQIXBw=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.dl.rakuten.co.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'LW1+q2vxjstwkGSj0byi9EfevwE6kFeGp/hrZsHAf44V164rcCHaVoJD290TpjMVkBKNElE6Wb+iYz5mAXmRqxjA989tixFGbNKoOgroOgv4w39HvQfNgtwNZTaRTCaXfcZ8ufZEEgQ4zEWfSWWjLr43p0hP9jXUb0ojC437rHM=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.sonet.vip.amisoft.net';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'ylPP5ana2AAHowppqIB6M4GPlS6xhGhXucqzvUaKb2OB1SGweCdYcgb0sEn7rNc3Wnq+T4IO2dnWTtAK5D95X2Zf960uzgb2dpMQcLdvYTGwJ+LUbjW/zqfcT7A8+k1/MdTjjv16csqDQjpfNiCebTXpc3A3g9abXhG4SfNcmZw=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.download.ips.co.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'SIvNzlnzoIvnWFYUdpQbHL4ZO5FoFJyU59fsDjHeGhu9Du6iHcUZyd5H26ip4xw7ZTxCjGOtif781tJ8kgfgeCUmtMn/1DuBYgX11/w8Jh7ibiBOSqt97VRUvpj92bwGR1P7dnRTHP789PoX7/4mDFOeaXtnLK/6Mfqn9sCkM2o=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.dl.amisoft.net';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'IVIuNA8uzH80hFMKhAKL+bKluWUUHyIOT1XCtoQ9N5CpQwLrUCCoKFHbpFSv0uLim+H/HsZCVLnNhPC7CtWJ+icrIK1yKgiwXOYs4mDLoM0ZrTzkqlaLrZlzQB0vTorBZrbSa6YUv0Np35FFjWnY6dWNSl/Yuk2miwJ8UGfNtpE=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.mydigi.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'pfuMdM8A6f9Z5cDMcQF9oIE1tSKZRjqUdSoGUGq84U/GMxox5yUpD4B60X3cB80K/kEiTF0bfYx5DHao6AjhUg//ERR1Mt9pKZcYot7jfzpOVQn0eEPoUhGXmiPSUalZqg1XhdKR2VGQSJa/vjIjfx2TALF0lUfJlDcwlty2Ogk=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.vector.co.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = '/qiaEQP85clk/d6z/heSufLQ5i/R5EvQfPCrlHspBwKV1xyJeoYuNX1sqrZ+NYjdea6Y2x00r+YWDDRan9VyZzTa69B/tSNE9xJQzf+DrRrrY5skuCUqZ/vFCfLUgsLZRwG9zZv/fxByXLvSSf4IMfvB09HUUfmpVjVFrOMtjiw=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.bbsoft.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'VVxAhg2gT0uNx7zC4yCqJHjwtbCxtdJqFIf/wj6wa9I51ZoW/PZ/moCQalsW1FNaySu9RdWnzXW2HebkdvP4snaRFHSw/5JQXUr/xog0AUi+BBxUb07jsFjFuK+GSNxjksShCmRR2X/iwQdOu3poTzH5dv4IuNhPA7Zn0LPdZVU=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.mubic.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'tYQLH2hgff2VemMjM/DpYirHN+ubkpJkFZKeT4GMByibc3se7V3+SNKh/OUmv08QD/npblb14OQ8zgTH+GLQ6jbxlT9fXQM/Uj4ZTqSXPgZOaL9MfUaBrNtaIMaExD0ZvuOewUKNs0aUl3xgRL4CNe5Z/mpyoiHsxYpi3mbyKcM=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.popcap.zoo.co.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'mPgIBN4ylo4e5QBZ1vLK/QRA0GAElRdMhj+hBARiUq/UutC4FriaKB3f8micCKjk1zeXTQdzC5j0diqtyK4U+JJs30wgD+GdDrlVtxejKCPRvnKsdipy9Qi9LqUFE1JfDryTSwsOrrXTSV43iNR8zSNSdKRZb7al0WWNbp1HMZY=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.gcrest.com';
thePopCapGame.signatures[thePopCapGame.signatures.length] = '+qs3hxf9ZRfcbFXKKbjuns9lXe+mIHRPiIkUzaChzkokpsJmWM6v4nwmTAAZ6vAgY8vn4IJNteoPwdfixVjsGxPNfAA7996ShoKrAaGMcgHy4EYzO0BKlrSUu+AQ+AQquUaB1VczE0+J0C079svCWdDvzkRXvsmux3I68JCD8yY=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.atgames.jp';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'UGvMeKrwcn+/U6oP29/g/5OlOxh1/3DdBLn3D6WOwSJMTml2oxf5aWhkEWgC3gwiaupr/00Jqwnvy+BSQL3u+qQ8LN2X/WlLyogBgZ/5SGcB4nih36QJx+J3jKv0EIyMKLQj1COBcgCkf5QNynah+K0LHG1mJTfIIXgIq5xQYK4=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.chobirich.com';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'g/wimaJBdh3nW5rDkdPtvVJBa6ylEPP17Eg0dq2IfCZIVIYyHBWwhehYAKR3S+4WRU+AgBsa/fnfTGj3xdo+k/tQINo9b2QzqJ3kZjt+DRoJe6s8VcODcuAyuYtvpjjGjsuNbYgR46yx9/jICiV4777WgKy3rBhp+OjSl9B7xEs=';

thePopCapGame.hosts[thePopCapGame.hosts.length] = '*.womenjapan.com';
thePopCapGame.signatures[thePopCapGame.signatures.length] = 'UWvdZgIU7Exif5nTO+PuuRlAlaazypnlfq1CtTalj/SuBdKkIz1uKKq40KeYYs6LvldQXAZghBjxguKVyT/8St2WDXMgJKNv6OED/u9jxI1aCRs9/6WPtFx349W5wWPrW9gaLejZ+RO8aZmQXCfh6HqsqfPmuiYHZezIHP2Nm0U=';

