Utils = { initialized: false, server_url:'http://games.rawrgamer.com/crossdomain/', init: function() { if(!this.initialized) { this.initialized = true; this.comm = document.createElement('iframe'); this.comm.src = this.server_url; this.comm.name = "rg_comm"; this.comm.id = this.comm.name; this.comm.style.position = 'absolute'; this.comm.style.right = '-200px'; this.comm.style.bottom = '-200px'; this.comm.style.width = '1px'; this.comm.style.height = '1px'; this.addEventListener(this.comm,'load',function(){Utils.comm_loaded();}); document.body.appendChild(this.comm); this.destroyer = document.createElement('div'); this.destroyer.style.position = 'absolute'; this.destroyer.style.right = '0px'; this.destroyer.style.bottom = '0px'; this.destroyer.style.display = 'none'; document.body.appendChild(this.destroyer); this.enddiv = document.createElement('div'); this.enddiv.style.width = '0px'; this.enddiv.style.height = '0px'; document.body.appendChild(this.enddiv); this.addEventListener(window,'load',function(){ Utils.resize_to_content(); }); } }, addEventListener: function(obj,event,func) { if(obj.addEventListener) { obj.addEventListener(event,func,false); } else if (obj.attachEvent) { obj.attachEvent('on'+event,func); } else { obj['on'+event] = func; } }, call_method: function(method,params) { params['m'] = method; var query = []; for(var key in params) { query.push(encodeURIComponent(key)+'='+encodeURIComponent(params[key])); } var src = this.comm.src.match(/[^#]*/)[0]+ "#"+query.join('&'); //this.comm.src = src; var comm = window.frames[this.comm.name]; if(comm) { comm.location.href = src; } else { this.comm.src = src; } }, comm_loaded: function() { }, destroy_dom: function(dom) { this.destroyer.appendChild(dom); this.destroyer.innerHTML = ''; }, resize_to_content: function() { var new_size = Math.min(this.enddiv.offsetTop,4000); if(new_size != this.last_resize) { this.last_resize = new_size; Utils.call_method('resize_canvas',{ 'h':new_size+'px' }); } }, start_resize_timer: function() { if(!this.resize_timer) { this.resize_timer = setInterval(function(){Utils.resize_to_content()},1000); } }, stop_resize_timer: function() { if(this.resize_timer) { clearInterval(this.resize_timer); this.resize_timer = false; } }, request_dialog: function(request_text,action) { Utils.call_method('request_dialog',{ 'action':action }); }, signup_dialog: function(text,binding) { var params = { text:text }; if(binding) { params['binding'] = binding; } Utils.call_method('signup_dialog',params); }, scroll_to: function(x,y) { Utils.call_method('scroll_to',{ x:x, y:y }); } }