function ajaxLoader ( ) {
	this.meta = new Object;
	this.delegate;
	this.wait = 0;
	this.preprocess = 0;

	this.sendRequest = function(forced) {
//alert("sendRequest: " + this.meta.url);
//alert("sendRequest: " + this.meta.param);
		if ( forced || ( --this.wait == 0  ) )
			ajax (	this.meta.url, 
					this.meta.param, 
					this.ReceiveData.bind(this) );
	}
	
	this.ReceiveData = function( reply ) {
		var answer = eval ( "(" + reply + ")" );
		delete this.meta;
		this.meta = answer.meta;
//alert("ReceiveData: " + this.meta.url);
//alert("ReceiveData: " + this.meta.param);
		if ( this.preprocess ) {
			this.preprocess(answer.data,answer.meta);
		}
		if ( !this.meta.error ) {
			this.delegate.newData(answer.data,answer.meta);
		}
		if ( this.meta.call > 0 ) {
			window.setTimeout ( this.sendRequest.bind(this), 
							this.meta.call * 1000 );
			this.wait++;
		}
//alert("ReceiveData: " + this.meta.url);
//alert("ReceiveData: " + this.meta.param);
		delete answer;
		delete reply;
//alert("ReceiveData: " + this.meta.url);
//alert("ReceiveData: " + this.meta.param);
	}
}

ajaxLoader.prototype.initTracking = function( delegate ) {
	this.meta.url = "ajax/liveLocationsAllUsers.php";
	var activity = {stop:0,walk:1,bike:2,car:3,fly:4};
	this.meta.param = "id=0&from=0&activity=" + (arg.activity ? activity[arg.activity] : 0 );
	this.delegate = delegate;
}

ajaxLoader.prototype.initUseriFrameTracking = function( delegate, user, from ) {
	this.meta.url = "ajax/liveLocationsRequestedUsers.php";
	this.meta.param = "id=0&from=" + from + "&user=" + user;
	this.delegate = delegate;
}

ajaxLoader.prototype.preprocessGroupiFrameTracking = function(data,meta) {
	this.meta.call = 1;
	this.meta.param = "user=";
	var comma = "";
	var start_time = new Date();
	var end_time = new Date();
	for ( var i = 0; i < data.length; ++i ) {
		start_time.setUnixDate(data[i].start);
		end_time.setUnixDate(data[i].end);
		if ( start_time.getTime() > now() || end_time.getTime() < now() )
			continue;
		this.meta.param += comma + data[i].id;
		comma = ",";
	}
	delete start_time;
	delete end_time;
	this.preprocess = 0; // we're done
	this.meta.error = 1; // prevent further data processing
}

ajaxLoader.prototype.initGroupiFrameTracking = function( delegate, group, from ) {
	this.meta.url = "ajax/usersOfGroup.php";
	this.meta.param = "group=" + group;
	this.delegate = delegate;
	this.preprocess = this.preprocessGroupiFrameTracking;
	this.sendRequest(true);
}

ajaxLoader.prototype.initUserTracking = function( delegate, url, param ) {
	this.meta.url = url;
	this.meta.param = param;
	this.delegate = delegate;
}

ajaxLoader.prototype.initPlayback = function( delegate, url, param ) {
	this.meta.url = url;
	this.meta.param = param;
	this.delegate = delegate;
}

ajaxLoader.prototype.loadArray = function( delegate, url, param ) {
	this.meta.url = url;
	this.meta.param = param;
	this.delegate = delegate;
	this.sendRequest(true);
}

ajaxLoader.prototype.destruct = function() {
	delete this.meta;
}

