﻿//var api = {
//	
//	game : null,
//	chat : null,
//	
//	cleanUp : function () {
//		this.game.apiReceiveData( { cmd:"close" } );
//		this.game = null;
//		this.chat = null;
//	},
//	
//	toSite	:	function (data) {
//		 console.log("called receiveData");
//		 site.receiveData(data);
//		 
//		 },//alert(data); 
//	//toSite	:	function (data) { alert(data); },
//	toGame	:	function (data) { if (!this.game) return;
//	///this.game.receiveData = site.receiveData;
//	
//	//this.game.receiveData2(data);
//	this.game.apiReceiveData(data); this.game.receiveData(data); },//alert(data);
//	toChat	:	function (data) { if (!this.chat) return; this.chat.receiveData(data); }
//};
//
//// LEGACY
//// Backwards compatibility: The old games are looking for an object called
//// 'lobby', so this will route them through to the new API
//var lobby = {
//	sendMessageToParent	: api.toSite,
//	//sendMessageToParent	: function (data) { alert(data); },
//	sendMessageToChild	: api.toGame,
//	sendMessageToChat	: api.toChat,
//	
//	log: function(data){
//		console.log('log method');
//		console.log(data);
//		
//		}
//};
//
//function traceIt () 
//{
//	alert(lobby);
//	alert(lobby.sendMessageToParent);
//}

var api = {
	
	game : null,
	chat : null,
	
	cleanUp : function () {
		this.game.apiReceiveData( { cmd:"close" } );
		this.game = null;
		this.chat = null;
	},
	
	toSite : function (data) {
		site.receiveData(data); 
	},
	
	
	toGame : function (data) {
		if (!this.game) return; 
		this.game.apiReceiveData(data); 
		this.game.receiveData(data); 
		
		// NEW:
		//this.game.receiveDataNEW(data); 
	},
	
	
	toChat	:	function (data) { if (!this.chat) return; this.chat.receiveData(data); }
};

// LEGACY
// Backwards compatibility: The old games are looking for an object called
// 'lobby', so this will route them through to the new API
var lobby = {
	sendMessageToParent	: api.toSite,
	sendMessageToChild	: api.toGame,
	sendMessageToChat	: api.toChat,
	
	log: function(data)	
	{
		//console.log('log method');
		console.log(data);
	}
};
