document.observe('dom:loaded', init);
Event.observe(window, 'load', initPngFix);
document.observe('click', manageEventClick);

var url = pathHttp + 'web_services.php';

var arrayCanaliTematici = new Array();

function init()
{	
	//carico le bandiere di secondo tipo per l'effetto rollover nell'header
	picIta = new Image(35, 24); 
	picIta.src = pathHttp + "immagini/ita_f2.png";
	picEng = new Image(35, 24); 
	picEng.src = pathHttp + "immagini/eng_f2.png"; 
	picFra = new Image(35, 24); 
	picFra.src = pathHttp + "immagini/fra_f2.png"; 
	picDeu = new Image(35, 24); 
	picDeu.src = pathHttp + "immagini/deu_f2.png";
	
	//inizializzazione cufon
	if(navigator.userAgent.indexOf('MSIE 6.0') == -1)
	{
		Cufon.replace('h1')('h3')('h4')('h5')('h6')('div.first')('div.filettoLeft')('div.testoOffertaNonValida p');
	}
	
	var flagArray = $$('#header .second a img');
	flagArray.each(function(flag) { flag.observe('mouseover', manageEventMouseover); });
	
	//caricamento del blink top homepage
	if($('blinker'))
	{
		window.blinker = new blink('blinker', 1000);
		blinker.start();
	}
	
	//caricamento dello slider immagini top (protofade)
	if($('protofade'))
	{
		new Protofade('protofade', { randomize: true, 
					  				 duration: 2.0									
								   });	
	}
	
	//inizializzazione della paginazione elenco offerte singolo canale tematico
	if($('containerOfferteCanaleTematico'))
	{
		var moveListOfferteCanaleTematico = new Move('containerOfferteCanaleTematico', 'batchOfferteCanaleTematico', 'offertaCanaleTematico', 'paginazioneOfferte', 8, 'Offerte');		
	}
	
	//inizializzazione della paginazione elenco eventi singolo canale tematico
	if($('containerEventiCanaleTematico'))
	{
		var moveListEventiCanaleTematico = new Move('containerEventiCanaleTematico', 'batchEventiCanaleTematico', 'evento', 'paginazioneEventi', 4, 'Eventi');		
	}
	
	//inizializzazione della paginazione elenco hotel e caricamento mappa
	if($('containerElencoHotel'))
	{
		var moveList = new Move('containerElencoHotel', 'batchElencoHotel', 'hotel', 'paginazioneHotel', 8, '');
		var selezionaHotel = new SelezionaHotel('form_filtro_hotel', 'containerElencoHotel', 'googlemapLarge', moveList);
	}
	
	if($('containerElencoHotelNoHotel'))
	{
		showPoint();	
	}
	
	//inizializzazione della paginazione elenco eventi pagina eventi
	if($('containerEventi'))
	{
		var moveListEventi = new Move('containerEventi', 'batchEventi', 'eventoLarge', 'paginazione', 14, '');		
	}
	
	//caricamento mappa piccola scheda hotel
	if($('smallPosizioneHotel'))
	{
		var latitude;
		var longitude;
		if($$('#smallPosizioneHotel .latitude')[0])
		{
			latitude = parseFloat($$('#smallPosizioneHotel .latitude')[0].innerHTML);
		}
		if($$('#smallPosizioneHotel .longitude')[0])
		{
			longitude = parseFloat($$('#smallPosizioneHotel .longitude')[0].innerHTML);
		}
		var icona = $$('#smallPosizioneHotel .icon')[0].innerHTML;
		
		if(undefined !== latitude && undefined !== longitude)
		{
			showPointHotel(latitude, longitude, icona);
		}
		else
		{
			if($$('#smallPosizioneHotel .address')[0])
			{
				var address = $$('#smallPosizioneHotel .address')[0].innerHTML;
			}
			showPointAddressHotel(address, icona);
		}
	}
	
	//caricamento opzioni custom highslide per gallery scheda hotel
	if($('schedaHotelImageContainerLeft'))
	{
		hs.align = 'center';
		hs.transitions = ['expand', 'crossfade'];
		hs.outlineType = 'rounded-white';
		hs.fadeInOut = true;
		hs.addSlideshow({
							slideshowGroup: 'group1',
							interval: 5000,
							repeat: false,
							useControls: true,
							fixedControls: 'fit',
							overlayOptions: {
												opacity: .75,
												position: 'bottom center',
												hideOnMouseOut: true
											}
						});	
	}
	
	//caricamento evento focus sulle textarea di invio delle mail preventivo
	if($('note_e_richieste'))
		$('note_e_richieste').observe('focus', manageEventFocus);
}

function initPngFix()
{
	if(navigator.userAgent.indexOf('MSIE 6.0') != -1)
	{
		pngfix();	
	}	
}

//funzione che gestisce gli eventi di click del mouse
function manageEventClick(evt)
{
	var element = Event.element(evt);
	switch(element.tagName.toLowerCase())
	{
		case 'a':
			if(element.id == 'linkBoxTelefono')
			{
				Event.stop(evt);
				
				var params = new Hash();
				params.set('action', 'update_statistiche_telefono');
				params.set('id_attivita', element.rel);
				params.set('id_canale_tematico', element.rev);
				new Ajax.Request(url, {
										method: 'post',
										contentType: 'application/x-www-form-urlencoded',
										parameters: params,
										onSuccess: function(transport) { 
																		 element.ancestors()[0].style.fontSize = '12px';
																		 element.ancestors()[0].update(transport.responseText);
																	   }
										});
			}
			else if(element.id == 'linkBoxOpenFormContatti')
			{
				Event.stop(evt);
				
				Effect.toggle('containerFormContatti', 'blind', { duration: 3.0 }); 
			}
			else if(element.id == 'linkBoxListinoPrezzi')
			{
				Event.stop(evt);
				
				Effect.toggle('containerListinoPrezzi', 'blind', { duration: 5.0 }); 
			}
			else if(element.id == 'linkContattiTelefonici')
			{
				Event.stop(evt);
				
				var jsel = document.createElement('SCRIPT');
				jsel.type = 'text/javascript';
				jsel.src = 'http://admin.abc.sm/scripts/count_click_view_telefono.php?id_attivita=' + element.rel + '&id_portale=2349';
				window.document.body.appendChild (jsel);
				
				if(!$('contattiTelefonici').visible())
				{
					$('spanContattiTelefonici').hide();
					$('linkContattiTelefonici').hide();	
					Effect.BlindDown('contattiTelefonici');	
				}
			}
			else if(element.id == 'linkIndietro')
			{
				history.back(1);	
			}
			else if(element.hasClassName('openerCanaleTematico'))
			{
				Event.stop(evt);
								
				var idCanaleTematico = 'canaleTematico' + element.rel;
				var idOpenerCanaleTematico = 'openerCanaleTematico' + element.rel;
				
				$(idOpenerCanaleTematico).toggleClassName('bgApri');
				$(idOpenerCanaleTematico).toggleClassName('bgChiudi');
				
				if(!$(idCanaleTematico).visible())
				{
					$$('#' + idOpenerCanaleTematico + ' .apri')[0].hide();
					$$('#' + idOpenerCanaleTematico + ' .chiudi')[0].show();
				}
				else
				{
					$$('#' + idOpenerCanaleTematico + ' .apri')[0].show();
					$$('#' + idOpenerCanaleTematico + ' .chiudi')[0].hide();
				}
				
				Effect.toggle(idCanaleTematico, 'blind');
			}
			else if(element.hasClassName('linkJavascript'))
			{
				Event.stop(evt);
			
				location.href = pathHttp + element.rel;
			}
		break;
		
		case 'span':
			if((element.hasClassName('apri') || element.hasClassName('chiudi')) && (element.ancestors()[0].hasClassName('openerCanaleTematico')))
			{
				Event.stop(evt);
				
				elementParent = element.ancestors()[0];
				
				var idCanaleTematico = 'canaleTematico' + elementParent.rel;
				var idOpenerCanaleTematico = 'openerCanaleTematico' + elementParent.rel;
				
				$(idOpenerCanaleTematico).toggleClassName('bgApri');
				$(idOpenerCanaleTematico).toggleClassName('bgChiudi');
				
				if(!$(idCanaleTematico).visible())
				{
					$$('#' + idOpenerCanaleTematico + ' .apri')[0].hide();
					$$('#' + idOpenerCanaleTematico + ' .chiudi')[0].show();
				}
				else
				{
					$$('#' + idOpenerCanaleTematico + ' .apri')[0].show();
					$$('#' + idOpenerCanaleTematico + ' .chiudi')[0].hide();
				}
				
				Effect.toggle(idCanaleTematico, 'blind');
			}
			else if((element.hasClassName('apri') || element.hasClassName('chiudi')) && (element.ancestors()[0].id == 'openerMappaElencoHotel'))
			{
				Event.stop(evt);
				
				if(!$('containerGooglemapLarge').visible())
				{
					$$('#openerMappaElencoHotel .apri')[0].hide();
					$$('#openerMappaElencoHotel .chiudi')[0].show();
				}
				else
				{
					$$('#openerMappaElencoHotel .apri')[0].show();
					$$('#openerMappaElencoHotel .chiudi')[0].hide();
				}
				
				Effect.toggle('containerGooglemapLarge', 'slide', { duration: 3.0 }); 
			}			
		break;
		
		case 'img':
			if(element.id == 'ricercaAvanzataDataStart')
			{
				displayCalendar($('ricercaAvanzataDataStart'), 'dd/mm/yyyy', element);
			}
			else if(element.id == 'ricercaAvanzataDataEnd')
			{
				displayCalendar($('ricercaAvanzataDataEnd'), 'dd/mm/yyyy', element);
			}
		break;
		
		case 'button':
			if(element.id == 'buttonRicercaAvanzata')
			{
				Event.stop(evt);
				
				submitFormRicercaAvanzata();
			}
		break;
	}
}

//funzione che gestisce gli eventi di mouseover sulle bandiere
function manageEventMouseover(evt)
{
	var element = Event.element(evt);
	
	element.stopObserving('mouseover', manageEventMouseover);
	
	var newSrc = pathHttp + 'immagini/' + element.id + '_f2.png';
	element.src = newSrc;
	if(navigator.userAgent.indexOf('MSIE 6.0') != -1)
	{
		element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newSrc + "',sizingMethod='crop')";
		element.src = clear;
	}
	
	new Effect.Move(element, { x: 0, 
							   y: -16, 
							   mode: 'relative',
							   transition: Effect.Transitions.sinoidal,
							   duration: 0.2,
							   queue: { position: 'front', 
										scope: 'menuFlag' + element.id + 'Scope' }
							 });
							
	new Effect.Move(element, { x: 0, 
							   y: 16, 
							   mode: 'relative', 
							   transition: Effect.Transitions.sinoidal,
							   duration: 0.5,
							   queue: { position: 'end', 
										scope: 'menuFlag' + element.id + 'Scope' },
							   afterFinish: function(obj) { 
							   								var newSrc = pathHttp + 'immagini/' + obj.element.id + '.png';
							   								obj.element.src = newSrc;
															if(navigator.userAgent.indexOf('MSIE 6.0') != -1)
															{
																obj.element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newSrc + "',sizingMethod='crop')";
																obj.element.src = clear;	
															}
															obj.element.observe('mouseover', manageEventMouseover); 
														  }
							 });
}

function manageEventFocus(evt)
{
	var element = Event.element(evt);
	
	if(element.hasClassName('default'))
	{
		element.removeClassName('default');
		Form.Element.clear(element);
	}
}

//invio form prenota online
function submitFormRicercaAvanzata()
{
	var form = $('form_ricerca_avanzata');
	
	if($F('canali_tematici') != '')
	{
		form.submit();	
	}
	else
	{
		alert($F('errore_canali_tematici'));	
	}
}

//preview dei video nella scheda hotel
function createDarkLayer()
{	
	var opacity = 60;
	var opaque = (opacity / 100);
	
	darkLayer = document.createElement("div");
	darkLayer.setAttribute("id", "darkLayer");
	darkLayer.style.position = "absolute";
	darkLayer.style.left = "0px";
	darkLayer.style.top = "0px";
	darkLayer.style.zIndex = "50";
	darkLayer.style.width = "100%";
	darkLayer.style.height = "" + ((document.height !== undefined) ? document.height : document.body.offsetHeight) + "px";	//"100%";
	darkLayer.style.backgroundColor = "#000000";
	darkLayer.style.opacity = opaque;                      
	darkLayer.style.MozOpacity = opaque;                   
	darkLayer.style.filter = 'alpha(opacity=' + opacity + ')'; 
	window.document.body.appendChild(darkLayer);
}

function destroyDarkLayer()
{
	$("darkLayer").remove();
}
	
function previewVideo(codice, descrizione, chiudi)
{	
	createDarkLayer();
	
	divElement = document.createElement("div");
	divElement.setAttribute("id", "div_preview_content");
	divElement.style.height = '800px';
	divElement.style.zIndex = '100';
	divElement.style.top = '0px';
	divElement.style.position = 'absolute';
	divElement.style.textAlign = 'center';
	
	divElementContent = '<table align="center" cellpadding="1" cellspacing="0" border="0">' + 
						'<tr>' + 
						'<td bgcolor="#FFFFFF" align="left" style="padding: 6px"><b>' + descrizione + '</b></td>' + 
						'<td bgcolor="#FFFFFF" align="right" style="padding: 6px"><a href="#chiudi" onclick="destroyDarkLayer(); destroyPreviewVideo(); return false;">' + chiudi + '</a></td>' + 
						'</tr>' + 
						'<tr><td bgcolor="#FFFFFF" colspan="2">' +
						'<object width="410" height="344" style="z-index:2000">' + 
						'<param name="movie" value="http://www.youtube.com/v/' + codice + '&hl=it&fs=1&rel=0&autoplay=1"></param>' + 
						'<param name="allowFullScreen" value="true"></param>' + 
						'<embed src="http://www.youtube.com/v/' + codice + '&hl=it&fs=1&rel=0&autoplay=1&fmt=6" style="z-index:2000" type="application/x-shockwave-flash" allowfullscreen="true" width="410" height="344"></embed>' + 
						'</object></td></tr>' + 
						'</table>';
	divElement.innerHTML = divElementContent;
	
	var windowWidth = 0;
	var windowHeight = 0;
	
	if(typeof( window.innerWidth ) == 'number' ) 
	{
    	//Non-IE
    	windowWidth = window.innerWidth;
    	windowHeight = window.innerHeight;
  	} 
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
	{
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
  	} 
	else if(document.body && (document.body.clientWidth || document.body.clientHeight )) 
	{
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
  	}
	
	var scrollOffsetY = 0;
	
	if(typeof(window.pageYOffset) == 'number') 
	{
    	//Netscape compliant
    	scrollOffsetY = window.pageYOffset;
	} 
	else if(document.body && document.body.scrollTop)
	{
    	//DOM compliant
    	scrollOffsetY = document.body.scrollTop;
	} 
	else if(document.documentElement && document.documentElement.scrollTop)
	{
    	//IE6 standards compliant mode
    	scrollOffsetY = document.documentElement.scrollTop;
  	}
	
	divElement.style.left = (Math.floor(windowWidth / 2) - 50) + 'px';
	divElement.style.top = (scrollOffsetY + 150) + 'px';
	
	window.document.body.appendChild(divElement);
}

function destroyPreviewVideo()
{
	$("div_preview_content").remove();	
}
//fine preview dei video nella scheda hotel

//carica in un select l'insieme delle categorie degli hotel per ogni località nella ricerca avanzata
function selectCategoria(element)
{
	var idFrazione = element.options[element.selectedIndex].value;
	
	var params = new Hash();
	params.set('action', 'get_elenco_categorie_hotel');	
	params.set('lang', lang);
	params.set('id_frazione', idFrazione);
	new Ajax.Request(url, {
							 method: 'post', 
							 contentType: 'application/x-www-form-urlencoded', 
							 parameters: params, 
							 onSuccess: function(transport) {
																$('ricercaCategoriaHotel').update(transport.responseText);
															}
						  });
}

//carica in un select l'insieme dei canali tematici che dipendono da un macrogruppo
function selectCanaleTematico(element)
{
	var idMacrogruppo = element.options[element.selectedIndex].value;
	if(idMacrogruppo == '')
	{
		$('ricercaCanaleTematico').update('<options value="">- -</options>');
	}
	else
	{
		var params = new Hash();
		params.set('action', 'get_elenco_canali_tematici');	
		params.set('lang', lang);
		params.set('id_macrogruppo', idMacrogruppo);
		new Ajax.Request(url, {
								 method: 'post', 
								 contentType: 'application/x-www-form-urlencoded', 
								 parameters: params, 
								 onSuccess: function(transport) {
																	$('ricercaCanaleTematico').update(transport.responseText);
															    }
							  });
	}
}

//carica un'area tematica in un elenco di aree tematiche correlate alla ricerca
function updateCanaliTematici(element)
{
	var selector = element.options[element.selectedIndex];
	
	if(selector.value != '' && selector.value != '0')
	{
		var idCanaleTematico = selector.value;
		var textCanaleTematico = selector.innerHTML;	

		if(undefined === arrayCanaliTematici.detect(function(n) {return n == idCanaleTematico; }))
		{
			$('blinkerAggiuntaCanaleTematico').show();
			new Effect.Pulsate('blinkerAggiuntaCanaleTematico', { pulses: 3,
							   									  duration: 1.5, 
																  queue: { position: 'front', 
																		   scope: 'blinker' }
							   									});
			new Effect.Fade('blinkerAggiuntaCanaleTematico', { duration: 1.5, 
															   queue: { position: 'end', 
																	    scope: 'blinker' }
							   									});				
			
			var idDiv = 'canale_tematico_' + idCanaleTematico;
			var idImg = 'immagine_' + idCanaleTematico;
			
			var div = document.createElement('div');
			div.id = idDiv;
			div.className = 'buttonElimina';
			$('containerCanaliSelezionati').insert({ bottom: div });
			
			var img = document.createElement('img');
			img.id = idImg;
			img.src = pathHttp + 'immagini/button_elimina.jpg';
			img.alt = $('title_canali_tematici').value;
			img.title = $('title_canali_tematici').value;
			$(idDiv).insert({ top: img });
			
			$(idImg).observe('click', deleteCanaleTematico);
			$(idImg).observe('mouseover', function() { $(idImg).src = pathHttp + 'immagini/button_elimina_hover.jpg'; });
			$(idImg).observe('mouseout', function() { $(idImg).src = pathHttp + 'immagini/button_elimina.jpg'; });
	
			$(idDiv).insert({ bottom: textCanaleTematico });
			
			arrayCanaliTematici.push(idCanaleTematico);
			$('canali_tematici').value = arrayCanaliTematici.join(',');
		}
	}
}

//elimina un'area tematica da un elenco di aree tematiche correlate alla ricerca
function deleteCanaleTematico(evt)
{
	var element = Event.element(evt);
	
	element.stopObserving('click');
	element.stopObserving('mouseover');
	element.stopObserving('mouseout');
	
	var regExp = /immagine_([0-9]*)/;
	var idCanaleTematico = element.id.match(regExp)[1];
	
	$('canale_tematico_' + idCanaleTematico).remove();
	
	arrayCanaliTematici = arrayCanaliTematici.without(idCanaleTematico);
	$('canali_tematici').value = arrayCanaliTematici.join(',');
}

//conto alla rovescia per la pagina 404
function countredirect()
{
	if(currentsecond != 1)
	{
		currentsecond -= 1;
		document.redirect.redirect2.value = currentsecond;
	}
	else
	{
		window.location = targetURL;
		return;
	}
	
	setTimeout("countredirect()", 1000);
}

//classe da utilizzare per filtrare gli hotel
var SelezionaHotel = Class.create({
									initialize: function(form, containerElenco, containerMappa, mover) {
																	this.form = $(form);
																	this.containerElenco = $(containerElenco);
																	this.containerMappa = $(containerMappa);
																	
																	this.map;
																	this.bounds;
																	this.numGeocoded = 0;
																	this.arrayDataAddress = new Array();
																	this.markerArray = new Array();
																	
																	if(this.form)
																		Event.observe(this.form, 'submit', this.handleFormSubmit.bind(this));
																	
																	this.moveList = mover;
																	
																	this.baseIconSmall = new GIcon();
																	this.baseIconSmall.shadow = pathHttp + "immagini/shadow_small.png";
																	this.baseIconSmall.iconSize = new GSize(28, 35);
																	this.baseIconSmall.shadowSize = new GSize(40, 35);
																	this.baseIconSmall.iconAnchor = new GPoint(14, 32);
																	this.baseIconSmall.infoWindowAnchor = new GPoint(14, 0);
																	this.baseIconSmall.infoShadowAnchor = new GPoint(14, 0);
																	
																	this.baseIconLarge = new GIcon();
																	this.baseIconLarge.shadow = pathHttp + "immagini/shadow_large.png";
																	this.baseIconLarge.iconSize = new GSize(49, 55);
																	this.baseIconLarge.shadowSize = new GSize(60, 57);
																	this.baseIconLarge.iconAnchor = new GPoint(24, 55);
																	this.baseIconLarge.infoWindowAnchor = new GPoint(23, 0);
																	this.baseIconLarge.infoShadowAnchor = new GPoint(23, 0);	
	
																	//precaricamento immagini
																	pic1 = new Image(28, 35); 
																	pic1.src = pathHttp + "immagini/icona_1_stelle.png"; 
																	pic2 = new Image(28, 35); 
																	pic2.src = pathHttp + "immagini/icona_2_stelle.png"; 
																	pic3 = new Image(28, 35); 
																	pic3.src = pathHttp + "immagini/icona_3_stelle.png";   
																	pic4 = new Image(28, 35); 
																	pic4.src = pathHttp + "immagini/icona_4_stelle.png";  
																	pic5 = new Image(28, 35); 
																	pic5.src = pathHttp + "immagini/icona_5_stelle.png"; 
																	pic6 = new Image(28, 35); 
																	pic6.src = pathHttp + "immagini/icona_6_stelle.png"; 
																	pic7 = new Image(28, 35); 
																	pic7.src = pathHttp + "immagini/icona_residence.png"; 
																	pic8 = new Image(28, 35); 
																	pic8.src = pathHttp + "immagini/icona_bed_breakfast.png";
																	pic9 = new Image(49, 55); 
																	pic9.src = pathHttp + "immagini/icona_ente_fiera.png";
																	//fine precaricamento immagini
																	
																	this.icona1Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_1_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.icona2Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_2_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.icona3Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_3_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.icona4Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_4_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.icona5Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_5_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.icona6Stelle = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_6_stelle.png", null, pathHttp + "immagini/shadow_small.png");
																	this.iconaResidence = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_residence.png", null, pathHttp + "immagini/shadow_small.png");
																	this.iconaBedBreakfast = new GIcon(this.baseIconSmall, pathHttp + "immagini/icona_bed_breakfast.png", null, pathHttp + "immagini/shadow_small.png");
															   		this.iconaEnteFiera = new GIcon(this.baseIconLarge, pathHttp + "immagini/icona_ente_fiera.png", null, pathHttp + "immagini/shadow_large.png");
															   		
																	this.showMapPosizioneMappa();
																	
																	this.updateHotelMappa();
															   },
															   
									handleFormSubmit: function(evt) {
																		Event.stop(evt);
																		
																		this.loadingImage();
																		this.form.request({ 
																							evalJSON: true,
																							onSuccess: this.handleResponse.bind(this) 
																						  });
																  },
																  
									handleResponse: function(transport) {
																			this.containerElenco.update(transport.responseJSON[0]);
																			if(navigator.userAgent.indexOf('MSIE 6.0') != -1)
																			{
																				pngfix();	
																			}

																			this.moveList.pagerDiv.update(transport.responseJSON[1]);
																			this.moveList.reset();
																			this.updateHotelMappa();
																	    },
									
									showMapPosizioneMappa: function() {
																				var dimensions = {width: 726, height: 300};
																				var latitude = $('latitudine').innerHTML;
																				var longitude = $('longitudine').innerHTML;
																				var point = new GLatLng(latitude, longitude);
																				
																				this.map = new GMap2(this.containerMappa, { size: new GSize(dimensions.width, dimensions.height) } );
																				this.map.setMapType(G_NORMAL_MAP);
																				this.map.addControl(new GLargeMapControl3D());
																				this.map.setCenter(point, 18);
																				this.bounds = this.map.getBounds();
																		  },
																		  
									updateHotelMappa: function()  {
																	this.removeInfoWindow();
																	
																	var arrayData = this.containerElenco.getElementsBySelector('.mapData');
																	for(i = 0; i < arrayData.size(); i++)
																	{ 
																		var latitude = arrayData[i].getElementsBySelector('.latitude')[0].innerHTML;
																		var longitude = arrayData[i].getElementsBySelector('.longitude')[0].innerHTML;
																		var address = arrayData[i].getElementsBySelector('.address')[0].innerHTML;
																		var icon = arrayData[i].getElementsBySelector('.icon')[0].innerHTML;
																		var details = arrayData[i].getElementsBySelector('.details')[0].innerHTML;
																		
																		this.arrayDataAddress.clear();
																		if(latitude != '' && longitude != '')
																		{
																			this.showPoint(latitude, longitude, icon, details, 0);
																		}
																		else
																		{
																			this.arrayDataAddress.push(arrayData[i]);
																		}
																	}
																	
																	this.geocodeAll();
																  },
																  
									showPoint: function(latitudine, longitudine, icona, testo, infoOpen) 
									{
										var point = new GLatLng(latitudine, longitudine);
										markerOptions = { icon: eval(icona) };
										var marker = new GMarker(point, markerOptions);
										this.markerArray.push(marker);
										
										if(infoOpen)
										{
											this.map.addOverlay(marker); 
											marker.openInfoWindowHtml(testo);
											if(this.bounds)
											{
												this.bounds.extend(point);
												var zoom = this.map.getBoundsZoomLevel(this.bounds); 
												var center = this.bounds.getCenter(); 
												this.map.setCenter(center); 
												this.map.setZoom(zoom);
											}
										}
										else
										{
											this. map.addOverlay(marker); 
											if(this.bounds)
											{			   
												this.bounds.extend(point);
												var zoom = this.map.getBoundsZoomLevel(this.bounds); 
												var center = this.bounds.getCenter(); 
												this.map.setCenter(center); 
												this.map.setZoom(zoom);
											}
											GEvent.addListener(marker, "click", function() 
																			{
																				marker.openInfoWindowHtml(testo);
																			});
										}
									},
									
									showPointAddress: function(response) {
																			var delay = 0;
																			if (response.Status.code == 620) 
																			{
																				// Too fast, try again, with a small pause
																				delay = 500;
																			}
																			else 
																			{
																				if(response.Status.code == 200) 
																			   	{
																				 	// Success; do something with the address.
																					var place = response.Placemark[0];
																					var latitude = place.Point.coordinates[1];
																					var longitude = place.Point.coordinates[0];
																					var icon = this.arrayDataAddress[this.numGeocoded].getElementsBySelector('.icon')[0].innerHTML;
																				 	var details = this.arrayDataAddress[this.numGeocoded].getElementsBySelector('.details')[0].innerHTML;
																					
																					this.showPoint(latitude, longitude, icon, details, 0);
																			   	}
																			   // Move onto the next address; this skips bad addresses, too.
																			   this.numGeocoded += 1;
																			 }
																			 window.setTimeout(this.geocodeAll.bind(this), delay);
																		 },
									
									geocodeAll: function() 
									{
										if (this.numGeocoded < this.arrayDataAddress.size()) 
										{
											var geocoder = new GClientGeocoder();
											var address = this.arrayDataAddress[this.numGeocoded].getElementsBySelector('.address')[0].innerHTML;
											geocoder.getLocations(address, this.showPointAddress.bind(this));
										}
									}, 
									
									removeInfoWindow: function()
									{
										if(this.markerArray.size() > 0)
										{
											for(i = 0; i < this.markerArray.size(); i++)
											{
												this.map.removeOverlay(this.markerArray[i]); 	
											}
											
											this.markerArray.clear();
										}
									},
									
									loadingImage: function() 
									{
										var loading = $('loading');
										
										var dimensions = loading.getDimensions();
										var containerDimensions = this.containerElenco.getDimensions();
										var leftPosition = Math.round(containerDimensions.width / 2) - Math.round(dimensions.width / 2);
										var topPosition = Math.round(containerDimensions.height / 2) - Math.round(dimensions.height / 2); 
										
										with(loading.style)
										{
											left = leftPosition + 'px';
											top = topPosition + 'px';
										}
										
										var darkLayer = window.document.createElement('div');
										darkLayer.id = 'darkLayer';
										darkLayer.style.height = containerDimensions.height + 'px';
										
										this.containerElenco.appendChild(darkLayer);
										loading.toggle();
									}
								  });

//classe da utilizzare per eseguire la paginazione
var Move = Class.create({	
							initialize: function(scroller_hotelDiv, batchDiv, itemClass, pagerDiv, numberVisible, idExtension) {
											this.scroller_hotelDiv = $('' + scroller_hotelDiv + '');
											this.batchDivName = batchDiv;
											this.batchDiv;
											this.itemClass = itemClass;
											this.pagerDiv = $('' + pagerDiv + '');
											this.numberVisible = numberVisible;
											this.idExtension = idExtension;
											
											this.scroller_hotelDivHeight = this.scroller_hotelDiv.getHeight();
											var calcItem = $$('.' + itemClass)[0];
											if(calcItem)
											{
												this.itemHeight = calcItem.getHeight();
												if(!isNaN(parseInt(calcItem.getStyle('margin-bottom'), 10)))
												{
													this.itemHeight	+= parseInt(calcItem.getStyle('margin-bottom'), 10);
												}
											}
											this.arrayAbsoluteMovementLinks = new Array();
											
											this.reset();
										},
										
							moveAbsolute: function(batchDivNumber) {	
											//se sono al primo o all'ultimo batch non faccio nulla
											if(((batchDivNumber) < 0) || ((batchDivNumber) > this.numberBatch))
											{
												return;
											}
											
											//scrolling batch hotel
											if(batchDivNumber == (this.numberBatch)) //se è l'ultimo batch si ridimensiona il contenitore
											{
												var numberRemainingHotel = this.numberHotel % this.numberVisible;
												this.scroller_hotelDiv.style.height = (this.itemHeight * numberRemainingHotel) + "px";												
											}
											else
											{
												this.scroller_hotelDiv.style.height = this.scroller_hotelDivHeight + "px";
											}
											this.batchDiv.style.top = '-' + (this.scroller_hotelDivHeight * (batchDivNumber)) + 'px';
											//fine scrolling batch hotel
											
											
											var arrayLi = $$('#navigationList' + this.idExtension + ' li.linkMovement');
											
											arrayLi[this.currentBatch].removeClassName('active');
											arrayLi[batchDivNumber].addClassName('active');
											
											//spostamento link numerici
											//se clicco verso destra
											if(batchDivNumber > this.currentBatch)
											{
												//se clicco sul link oltre la metà dell'inizio
												if(batchDivNumber > 4)
												{
													var spostamento = Math.abs(batchDivNumber - this.currentBatch);
													for(i = 1; i <= spostamento; i++)
													{
														//verifico se mi porto fuori del numero massimo di li
														if((this.lastVisible + 1) > this.numberBatch)
														{
															break;	
														}
														
														//verifico se mi sposto a destra di più di 4 link
														if(this.lastVisible > batchDivNumber + 3)
														{
															break;	
														}
														
														arrayLi[this.firstVisible].style.display = 'none';
														this.firstVisible += 1;
														this.lastVisible += 1;
														arrayLi[this.lastVisible].style.display = 'inline';
													}
												}
											}
											
											//se clicco verso sinistra
											if(batchDivNumber < this.currentBatch)
											{
												//se clicco sul link prima della metà dall'inizio
												if(batchDivNumber < this.numberBatch - 4)
												{
													var spostamento = Math.abs(batchDivNumber - this.currentBatch);
													for(i = 1; i <= spostamento; i++)
													{
														//verifico se mi porto fuori del numero minimo di li
														if((this.firstVisible - 1) < 0)
														{
															break;	
														}
														
														//verifico se mi sposto a sinistra di più di 4 link
														if(this.firstVisible < batchDivNumber - 3)
														{
															break;	
														}
														
														arrayLi[this.lastVisible].style.display = 'none';
														this.lastVisible -= 1;
														this.firstVisible -= 1;
														arrayLi[this.firstVisible].style.display = 'inline';
														
														//aggiungo il bordo al primo li
														arrayLi[this.firstVisible + 1].addClassName('borderLeft');
													}
												}
											}
											//fine spostamento link numerici
											
											//modifica puntini
											$('dots_before' + this.idExtension).style.visibility = 'hidden';
											if(this.firstVisible > 0)
											{	
												$('dots_before' + this.idExtension).style.visibility = 'visible';
											}
											
											$('dots_after' + this.idExtension).style.visibility = 'visible';
											if(this.lastVisible == this.numberBatch)
											{
												$('dots_after' + this.idExtension).style.visibility = 'hidden';
											}
											//fine modifica puntini*/
											
											//elimino il bordo dal primo li
											arrayLi[this.firstVisible].removeClassName('borderLeft');
											
											this.currentBatch = batchDivNumber;
											
											//colorazione link precedente/successivo
											if(this.currentBatch > 0)
											{
												$('divPrevious' + this.idExtension).addClassName('active');
												$('linkPrevious' + this.idExtension).addClassName('active');
											}
											else
											{
												$('divPrevious' + this.idExtension).removeClassName('active');
												$('linkPrevious' + this.idExtension).className = '';	
											}
											if(this.currentBatch == this.numberBatch)
											{
												$('divNext' + this.idExtension).removeClassName('active');
												$('linkNext' + this.idExtension).className = '';
											}
											else
											{
												$('divNext' + this.idExtension).addClassName('active');
												$('linkNext' + this.idExtension).addClassName('active');	
											}
											//fine colorazione link precedente/successivo
											
											//spostamento all'inizio del blocco icone
											this.scroller_hotelDiv.scrollTo();
										},
										
							movePrevious: function(evt) {
															Event.stop(evt);
															this.moveAbsolute(this.currentBatch - 1);
													 	},
										
							moveNext: function(evt) {
														Event.stop(evt);
														this.moveAbsolute(this.currentBatch + 1);
												 	},
										
							moveElement: function(evt) {
														Event.stop(evt);
														
														var element = Event.element(evt);
														this.moveAbsolute(parseInt(element.rel, 10));	
													   },	
													   
							linkEventAbsoluteMovementLinks: function() {
																		Event.observe('linkPrevious' + this.idExtension, 'click', this.movePrevious.bind(this));
																		Event.observe('linkNext' + this.idExtension, 'click', this.moveNext.bind(this));
																		
																		var aArray = $$('#' + this.pagerDiv.id + ' a');
																		for(i = 1; i < (aArray.size() - 1); i++)
																		{
																			this.arrayAbsoluteMovementLinks.push(aArray[i]);
																			Event.observe(aArray[i], 'click', this.moveElement.bind(this));	
																		}
													  				  }, 
															   
							unlinkEventAbsoluteMovementLinks: function() {
																			Event.stopObserving('linkPrevious' + this.idExtension);
																			Event.stopObserving('linkNext' + this.idExtension);
																			
																			if(this.arrayAbsoluteMovementLinks.size() > 0)
																			{
																				this.arrayAbsoluteMovementLinks.each(function(a) { a.stopObserving(); });
																				
																				this.arrayAbsoluteMovementLinks.clear();
																			}		
																		 },
										
							reset: function() {
													this.batchDiv = $('' + this.batchDivName + '');
													this.numberHotel = $$('#' + this.batchDivName + ' .' + this.itemClass).size();
													this.numberBatch = parseInt(this.numberHotel / this.numberVisible) + (((this.numberHotel % this.numberVisible) > 0)? 1 : 0) - 1;
													
													this.currentBatch = 0;
													this.firstVisible = 0;
													this.lastVisible = 8;
													
													if(this.numberHotel > this.numberVisible)
													{
														this.scroller_hotelDiv.style.height = (this.numberVisible * this.itemHeight) + 'px';
														this.pagerDiv.show();
														
														this.unlinkEventAbsoluteMovementLinks();
														this.linkEventAbsoluteMovementLinks();
													}
													else if(this.numberHotel > 0)
													{
														this.scroller_hotelDiv.style.height = (this.numberHotel * this.itemHeight) + 'px';
														this.pagerDiv.hide();
													}
													else
													{
														this.scroller_hotelDiv.style.height = '40px';
														this.pagerDiv.hide();	
													}
											  }								  
						});

//funzione per gestire il blinking della scritta nell'header
function blink(id, delay) 
{
	this.obj = "blinkObj" + blink.count++;
	eval( this.obj + " = this " );
	this.css = ( document.getElementById? document.getElementById( id ).style : (document.all? document.all.fooImg.style : document.layers.fooImg ) );
	if( !this.css && !document.layers ) alert( 'Errore: non trovo il DIV con id="' + id + '"' );
	this.delay = delay || 1000;
	this.blinking = false;
	
	this.setDelay = function( delay ) { this.delay = delay; }
	
	this.isBlinking = function() { return this.blinking; }

	this.start = function() { if( this.isBlinking() ) return false; else this.go(); return true; }
	
	this.go = function() {
		this.blinking = true;
		if( this.isVisible() ) this.hide();
		else this.show();
		this.timer = setTimeout( this.obj + ".go()", this.delay );
	}
	
	this.isVisible = function() { return ( this.css.visibility == "visible" || this.css.visibility == "show" ); }
	
	this.hide = function() { this.css.visibility = ( document.layers? "hide" : "hidden" );  }
	
	this.show = function() { this.css.visibility = ( document.layers? "show" : "visible" ); }

	this.stop = function() {
		this.show();
		this.blinking = false;
		clearTimeout( this.timer );
	}
	return this;
}
blink.count = 0;