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

function init()
{		
	var paramsTop = {
						wmode: 'transparent',
						quality: 'high'
                    }
	swfobject.embedSWF(pathHttp + 'flash/menu.swf', 'flash', '168', '350', '9.0.0', 'expressInstall.swf', '', paramsTop);
	
	//inizializzazione cufon
	if(navigator.userAgent.indexOf('MSIE 6.0') == -1)
	{
		Cufon.replace('h1')('h3')('span.title')('span.titoloOrangeSmall');
	}
	
	//inizializzazione scroller eventi colonna dx
	var arrayEventiUl = $$('.eventiRight');
	if(arrayEventiUl.size() > 1)
	{
		var parametriEventi = new Array()
		parametriEventi["divname"] = "marqueedivEventi"; //nome del div che contiene il testo
		parametriEventi["containername"] = "marqueeContainerEventi"; //nome del div contenitore dello scroller
		parametriEventi["direction"] = "up"; //Specify direction of movement
		parametriEventi["speed"] = 3; //Specify marquee scroll speed (larger is faster 1-10)
		parametriEventi["pauseScroll"] = 1; //Specifica se impostare uno scroller con pause periodiche (0=no. 1=sì)
		parametriEventi["pauseNumber"] = arrayEventiUl.size(); //Numero di elementi contenuti nello scroller
		parametriEventi["numScroll"] = 1; //Numero di elementi da scrollare prima della pausa
		parametriEventi["pauseInterval"] = 5000; //Durata di ciascuna pausa periodica
		parametriEventi["pause"] = 1; //Pause marquee onMousever (0=no. 1=yes)

		oggettoEventi = new Scroller(parametriEventi);
		oggettoEventi.initializemarquee();
		
		$('marqueeContainerEventi').observe('mouseover', function() { oggettoEventi.pauseFunction(); });
		$('marqueeContainerEventi').observe('mouseout', function() { oggettoEventi.copyFunction(); });
	}
	
	//caricamento mappa scheda hotel
	if($('googlemapSchedaHotel'))
		displayMapSchedaHotel('googlemapSchedaHotel', true);
		
	//caricamento mappa dove siamo
	if($('googlemapDoveSiamo'))
		displayMapSchedaHotel('googlemapDoveSiamo', false);
	
	//caricamento gallery immagini scheda
	if($('schedaAttivita'))
	{
		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
											}
						});	
	}
}

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

function manageEventClick(evt)
{
	var element = Event.element(evt);
	
	switch(element.tagName.toLowerCase())
	{
		case 'a':
			if(element.hasClassName('mappaHomepage'))
			{
				Event.stop(evt);
				
				var frazione = element.id;
				
				if(!$('containerGooglemap').visible())
				{
					Effect.BlindDown('containerGooglemap');
				}
				
				var params = new Hash();
				params.set('action', 'get_attivita_mappa_homepage');
				params.set('frazione', frazione);
				
				new Ajax.Request(url, {
										method: 'post',
										contentType: 'application/x-www-form-urlencoded',
										parameters: params,
										evalJSON: true,
										onSuccess: function(transport) { 
																		 displayMapHomepage(transport.responseJSON);
																	   }
									   });
			}
			else if(element.id == 'linkConsiglioDirettivo')
			{
				Event.stop(evt);
				
				Effect.toggle('testoConsiglioDirettivo', 'blind');	
			}
			else if(element.id == 'linkApriPercorso')
			{
				Event.stop(evt);
				
				Effect.toggle('containerPercorso', 'blind');	
			}
			else if(element.id == 'linkChiudiGooglemap')
			{
				Event.stop(evt);
				
				Effect.toggle('containerGooglemap', 'blind');
				
				markerArray.each(function(marker) { map.removeOverlay(marker) });
			}
		break;
		
		case 'img':
		break;
	}
}

function recupera_coordinate()
{
	if(document.getElementById('frazione').selectedIndex > 0)
	{
		frazione = document.getElementById('frazione').options[document.getElementById('frazione').selectedIndex].innerHTML;
		var indirizzo = document.getElementById('indirizzo').value;
		var cap = document.getElementById('cap').value;

		var jsel = document.createElement('SCRIPT'); 
		jsel.type = 'text/javascript'; 
		jsel.src = 'http://admin.abc.sm/clienti/ajax_scripts/get_lat_long_attivita.php?indirizzo=' + indirizzo + '&frazione=' + frazione +'&cap=' + cap;
		window.document.body.appendChild(jsel);
	}
	else
	{
		alert('seleziona una località'); 
	}	
}

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