/*depend on class Ajax*/
function BufferedLoader(url,callback)
{
	this._url=url;
	this._callback=callback;
}

BufferedLoader.prototype = {
	_msg:false,
	_exist:false,
	_resp:null,
	start_msg:function()
	{
		this._msg = true;
	},
	stop_msg:function()
	{
		this._msg = false;
	},
	msg:function(str)
	{
		if(this._msg)
			alert(str)
	},
	load:function()
	{
		if(!this._url)return;
		if(this._exist&&this._resp)
		{
			if(this._callback)
				this._callback(this._resp);
			else
				this.msg("No Callback is Assigned.!");
			return;
		}

		var url = this._url;
		url += (this._url.indexOf("?")>=0?"&":"?")+"refresh_time="+new Date().getTime();
		this.msg("URL:"+url);
		var this_obj = this;
		new Ajax.Request(url, 
		{
			response: "Object",
			onSuccess: Delegate.create(this, function(evt){
				this_obj.msg("we did it!");
				if(evt&&evt.response)
				{
					this_obj._exist = true;
					this_obj._resp = evt.response;
					this_obj.msg("before calling it(the callback)!");
					this_obj._callback(evt.response);
				}
			}),
			on404: function(evt){
				this_obj.msg("404 Err:["+this_obj._url+"]");
			}
		});
	},
	reload:function()
	{
		this.clear();
		this.load();
	},
	setCallback:function(callback)
	{
		this._callback = callback;
	},
	setURL:function(sURL)
	{
		this._url = sURL;
	},
	clear:function()
	{
		this._exist = false;
		this._resp = null;
	}
};
