				
	/**
	*	Classe per il supporto al funzionamento di un sito AJAX
	*/
	MOWAJAXSiteSupport = Class.create();
	MOWAJAXSiteSupport.prototype = {
		initialize: function() {
			this.options = Object.extend({
				loaderIcon:			'images/loader.gif',
				loaderSize:			100,
				useRSH:				true
			}, arguments[0] || {});
	
			// Associo al caricamento della pagina l'handler onWindowLoad della classe
			Event.observe(window, 'load', this.onWindowLoad.bindAsEventListener(this)); 
		},
		
		onWindowLoad: function() {
			if (this.options.useRSH) {
				// Sovrascrivo l'handler di RSH chiamato al cambiamento di link/pagina dovuto a back/forth (o accesso diretto con #...)
				dhtmlHistory.addListener(this.historyChange.bindAsEventListener(this));
				//historyChange = this.historyChange.bindAsEventListener(this);
			}
			
		},
		
		historyChange: function(newLocation, historyData) {
			if (!isNaN(newLocation)) {
				theSlide.stop();
				new Effect.Morph(theSlide.holderDiv, {style:'opacity:0;'});
				this.call('TheContent', {CMD:'ShowContent', nid:newLocation});
				this.call('LocationBar', {CMD:'ShowLocationBar', nid:newLocation}, {useLoader:false});
				this.call('SecondaryBar', {CMD:'ShowSecondaryBar', nid:newLocation}, {useLoader:false});
			}			
			if (newLocation == 'home' || newLocation == '') {
				theSlide.start();
				new Effect.Morph(theSlide.holderDiv, {style:'opacity:1;'});
				$('TheContent').innerHTML = '';
				$('LocationBar').innerHTML = 'home';
				$('SecondaryBar').innerHTML = '';
			}

		},
		
		call: function(Element) {
			var CallParameters = Object.extend({
				}, arguments[1] || {});
			
			var pars = Object.extend({
					loaderIcon:		this.options.loaderIcon,
					loaderSize:		this.options.loaderSize,
					useLoader:		true,
					replace:		false,
					evalJS:			true
				}, arguments[2] || {});
			
			if (Element && pars.useLoader) {
				$(Element).innerHTML = '<img src="'+pars.loaderIcon+'" style="position:absolute;top:50%;left:50%;margin-left:-'+Math.floor(pars.loaderSize/2)+'px;margin-top:-'+Math.floor(pars.loaderSize/2)+'px;" />';
			}
			if (Element && !$(Element).visible()) {
				new Effect.Appear(Element, {duration:0.5});
			}
				
			new Ajax.Request('_com.php', {
					method: 'post',
					parameters: CallParameters,
					evalJS:	pars.evalJS,
					onFailure: this.AjaxError.bindAsEventListener(this),
					onComplete: function(transport) {
						if (Element) {
							if (pars.replace) {
								$(Element).replace(transport.responseText);
							} else {
								$(Element).innerHTML = transport.responseText;
							}
							
							//if (pars.evalJS)
								transport.responseText.evalScripts();
						}
					}
				});
		},
		
		AjaxError: function(transport) {
			alert('E\' avvenuto un errore di comunicazione AJAX');
		}
		
	}


	MOWSite = new MOWAJAXSiteSupport();
	
	Event.observe(window, 'load', function() {
			dhtmlHistory.initialize();
			if (dhtmlHistory.isFirstLoad()) {
				//dhtmlHistory.add('<?= $firstPage; ?>', '<?= $firstPage; ?>');
			}
		});

	//historyChange: function(newLocation, historyData) {
	//	alert(newLocation);
	//	MOWSite.historyChange(newLocation, historyData);
	//}






	////////////////////////////////////////////////////////////////////
	// Editing inline dei contenuti

		currentEditingID = 0;
		currentEditingType = '';
		currentEditingField = '';
		currentEditingDivID = 0;
		openContentEditor = function(contentType, contentField, contentID, divID) {
			if (currentEditingID != 0) {
				alert("E' possibile editare un articolo alla volta");
				return;
			}
			currentEditingType = contentType;
			currentEditingField = contentField;
			currentEditingID = contentID;
			currentEditingDivID = divID;
		
			$(divID).parentNode.absolutize();
			$(divID).absolutize();
			
			// Allunga l'editor se non c'è spazio..
			//if ($(divID).getStyle('height').substr(0,$(divID).getStyle('height').length-2) < 400)
				$(divID).setStyle({height:'600px'});
			
			new Ajax.Request('includes/_getContent.php', {
					method: 'post',
					parameters: { 'contentType':currentEditingType, 'contentField':currentEditingField, 'contentID': currentEditingID },
					onSuccess: function(transport) {
						FCKCreate(divID, 'editor1', transport.responseText, saveContentEditing);
					}
				});		
		}
		
		
		saveContentEditing = function() {
			new Ajax.Request('includes/_commitContent.php', {
					method: 'post',
					parameters: { 'contentType':currentEditingType, 'contentField':currentEditingField, 'contentID': currentEditingID, 'editing': FCKGetContents('editor1', false) },
					onSuccess: function(transport) {
						$(currentEditingDivID).innerHTML = FCKGetContents('editor1', false);
						currentEditingID = 0;
						currentEditingField = '';
						currentEditingType = '';
						currentEditingDivID = 0;
					}
				});
			return false;
		}
