// XAJAX_LOADER_JS 
// @author: Jeremy Dill
// @requires jQuery
// @example : xajax.lcall('servUp', ["/hosts/add","hostbox","",{'mode':'add'}],{ap:this,offset:{offsetX:10,offsetY:0}}); 
// @ver: .4
/* ChangeLog:<br>
 *           - .4 revamped lcall
 *           - .3 added options for ap and offset (small loader)
 *           - .2 added custom call functions
 *           - .1 initial release
*/

/* CUSTOM LOADER */
// SETTINGS
var timeBeforeLoader=10000;
var timeBeforeGivingUp=10000;
var loadDivSelector=".loader";
var centerInSel="#header";


// MAKE LOADER
if(undefined==xajax) xajax={};
if(undefined!=xajax.callback){
	xajax.myLoader = xajax.callback.create(timeBeforeLoader, timeBeforeGivingUp);
	xajax.myLoader.onResponseDelay = function(oRequest) {
	if(oRequest.options.noloader) return false;
	if (oRequest.options.ap) $(loadDivSelector+"_sm").placeRight(oRequest.options.ap,oRequest.options.offset).fadeIn(200);
	else $(loadDivSelector).vCenter({maxTop:190}).fadeIn(200);};
	xajax.myLoader.beforeResponseProcessing  = function() {$(loadDivSelector+","+loadDivSelector+"_sm").fadeOut(300);};
	xajax.myLoader.onFailure= function() {$(loadDivSelector+","+loadDivSelector+"_sm").fadeOut(300);alert('Sorry, there was a problem.  Please try again later');xajax.wait=false;return false};
}

/* CUSTOM CALL FUNCTIONS */
// LCALL - CALL WITH LOADER
xajax.lcall=function(func,params,opt){
	if("undefined"==typeof(opt)) opt={};
	if("undefined"==typeof(params)) params=[];
	xajax.request( { xjxfun: func }, {parameters: params, callback: xajax.myLoader, options: opt});	
	if(opt.instant&&opt.ap) {
 		$(loadDivSelector+"_sm").placeRight(opt.ap,opt.offset).show();
	}
}

// SCALL - CALL WITH LOADER AND SESSION ID AS FIRST ITEM.
xajax.sessionid="";
xajax.scall=function(func,params,opt){
	if("undefined"==typeof(params)) params=[];
	if("undefined"==typeof(opt)) opt={};	
	params.unshift(xajax.sessionid);	
	xajax.request( { xjxfun: func }, {parameters: params, callback: xajax.myLoader, options: opt});
}

// LOAD UP XAJAX DYjNAMICALLY USING JQUERY
function dynLoadXajax(){ 
	jQuery.ajax({
	  type: "GET",
	  url: "/_common_php/xajax_setup.php",
	  dataType: "script"
	});
}