function ElusivePush(push_domain, uid, session_id, domain)
{
	
	
	this.receive = function(push_domain, uid, session_id, domain)
	{
		url = "http://"+push_domain+"/push.html?api=push&uid="+uid+"&session_id="+session_id+"&domain="+domain;
		
		window.frames['push_frame'].location.href = url;
	}
	
	
	
	this.receive(push_domain, uid, session_id, domain);
}


function ElusivePushReceiver(script, content_id, content_input, content_data)
{
	script = Base64.decode(script);
	content_id = content_id;
	content_input = content_input;
	content_data = Base64.decode(content_data);
	
	if (content_input == 'insert')
	{
		$(content_id).innerHTML += content_data;
	}
	else if (content_input == 'replace')
	{
		$(content_id).innerHTML = content_data;
	}
	
	
	window.setTimeout(script, 200);
}

function IframePush()
{
	this.receive = function ()
	{
		
		
		var myQuery = new QueryString();
		
		myQuery.read();
		
		window.domain = myQuery.get('domain');
		
		
		var url = 'api.php5?api=push&uid='+myQuery.get('uid')+'&session_id='+myQuery.get('session_id');
		// notice the use of a proxy to circumvent the Same Origin Policy.

		new Ajax.Request(url, {
  			method: 'get',
  			onSuccess: function(transport) {
  				try
  				{
	  				messages=transport.responseXML.getElementsByTagName("message");
			
					
					if (messages.length > 0)
					{
						message = messages[0];
						
						script = message.getElementsByTagName("script")[0].firstChild.nodeValue;
	  					content_id 	  = message.getElementsByTagName("content_id")[0].firstChild.nodeValue;
	  					content_input = message.getElementsByTagName("content_input")[0].firstChild.nodeValue;
	  					content_data  = message.getElementsByTagName("content_data")[0].firstChild.nodeValue;
	  					
	  					
	  					script = Base64.encode(script);
	  					content_id = content_id;
	  					content_input = content_input;
	  					content_data = Base64.encode(content_data);
	  					
	  					push_url = Base64.encode(window.location.href);
	  					
	  					url = 'http://'+window.domain+'/pushSend.html?script='+script+'&content_id='+content_id+'&content_input='+content_input+'&content_data='+content_data+'&push_url='+push_url;
	  				
	  					window.location.href = url;
					}
					else
						IframePush();
  				}
  				catch(e)
  				{
  					alert(e);
  				}		
   			}
		});
	}	
	
	this.receive();
}

function IframePushSend()
{
		
	var myQuery = new QueryString();
		
	myQuery.read();

	var push_url = Base64.decode(myQuery.get('push_url')); 

	parent.ElusivePushReceiver(myQuery.get('script'), myQuery.get('content_id'), myQuery.get('content_input'), myQuery.get('content_data'));

	window.location.href = push_url;
}
