Ponzi = {
	events: {
		fbInit: new CG.Event()
	}
};
Ponzi.events.fbInit.subscribe(function(){
	if(window.parent !== window)
	{
		try
		{
			FB_RequireFeatures(["CanvasUtil"], function()
			{
				//stop facebook from autosizing
				FB.CanvasClient.stopTimerToSizeToContent();
				//set the new height
				FB.CanvasClient.setCanvasHeight("1070px");
			});
		}
		catch(ex)
		{
			console.log(ex);
		}
	}
	
});

CG.options = jQuery.extend(CG && CG.options ? CG.options || {} : {}, {
	GameListManager: {
		gameList: {
			18: {link: 'http://apps.facebook.com/warstorm/?cgcode=4b83e891-78fc-4239-84d7-174345aef79c'}
		}
	},
	Game: { name: 'Ponzi, Inc.' }
});

jQuery(function() {
	var flashVersion = GetSwfVer().toString().split('.')[0];
	if( parseInt( flashVersion, 10 ) < 10 )
	{
		jQuery('#ponzi-container').css('display', 'none');
		jQuery('#fatal-error').css('display', 'none');
		jQuery('#no-flash').css('display', 'block');
	}

	var f = document.getElementById('EmbeddedFlashElement'), e = f.getElementsByTagName('embed')[0];

	if(f)
	{
		f.focus();
		CG.FacebookHelper.events.streamDialogClosed.subscribe(function() {
			if(f.FBStreamClosed)
			{
				f.FBStreamClosed();
			}
			else if(e.FBStreamClosed)
			{
				e.FBStreamClosed();
			}
		});
		
		CG.Commerce.events.close.subscribe(function() {
			if(f.updateCoins)
			{
				f.updateCoins();
			}
			else if(e.updateCoins)
			{
				e.updateCoins();
			}
		});
	}
		
});

var	showHelp = function() {
		var options = {
			srcType: 'iframe',
			top: 30,
			height: 620,
			width: 690
		},

		wrapper = jQuery('<div class="cg-modal-wrapper"></div>'),
		close = jQuery('<a href="#">Close Page</a>').click(function() {
			CG.Modal.closeAll();
		});

		modal = new CG.Modal('http://wiki.ponziinc.com/index.php/Ponzi', options);

		var container = jQuery(modal.getContainerElement()), iframe = container.find('iframe');
		container.append(close).append(wrapper.append('<div class="background"></div>').append(iframe));
	};

function showFatalError() {
		jQuery('#cg_top_box').css('display', 'none');
		jQuery('#cgbar').css('display', 'none');
		jQuery('#ponzi-container').css('display', 'none');
		jQuery('#no-flash').css('display', 'none');
		jQuery('#fatal-error').css('display', 'block');
};

function showTopBox() {
	jQuery('#cg_top_box').css('display', 'block');
}

function hideTopBox() {
	jQuery('#cg_top_box').css('display', 'none');
	CG.TopBox.events.cancelInit.fire();
}

function initTrialPay(filename, product_code, user_id) {
	jQuery.getScript(filename,
			function() { TRIALPAY.social.init_overlay('', user_id, {'p':product_code}); }
			);
}

