function lista_accordion(toggler,accordion){
	var ac = new Fx.Accordion($$(toggler),$$(accordion),{
			alwaysHide: true,
			start : 'all-closed',
			height: true,
			transition: Fx.Transitions.quadIn,
			duration: 1000
		});
}
function selettore(elementi,classe){
	var tabs = $$(elementi);
	tabs.each(function(tab){
		tab.addEvent("mouseover", function() {
			this.addClass(classe);
		}.bind(tab));
		
		tab.addEvent("mouseout", function() {
			this.removeClass(classe);
		}.bind(tab));
	});
}

var SimpleSlideshow = new Class({
	options: {
		showControls: false,
		showDuration: 5000,
		showTOC: false,
		tocWidth: 20,
		tocClass: 'toc',
		tocActiveClass: 'toc-active'
	},
	Implements: [Options,Events],
	initialize: function(container,elements,options) {
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = 0;
		this.interval = '';
		if(this.options.showTOC) this.toc = [];
		
		this.elements.each(function(el,i){
			if(this.options.showTOC) {
				this.toc.push(new Element('a',{
					text: i+1,
					href: '#',
					'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''),
					events: {
						click: function(e) {
							if(e) e.stop();
							this.stop();
							this.show(i);
						}.bind(this)
					},
					styles: {
						left: ((i + 1) * (this.options.tocWidth + 10))
					}
				}).inject(this.container));
			}
			if(i > 0) el.set('opacity',0);
		},this);
		
		if(this.options.showControls) {
			this.createControls();
			
		}

		this.container.addEvents({
			mouseenter: function() { this.stop(); }.bind(this),
			mouseleave: function() { this.start(); }.bind(this)
		});

	},
	show: function(to) {
		this.elements[this.currentIndex].fade('out');
		if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
		this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].fade('in');
		if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
	},
	start: function() {
		this.interval = this.show.bind(this).periodical(this.options.showDuration);
	},
	stop: function() {
		$clear(this.interval);
	},

	createControls: function() {
		var next = new Element('a',{
			href: '#',
			id: 'next',
			text: '>>',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show();
				}.bind(this)
			}
		}).inject(this.container);
		var previous = new Element('a',{
			href: '#',
			id: 'previous',
			text: '<<',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
				}.bind(this)
			}
		}).inject(this.container);
	}
});


function fadePagina(){
    var myElement = $$('.mask');
    myElement.set('tween', {
	duration: '2000'
    });
    myElement.tween('opacity', 1, 0);
}


document.addEvent('domready', function() {
    
    var href = 'index.php'+location.search;

    if(href=='index.php'){
	$('body').set('mask');
	var auguri = new Element('p', {id: 'auguri'});	
	auguri.set('html','<span id="primo">semplicemente...</span><span id="secondo">auguri di cuore</span>');
	
	$('body').mask(); //obscure the element with the overlay
	$$('.mask').adopt(auguri);
	setTimeout('fadePagina()',4000);
    }

	lista_accordion("div.footer_titolo","div.collapse");
	var opt = {
		duration: 6000,
		delay: 3000,
		auto:true,
		onMouseEnter: function(){this.stop();},
		onMouseLeave: function(){this.play();},
	}

	selettore('#menu a','selected');

	if($$('.slide').length>0){
		var slideshow = new SimpleSlideshow('immagine','#immagine img');
		slideshow.start();
	}
	
	var myTabSwapper = new TabSwapper({
		selectedClass: 'tab_on',
		deselectedClass: 'tab_off',
		mouseoverClass: 'over',
		mouseoutClass: '',
		tabs: $$('#scelta .bottone'),
		clickers: $$('#scelta .bottone'),
		sections: $$('#testo .tab'),
		smooth: true
	});	
	
	var equalizer = new Equalizer('.equalize').equalize('height');	

// 	Mediabox.open('http://www.spiaggiadonnarosa.com/Donnarosa Mar17.mp4', "Donnarosa 17 maggio::<a href='Donnarosa Mar17.mp3' target='_blank'>Scarica lo spot in formato mp3</a> <br/><a href='Donnarosa Mar17.mp4' target='_blank'>Oppure il video in formato mp4</a>", '480 280');

});
