ajax_queue = new Object();
ajax_queue.q = new Array();
ajax_queue.cur = null;

ajax_queue.add = function( a, pass_data, post_method )
{
	a.pass_data = pass_data;
	a.post_method = post_method;
	a.proper_callback = a.callback;
	a.callback = ajax_queue.item_processed;
	ajax_queue.q.push( a );
}

ajax_queue.process = function()
{
	if ( ajax_queue.q.length == 0 )
		return;
	
	ajax_queue.cur = ajax_queue.q.shift();
	ajax_queue.cur.update( ajax_queue.cur.pass_data, ajax_queue.cur.post_method );
}

ajax_queue.item_processed = function( response, code )
{
	if ( ajax_queue.cur.proper_callback )
	{
		ajax_queue.cur.proper_callback( response, code );
		ajax_queue.cur.callback = ajax_queue.cur.proper_callback;
	}
	
	ajax_queue.process();
}
