function initGalleryCarousel(){
	var id_photo_clicked=(jQuery('#idx_id_photo').val()!='')?jQuery('#idx_id_photo').val():'';
	var idx_pos_photo=jQuery('#'+id_photo_clicked).parent().attr('jcarouselindex');
	var idx_start=(id_photo_clicked!='' && idx_pos_photo!='')?idx_pos_photo:1;
	jQuery('#gallery_carousel').jcarousel({visible: 4,start:idx_start});
}
jQuery(document).ready(function() {
  jQuery('#mycarousel').jcarousel({visible: 4});
  initGalleryCarousel();
  
  $('#zc').click(function() {
		$.post('/sites/traitement/charger_code.php', { 'id': $(this).attr('alt')}, function(data) {
			$('#zac').html(data);
		});
		return false;
	});
	
  $("span [id='zcr']").click(function() {
		var id_zcr = $(this).attr('alt');
		
		$.post('/sites/traitement/charger_code.php', { 'id': id_zcr}, function(data) {
			$('#zacr_'+id_zcr).html(data);
		});
		return false;
	});
	
  $('#zcl').click(function() {
		$.post('/sites/traitement/charger_code.php', { 'id': $(this).attr('alt')}, function(data) {
			$('#zacl').html(data);
		});
		return false;
	});	
  
});

$(function() {
	$('a[@rel*=lightbox]').lightBox();
});

$(function() {
	$('a[rel=facebox]').facebox();
});

$(function() {
 	$('#lien_comments > div > ul').tabs();
});

function valider_sondage(formulaire, zone_retour, idsondage) {
	var btn_sondage = eval("document."+formulaire+".btn_voter_"+idsondage);
	
	if (btn_sondage){
		btn_sondage.disabled = true;
	}
	
	var	form_sondage = eval("document."+formulaire);
	var valeur_reponse = '';
	for(var i=0; i < form_sondage.choix_vote.length; i++) {
		if(form_sondage.choix_vote[i].checked) {
			if(valeur_reponse==''){
				valeur_reponse = form_sondage.choix_vote[i].value;}
			else{
				valeur_reponse = valeur_reponse+','+form_sondage.choix_vote[i].value;}
		}
	}
	
	
	$.ajax({
		type: "POST",
		url: "sites/traitement/valider_sondage.php",
		data: "idr=" + valeur_reponse +
					"&ids=" + form_sondage.idsond.value,
		success: function(text) {
			$("#zone_sondage_"+text).load("sites/inclusion/resultats_sondage.php?idsond="+text+"");
		}
	});
}

function check_bouton(formulaire, nbr_rep){
	var	form_sondage = eval("document."+formulaire);
	var compteur = 0;

	if(nbr_rep>1){
		/*	On compte le nombre de bouton activé de la liste*/
		for (var i=0; i<form_sondage.length;i++) {
				if(form_sondage[i].checked){
				compteur++;
				}
		}
		
		/*	Si  le nombre de bouton activé est égal au nombre de choix max possibles alors on désactive tous les boutons non activés*/
		if(compteur>=nbr_rep){
			for (var i=1; i<form_sondage.length-1;i++) {
					if(form_sondage[i].checked==false){
						form_sondage[i].disabled=true;
					}
			}
		}
		/*	Sinon on réactive tous les boutons désactivés*/
		else{
			for (var i=0; i<form_sondage.length;i++) {
				if(form_sondage[i].disabled==true){
					form_sondage[i].disabled=false;
				}
			}
		}
	}
}


/* Enlever les accents et caractères spéciaux dans une chaine de caractères (pour placer en URL) */
function nettoyer_titre_url(title) {
	var newtitle = title.replace(/[é|è|ê]/gi, "e");
	newtitle = newtitle.replace(/[à|â|ã]/gi, "a");
	newtitle = newtitle.replace(/[û|ù|ü]/gi, "u");
	newtitle = newtitle.replace(/[î|ï]/gi, "i");
	newtitle = newtitle.replace(/[^a-zA-Z0-9]+/gi, "-");
	return newtitle;
}

function afficher_masquer(id_zone) {
	if(document.getElementById('btn_'+id_zone).innerHTML == 'Voir +') {
		document.getElementById('plus_'+id_zone).style.display = 'block';
		document.getElementById('btn_'+id_zone).innerHTML = 'Voir -';
	}
	else {
		document.getElementById('plus_'+id_zone).style.display = 'none';
		document.getElementById('btn_'+id_zone).innerHTML = 'Voir +';
	}
}

function buzz_count() {
	jQuery('.no_class_buzz').click(function(){
		var btn  = jQuery(this).attr('id');
		var obj = jQuery('#id_objet_'+btn).val();
		//on separe le type, l'action et l'id de la valeur
		var val_splitted = obj.split('_');
		var type = val_splitted[0];
		var action = val_splitted[1];
		var id_object = val_splitted[2];
		file('gestion/traitement/buzz_count.php?id='+id_object+'&type='+type+'&action='+action);
	});	
}

