				
	/**
	*	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,
				GMapLoaded:			false
			}, 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);
			}
			
		},
		
		open: function(url) {
			this.historyChange(url, url);
			if (!dhtmlHistory.isSafari)
				dhtmlHistory.add(url, url);
		},
		
		historyChange: function(newLocation, historyData) {
			$('CategoryLogoHere').innerHTML = '';
			
			switch(newLocation) {
				case 'Homepage':
					$('GoogleMap').hide();
					theHomeSlide.start();
					new Effect.Morph(theHomeSlide.holderDiv, {style:'opacity:1;'}); 
					this.call('TheContent', {CMD:'ShowContent', nid:newLocation});
					break;

				case 'DoveSiamo':
					theHomeSlide.stop();
					new Effect.Morph(theHomeSlide.holderDiv, {style:'opacity:0;'}); 
					$('GoogleMap').show();
					if (!this.options.GMapLoaded) { showmap(); this.options.GMapLoaded = true; }
					this.call('TheContent', {CMD:'ShowContent', nid:newLocation});
					break;
					
				default:
					$('GoogleMap').hide();
					theHomeSlide.stop();
					new Effect.Morph(theHomeSlide.holderDiv, {style:'opacity:0;'}); 
					this.call('TheContent', {CMD:'ShowContent', nid:newLocation});
					break;
			}
			$('FocusHere').focus();
			pageTracker._trackPageview('?nid='+newLocation);
		},
		
		showSpecificProduct: function(idSpecificProduct, imgN, UID) {
			this.call('PTitle_'+UID, {CMD:'ShowPTitle', idProdottoSpecifico:idSpecificProduct},{useLoader:false});
			this.call('PImage_'+UID, {CMD:'ShowPImage', idProdottoSpecifico:idSpecificProduct, imageNumber:imgN},{useLoader:false});
		},
		
		moveFrecciaPiccola: function(menuID, SfondoCategoria) {
			Position = this.findRealPosition($(menuID));
			new Effect.Morph('FrecciaPiccola', {style:'top:'+(Position['y']-26)+'px;', duration: 0.4});
			
			//if (menuID == 'm3304') {
				new Effect.Morph('HelpCatalogo', {style:'height:0px;margin-top:0px;', duration: 0.5});
			//} else {
				//new Effect.Morph('HelpCatalogo', {style:'height:71px;margin-top:-25px;', duration: 0.5});
			//}
			
			if (!!SfondoCategoria)
				$('SfondoCategoria').src = 'images/SfondiCategorie/'+SfondoCategoria+'.jpg';
			else 
				$('SfondoCategoria').src = 'images/SfondiCategorie/Default.jpg';
		},
		
		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="margin-top:100px;margin-left:320px;" />';
			}
			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');
		},
		
		findRealPosition: function(obj) {
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				curleft = obj.offsetLeft
				curtop = obj.offsetTop
				while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
				}
			}
			return {'x': curleft, 'y': curtop};
		}		
		
	}


	MOWSite = new MOWAJAXSiteSupport();


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

	////////////////////////////////////////////////////////////////////
	// 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;
		}