var url = pathHttp + 'web_services.php';
		
Event.observe(window, 'load', initGooglemap);
document.observe('dom:loaded', init);

function initGooglemap()
{
	//caricamento googlemap large riepilogo pagina hotel
	if($('boxGooglemap'))
	{
		var googlemap = new DisplayGooglemap('boxGooglemap');
		googlemap.setMarkerHTMLData('#googlemapData','.hotel','');
	}
	
	if($('googlemapSmall'))
	{
		var googlemap = new DisplayGooglemap('googlemapSmall');
		googlemap.setSingleMarkerHTMLData('googlemapData');
	}

}

function manageEventFocus(evt)
{
	var element = Event.element(evt);
	
	if(element.hasClassName('default'))
	{
		element.removeClassName('default');
		Form.Element.clear(element);
	}
}

function init(){	
	if (document.images)
   {
	//caricamento immagini sfondi
	var pic1 = new Image();
	pic1.src = pathHttp + '/img/structure/menu_dw_bt_bg.png';
	var pic2 = new Image();
	pic2.src = pathHttp + '/img/structure/menu_dw_fbt_bg.png';
	var pic3 = new Image();
	pic3.src = pathHttp + '/img/structure/bg.jpg';
	   
     pic1on= new Image(36,25);
     pic1on.src="/img/structure/flag_ita.png";  

     pic1off= new Image(36,25);
     pic1off.src="/img/structure/flag_ita_lg.png";
	 
	 pic2on= new Image(36,25);
     pic2on.src="/img/structure/flag_eng.png";  

     pic2off= new Image(36,25);
     pic2off.src="/img/structure/flag_eng_lg.png";
	 
	 pic3on= new Image(36,25);
     pic3on.src="/img/structure/flag_deu.png";  

     pic3off= new Image(36,25);
     pic3off.src="/img/structure/flag_deu_lg.png";
   }

	//inizializzazione scroller lastminute colonna sx
	var arrayLastminuteLeft = $$('.lastminuteSmall');
	if(arrayLastminuteLeft.size() > 3)
	{
		var parametriLastminuteSmall = new Array()
		parametriLastminuteSmall["divname"] = "marqueedivLastminuteSmall"; //nome del div che contiene il testo
		parametriLastminuteSmall["containername"] = "marqueeContainerLastminuteSmall"; //nome del div contenitore dello scroller
		parametriLastminuteSmall["direction"] = "up"; //Specify direction of movement
		parametriLastminuteSmall["speed"] = 3; //Specify marquee scroll speed (larger is faster 1-10)
		parametriLastminuteSmall["pauseScroll"] = 1; //Specifica se impostare uno scroller con pause periodiche (0=no. 1=se)
		parametriLastminuteSmall["pauseNumber"] = arrayLastminuteLeft.size(); //Numero di elementi contenuti nello scroller
		parametriLastminuteSmall["numScroll"] = 3; //Numero di elementi da scrollare prima della pausa
		parametriLastminuteSmall["pauseInterval"] = 5000; //Durata di ciascuna pausa periodica
		parametriLastminuteSmall["pause"] = 1; //Pause marquee onMousever (0=no. 1=yes)

		oggettoLastminuteSmall = new Scroller(parametriLastminuteSmall);
		oggettoLastminuteSmall.initializemarquee();
		
		$('marqueeContainerLastminuteSmall').observe('mouseover', function() { oggettoLastminuteSmall.pauseFunction(); });
		$('marqueeContainerLastminuteSmall').observe('mouseout', function() { oggettoLastminuteSmall.copyFunction(); });
	}
	
	//caricamento dello slider immagini top (protofade)
    if($('protofade'))
    {
        new Protofade('protofade', { randomize: true, 
                                       duration: 3.0                                    
                                   });    
    }
    
	//inizializzazione della paginazione elenco lastminute pagine lastminute frazione
	if($('containerLastminuteLarge'))
	{
		var moveListLastminute = new Move('containerLastminuteLarge', 'batchLastminuteLarge', 'lastminute', 'paginazione', 11, '');		
	}
	
	if($('note_e_richieste'))
		$('note_e_richieste').observe('focus', manageEventFocus);
	
	Cufon.replace('.qfon',{fontFamily: 'Euphemia'}); 
	Cufon.replace('.qfon_bold',{fontFamily: 'Euphemia UCAS'}); 
	Cufon.replace('.menuUpItem',{fontFamily: 'Euphemia UCAS', hover: {color: '#FEC900'} });
	Cufon.replace('.menuDwItem',{fontFamily: 'Euphemia UCAS', hover: {color: '#FEC900'} });
	Cufon.replace('.qfon-shadow', {fontFamily: 'Euphemia UCAS',
                    textShadow: '1px 1px #444'
                    });
	
	
	if($('carousel-wrapper-gallery')) new Carousel('carousel-wrapper-gallery',$$('#carousel-content-gallery .slide'), $$('a.carousel-control'),{
                                                 auto:false,
                                                 duration:1,
                                                 frequency:3,
                                                 circular:false,                                
                                                 wheel:false,       
                                                 visibleSlides :4
                                                 }); 
}
	


//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) > 0)? (this.numberHotel % this.numberVisible) : 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();	
													}
											  }								  
						});




	
	
	
