var apidoc = {
	
	sending : null,
	opts : {},
	
	init : function( opt )
		{
			opt = opt || {};
			this.opts = {
				serverURL : opt.serverURL,
				ajaxFunc : opt.ajaxFunc || apidoc.getPage
			}
			phpkod.plugins.ajaxUrl.serverUrl = this.opts.serverURL;
			phpkod.plugins.ajaxUrl.ajaxFunc = this.opts.ajaxFunc;
			phpkod.plugins.ajaxUrl.init();
			
			SyntaxHighlighter.all();
			
			$(function(){ apidoc.documentReady() });
			
		},
	
	documentReady : function()
		{
			phpkod.plugins.ajaxUrl.rewriteUrl();
		},
	
	getPage : function(url)
		{
			if(!url)
				return;
			$('#nav').animate({opacity:0.5}, 'fast');
			xajax_getp(url);
			if(apidoc.sending !== null)
				window.clearTimeout(apidoc.sending);
			apidoc.sending = window.setTimeout( "apidoc.timetrouble('"+url+"');", '3500' );
			return false;
		},
	
	setPage : function(o)
		{
			$('#nav').html(o);
			$('#nav').animate({opacity:1}, 'fast');
			phpkod.plugins.ajaxUrl.rewriteUrl();
			SyntaxHighlighter.highlight();
			if(apidoc.sending !== null)
				window.clearTimeout(apidoc.sending);
			apidoc.sending = null;
			$('body,html').animate({
				scrollTop: 0
			}, 500);
		},
	
	pageError : function(msg)
		{
			$('#nav').animate({opacity:1}, 'fast');
			alert(msg);
			if(apidoc.sending !== null)
				window.clearTimeout(apidoc.sending);
			apidoc.sending = null;
		},
	
	timetrouble : function(url)
		{
			if(apidoc.sending === null)
				return;
			alert('La documentation demandee ('+url+') ne semble pas repondre. Veuillez séléctionner un autre service.');
			$('#nav').animate({opacity:1}, 'fast');
			apidoc.sending = null;
		}
	
}
