function ContentLoader() {
	this.contentId = "main-content";
	this.formsResult = new Array();   // id del contenitore di ritorno del risultato di una form
	this.formsCallback = new Array(); // callback da chiamare per il risultato di ritorno
	this.preview = 1;
	
	this.loaderInit  = function () {
		this.setAjaxCalls(0); // su tutto il documento
	}
	
	this.images = {
		loader : '<li><img src="/immagini/loader.gif"></li>'
	};
	
	this.loadContent = function (href,name) {
		//alert("load content " + href + ":" + name);
		//if (this.preview)
		//	return this.loadPreview(href,id);
		//var obj = id?$('#'+id):$('#'+this.contentId);
		//obj.html(this.images.loader).load(href, {}, function(data) { }); 
		if (this.callbackExist(name)) {
			
			$.post(href, {}, function(data) { 
				loader.ajaxExecuted(name,data);
			});
		} else {
			$('#'+this.contentId).html(this.images.loader).load(href, {}, function(data) { }); 
		}
		
	}
	/*
	this.loadPreview = function (href,id) {
		
		$('#'+id).html(this.images.loader).load("/Uicms/previewRequest",{href:href}, function(data) { }); 
	}
	*/
	this.loadForm = function (form) {
		var method = $.get;
		if ( form.attr("method").toLowerCase() == "post") 
			method = $.post;
		
		method(form.attr("action"),form.serialize(), function(data) {
			loader.ajaxExecuted(name,data);
			/*
			if (loader.formsCallback[form.attr("name")])
				eval(loader.formsCallback[form.attr("name")]+"(data)");
			else if (loader.formsResult[form.attr("name")] && $('#'+loader.formsResult[form.attr("name")]))
				$('#'+loader.formsResult[form.attr("name")]).html(data);
			else if ($('#'+form.attr("name")+"_result")) 
				$('#'+form.attr("name")+"_result").html(data);
				*/
		});
		
	}
	
	// aggiornamento degli oggetti nel contenitore di id "id" se id 0 viene fatta sul tutto il documento
	this.setAjaxCalls = function (id) {
		// aggiunta automatica chiamate ajax nelle form
		var k = id?"#"+id + " form":"form";
		$(k).each(function(index) {
			var name = $(this).attr("name");
			
			if (name.indexOf("fx") >= 0) { 
				$(this).submit(function() {
					
					loader.loadForm($(this),name);
				  	return false;
				});
			}
		});
		
		// aggiunta automatica ajax per i link
		k = id?"#"+id + " a":"a";
		$(k).each(function(index) {
			var name = $(this).attr("name");
			if (name.indexOf("lx") >= 0) { 
				$(this).click(function() {
					
					loader.loadContent($(this).attr("href"),name);
				  	return false;
				});
			}
		});
	}
	// al ritorno della funzione ajax eseguo l'azione
	this.ajaxExecuted = function (name,data)  {
		
		/*
		try {
			eval("jQuery.isFunction("+name+"_callback)");
			eval(id+"_callback(data)");
		} catch (e) {
			//alert(e.message);
		}
		*/
		// controllo che non ci sia una callback
		if (this.callbackExist(name)) {
			eval(name+"_callback(data)");
		} else {
			// altrimenti scrivo il contenuto nel contenitore di default
			try {
				$('#'+this.contentId).html(data);
			} catch (e) {
				alert(e.message);
			}
		}
	}
	
	this.callbackExist = function (name) {
		try {
			eval("jQuery.isFunction("+name+"_callback)");
			return true;
		} catch (e) {}
		return false;
	}
}
