document.observe('dom:loaded', function()
{
	// accordion orizzontale	
	$$('.accordion').each(function(obj) { new accordion(obj.identify(), 'li',{ selected : 0, size :{totalWidth : 512, totalHeight : 130, minPanelWidth : 58, maxPanelWidth : 280 } }); });
	// hs alert sito esterno
	$$('a[rel=hs]').each(function(link)	{ link.observe('click', function(e) {	Event.stop(e); hs.htmlExpand(link, { contentId: 'highslide-html' }); $('prosegui').href = link; });});
	// fader gallery foto del mese
	new Widget.Fader('foto-mese', pictures.pluck('src'), {beforeFade: displayTitle,fadeInDuration: 1,fadeOutDuration: 1,displayDuration: 5});
	// link plus observer
	listPlusObserver();
	// captionObserver
	captionObserver();
	// form
	formUtils.init();
	// gmaps
	mapsInitialize();
});

function listPlusObserver()
{
	$$('.smart-list-plus>a').invoke('observe', 'click', function(){ $(this).next('ul').toggle(); });
}


function captionObserver()
{
	if (!$('box-image')) return;
	$('box-image').observe('mouseenter', function()
	{
		new Effect.Parallel([
			new Effect.Move(this.down('.caption'), { sync: true, x: 0, y: 0, mode: 'absolute' }), new Effect.Opacity(this.down('.caption'), { sync: true, from: 1, to: 0.8 }) ],
			{ duration: 0.5, queue : { position:'end', scope:'caption', limit:2 }
        });
	});
	
	$('box-image').observe('mouseleave', function()
	{
		new Effect.Parallel([
           new Effect.Move(this.down('.caption'), { sync: true, x: 0, y: 258, mode: 'absolute' }), new Effect.Opacity(this.down('.caption'), { sync: true, from: 0.8, to: 1 })],
           { duration: 0.2,queue : { position:'end', scope:'caption', limit:2 }});
	});
}

function mapsInitialize()
{
	if ($("mappa-container") && GBrowserIsCompatible())
	{
        var map = new GMap2($("mappa-container"));
        map.setCenter(new GLatLng(44.116400, 10.409200), 10);
        map.setMapType(G_PHYSICAL_MAP);
        map.setUIToDefault();
    }
} 

function displayTitle(img, fadeIn) {
	if(fadeIn)
	{
		var appearing = pictures.find(function(e){return img.src.slice(-e.src.length) == e.src; });
		if (appearing) 	$("foto-descr").update(appearing.title);
		else			$("foto-descr").update('');
	}
}

	