var vote = function() {
	$$('.avis').each(function(el, i){
	el.addEvent('click', function(e){
		e.stop();
		var ajaxUrl = el.getProperty('rel');
		var ajdRequest = new Request({
   				url: 'avis.php?'+ajaxUrl,
	   			onRequest: function() {
	   				el.set('html', 'En cours de traitement&#8230;');
	   				el.erase('href');
				},
				onComplete: function(response){
					el.set('html', response);
					el.setStyle('color', '#454c50');
				}
   			}).get();
	});
	});
}

var showOverInput = function() {
	$$('.overInput').each(function(el, i){
		var myOverText = new OverText(el, {element:'alt'}).show();
	});
}

var envoiCommentaires = function() {
	$$('.formCommentaire').each(function(el, i){
	el.addEvent('submit', function(e){
		e.stop();
		this.set('send', {
			onRequest: function() {
				el.set('html', 'En cours d&#8217;envoi&#8230;');
			},
			onComplete: function(response) {
				if($('zone_commentaires')) {
					el.set('html', '');
					$('zone_commentaires').set('html', response);
				} else {
					el.set('html', response);
				}
				showOverInput();
		}});
		this.send();
	});
	});
}

var fermerNouveaute = function() {
	$('fermer_nouveaute').addEvent('click', function(e){
		e.stop();
		var nomCookie = $('fermer_nouveaute').getProperty('title');
		var myRequest = new Request.HTML({
			method: 'get',
			url: 'nouveaute.php',
			onRequest: function() {
				$('information_nouveaute').setStyle('display', 'none');
				$('information_nouveaute').set('html', '');
			}
		});
		myRequest.send(nomCookie);
	});
}

window.addEvent('domready', function() {
	if($$('.avis').length > 0){ vote(); }
	if($$('.faire_commentaire').length > 0){
		var myAccordion = new Fx.Accordion($$('.faire_commentaire'), $$('.slide_commentaire'), { display:-1 });
	}
	if($$('.overInput').length > 0){ showOverInput(); }
	if($$('.formCommentaire').length > 0){ envoiCommentaires(); }
	if($('fermer_nouveaute')){ fermerNouveaute(); }
});
