
$(document).ready(function() {
	
	// Navigation top (menu déroulant de second niveau) :
	$('#navtop li').hover(
		function() { $(this).find('ul').show(); },
		function() { $(this).find('ul').hide(); }
	);
	
	// Diaporama tetiere :
	set_diaporama_tetiere();
	
	// colorBox :
	$('a.colorbox').colorbox();
	$('a.close_cbox').click(function(e) {
		parent.$.fn.colorbox.close();
		parent.refresh_panier();
		e.preventDefault();
	});
	
	$('#add_panier').submit(function(e) {
		id_produit = $('#id').val();
		code_taille = $('#select_taille').val();
		if (!isNaN(id_produit)) {
			if (code_taille != '') {
				$.fn.colorbox({href:'panier.php?add_produit='+id_produit+'&code_taille='+code_taille, iframe:true, width:450, height:300});
			} else {
				alert('Vous devez choisir une taille');
			}
		}
		e.preventDefault();
	});
	
	$('.btn_panier_suppr').live('click', function(e) {
		id_ligne = $(this).attr('id').replace('btn_panier_suppr:', ''); //:2_M
		$.ajax({
			type: "POST",
			url: "inc.col_gauche_x_panier.php",
			data: 'del='+id_ligne,
			success: function(response){ $('#x_panier').html(response); }
		});
		e.preventDefault();
	});
	
	$('.erreur').hover(
		function() { $(this).find('.detail_erreur').show(); }, 
		function() { $(this).find('.detail_erreur').hide(); }
	);
	
	
});


var current_diapo = 0;
var nb_diapo = 1;
var do_rotate_diapo = true;

function set_diaporama_tetiere() {
	
	$('#img_diapo li').animate({opacity:0}, 0);
	$('#txt_diapo li').animate({height:0}, 0);
	$('#img_diapo li:eq(0)').animate({opacity:1}, 0);
	$('#txt_diapo li:eq(0)').animate({height:'200px'}, 0);
	
	// génération des liens pour passer d'un bloc à l'autre :
	nb_diapo = $('#img_diapo li').size();
	liens = '';
	for (i=1; i<=nb_diapo; i++) {
		liens += '<a href="#" class="lien_diapo" id="lien_diapo_'+i+'">'+i+'</a>';
	}
	$('#diapo_header').append('<div id="pagin_diapo">'+liens+'</div>');
	$('#diapo_header #pagin_diapo a').click(function(e) {
		id_diapo = $(this).attr('id').replace('lien_diapo_', '');
		affiche_diapo(id_diapo);
		e.preventDefault();
	});
	$('#diapo_header').hover(function() {do_rotate_diapo = false;}, function() {do_rotate_diapo = true;});
	rotate_diapo();
}
function affiche_diapo(id_diapo) {
	if (id_diapo != current_diapo) {
		$('#img_diapo_'+current_diapo).animate({opacity:0}, 'slow');
		$('#img_diapo_'+id_diapo).show().animate({opacity:1}, 'slow');
		$('#txt_diapo_'+current_diapo).animate({height:0}, 'fast');
		$('#txt_diapo_'+id_diapo).animate({height:'200px'}, 'slow');
		
		$('#lien_diapo_'+id_diapo).addClass('current');
		$('#lien_diapo_'+current_diapo).removeClass('current');
		current_diapo = id_diapo;
	}
}
function rotate_diapo() {
	if (do_rotate_diapo) {
		new_id_diapo = current_diapo+1;
		if (new_id_diapo > nb_diapo) new_id_diapo = 1
		affiche_diapo(new_id_diapo);
	}
	setTimeout('rotate_diapo()', 4000);
}

function refresh_panier() {
	$.ajax({
		type: "POST",
		url: "inc.col_gauche_x_panier.php",
		success: function(response){ $('#x_panier').html(response); }
	});
}



/****	VOTES MEDIA 	****/
$(document).ready(function() {
	$('.bloc_votez').each(function() {
		current_vote = $(this).attr('class').replace('bloc_votez vote_', '');
		current_id = $(this).attr('id').replace('bloc_vote_', '');
		if (isNaN(current_vote) || current_vote < 0 || current_vote > 5) current_vote = 5;
		current_vote = current_vote;
		$(this).rater('photos_x_votes.php?id_photo='+current_id, {curvalue:current_vote});
	});
});


