function ape_adapter(options)
{
	var ths=this;
	
	this.onready=options.onready;				// hivjuk, ha minden kesz ...
	this.onmessage=options.onmessage;
	this.client_name=options.client_name;		// = session_id()
	this.client = new APE.Client();	
	this.client.load({	
		'identifier': 'ape_1', /* ape alkalmazas id. lehet barmi, lehet tobb */
		'complete':
			function(){
				//alert(ths.client_name);
				/* kliens neve. egyedi legyen. alahuzas nem szabad bele, amiatt szoptam egesz delutan... */
				//d=new Date;
				//client_name="<?=session_id()?>";
				
				/* ha minden ok, mehet a ready(), ez akkor van, ha a start() sikerult ... */
				ths.client.addEvent('ready',ths.ready);
				/* feljelentkezunk a szerverre */
				if (ths.client.core.options.restore) {
					//Calling start(); without arguments will ask the APE Server for a user session
					ths.client.core.start();
				} 
				else {
					//It's not a session restoration, ask user for his name
					ths.client.core.start({'name': ths.client_name});
				}
			}
	});

	this.ready=function()
	{
		/* esemenykezelo, a bejovo uzenetekhez */
		ths.client.onRaw('postmsg', ths.onmessage);
		//this.client.addEvent('multiPipeCreate', this.multipipecreate);
		
		ths.client.core.join('main');

		/*
		if (client.core.options.restore) {
			//If it's a session restoration, ask the APE server for the custom session 'key1'
			client.core.getSession('key1', 
				function(resp) {
					//alert('Receiving sessions data. key1 value is : '+ resp.data.sessions.key1);
				}
			);
		} 
		else {
			//Saving custom session key1 one the server
			//alert('saving custom session data, key1 on the server');
			client.core.setSession({'key1':'value1'});
		}
		*/

		/* csatlakozunk a 'main' csatornahoz. erre a csat.-ra kuldi a php az uzeneteket. ha nem letezett eddig, akkor most majd jol letrejon */
		
		
		
					
		//alert(this.client_name);
		ths.onready();
	}

	
	/*
	function multipipecreate(pipe,options)
	{
		if(pipe.name=="main"){
			alert(options.users.length);
			pipe.addEvent('userJoin', userjoin);
			pipe.addEvent('userLeft', userleft);
		}
	}

	function userjoin(user, pipe)
	{
		alert("join: "+user.properties.name);
	}

	function userleft(user, pipe)
	{
		alert("left: "+user.properties.name);
	}
	*/

}
