
var pennybank = (function () { 

	//var url = 'http://web.lan:5002';
	var url = 'http://www.pennybank.ru';
	
	return {
		
		sockets: {},
		
		widget: function(id, w, h) {
			
			var widget_url = url + '/widgets/' + w + 'x' + h;
			
			document.getElementById(id).style.width = w + 'px';
			document.getElementById(id).style.height = h + 'px';
			
			var $this = this;
			this.sockets[id] = new easyXDM.Socket({
				remote: widget_url,
				channel: id,
				container: id,
				
				onReady: function() {
					$this.resize(id, w, h);
				},
				
				onMessage: function(message, origin) {
					$this.resize(id, w, message);
				}
			});
		},

		resize: function(id, w, h) {
			//if(window.console) console.log('resize', id, w, h, document.getElementById('easyXDM_' + id + '_provider'));
			document.getElementById(id).style.width = w + 'px';
			document.getElementById(id).style.height = h + 'px';
			var iframe = document.getElementById('easyXDM_' + id + '_provider');
			iframe.style.width = w + 'px';
			iframe.style.height = h + 'px';
		}
	};
	
})();

