$(document).ready(function() {
	
	// On retire les commentaires dans les block 'scriptonly'
	$(".scriptonly").each(function(i) {
		html = $(this).html();
		html = html.replace('<!--', '').replace('-->', '');
		$(this).html(html);
	});

	// Menus
	$("#nav_principale_int").addClass('off');
	$("#nav_principale_int").mouseover(function() {
		$(this).removeClass('off');
		return false;
	});
	$("#nav_principale_int").mouseout(function() {
		$(this).addClass('off');
		return false;
	});

	// Contenu dépliable
	$(".depliant_content .zoom_texte").addClass('off');
	$(".depliant_plus a").bind('click', function() {
		$("../../div.zoom_texte", this).toggleClass('off');
		$(this).toggleClass('zoom_moins');
		return false;
	});

	// Votes
	$(".article .voter a").hover(function(){
		// Si on est sur le lien voter
		if ($(this).attr('class') == 'lien_voter')
			return;

		$("../.lien_voter",this).attr('title', $("img", this).attr('alt'));

		current_star = this;
		while (parseInt($("img", current_star).attr('alt')) >= 1)
		{
			$("img", current_star).attr('src', '/sr/img/soft_etoile_pleine.gif');
			tmp = $(current_star).prev(); // On est obligé de passer par une variable temporaire
			current_star = tmp;
		}
		current_star = this;
		tmp = $(current_star).next();
		current_star = tmp;
		while (parseInt($("img", current_star).attr('alt')) <= '5')
		{
			$("img", current_star).attr('src', '/sr/img/soft_etoile_contour.gif');
			tmp = $(current_star).next();
			current_star = tmp;
		}
		
	},function(){});

	$(".article .voter a").bind('click', function() {
		id_vote =  $("../../..",this).attr('id');
		param1 = id_vote.substr(id_vote.indexOf('_')+1);
		// Si on est sur le lien voter
		if ($(this).attr('class') == 'lien_voter')
			param2 = $(this).attr('title');
		else
			param2 = $("img",this).attr('alt');

		if (id_vote.indexOf('soft') != -1)
		{
			var result = $.ajax({url: "/sr/ajax.php?function=ux_softdrink::add_note&param[]="+param2+"&param[]="+param1, async: false}).responseText;

			// On conserve la note en cookie
			SetCookie('note_softdrink_'+param1, param2);
		}
		else
		{
			var result = $.ajax({url: "/sr/ajax.php?function=ux_solution::add_note&param[]="+param2+"&param[]="+param1, async: false}).responseText;

			// On conserve la note en cookie
			SetCookie('note_solution_' + param1, param2);
		}

		// On remonte les images d'un niveau et on supprime les liens
		mp = $(this).parent();
		$("a", mp).each(function() {
			$("img", this).appendTo(mp);
			$(this).remove();
		});

		// On rajoute un message de confirmation
		$(mp).append(' <span>Votre vote a été pris en compte</span>');

		return false;
	});

	// Block comparatif des boissons
	if (document.getElementById('soft_container'))
	{
		var options = {
			blockWidth: 665,
			blockVisibleWidth: 170,
			scrollSpeed: "normal",
			scrollStep: 99
		}
		$(".softdrinks_comparatif").scrollBlock(options);
	}

	// Block formulaire recherche bénévole
	$(".colonne_droite .form_recherche_benevole_short a").bind('click', function() {
		$(".colonne_droite .form_recherche_benevole_short").toggleClass('off');
		$(".colonne_droite .form_recherche_benevole").toggleClass('off');
		$(".colonne_droite .form_recherche_offre").toggleClass('off');
		return false;
	});
	
	// Slide des softdrinks et solutions
	var options = {
		newsWidth: 320,
		newsHeight: 326,
		newsSpeed: "normal",
		nbItem: 2
	}
	$(".slider").slideNews(options);
});
