// JavaScript Document
$(document).ready(function () {
							
// Position de départ							
$.scrollTo('#bloc_contact',{axis:'xy', duration:700});
	

$('.agence .deplacement').bind('click', function() {
	$.scrollTo('#bloc_agence',{axis:'xy', duration:900});
	});

$('.refs .deplacement').bind('click', function() {
	$.scrollTo({top:'420px',left:'3110px'},{axis:'xy', duration:900});
	});

$('.contact .deplacement').bind('click', function() {
	$.scrollTo('#bloc_contact',{axis:'xy', duration:900});
	});

$('#bloc_agence .menuAgence .deplacement').bind('click', function() {
	$dest = $(this).attr('href');
	$.scrollTo($dest ,{axis:'y', duration: 700});
	});


$('.client').bind('click', changeClient);
$('.prestation').bind('click', changePresta);
$('.image_supp').bind('click', changeImage);

});



function changeClient()
{
	$client = $(this).attr('id').substring(7);
	$('.client').removeClass('select');
	$(this).addClass('select');
	
	$.post("maj_prestations.php", { id_client: $client},
	function success(data){
		// on remplace la liste des prestations
		$('#liste_prestations').replaceWith(data);
		
		// on sélectionne la première prestation
		$('.prestation').removeClass('select');
		$('#liste_prestations li:first a').addClass('select');
		
		// on affiche les infos de la première prestation
		$prestation = $('#liste_prestations li:first a').attr('id').substring(7);
		
		$.post("maj_infos.php", { id_presta: $prestation},
		function success(data){
			//on affiche les infos
			$('#infos').replaceWith(data);
			// on remet les events en place
			$('.prestation').bind('click', changePresta);
			$('.image_supp').bind('click', changeImage);
		});
	});

}

function changePresta()
{
	
	// on sélectionne la première prestation
	$('.prestation').removeClass('select');
	$(this).addClass('select');
	
	// on affiche les infos de la première prestation
	$prestation = $(this).attr('id').substring(7);
	
	$.post("maj_infos.php", { id_presta: $prestation},
	function success(data){
		// on affiche les infos
		$('#infos').replaceWith(data);
		// on remet les events en place
		$('.image_supp').bind('click', changeImage);
	});
	
}

function changeImage()
{
	$num_image = parseInt($(this).html().substr(0,2));
	
	$('.image_supp').removeClass('rouge');
	$(this).addClass('rouge');
	$id_ref = $(this).children().html();
	//alert ('id_ref = ' + $id_ref);
	
	$.post("maj_image.php", { num_image: $num_image, id_ref: $id_ref},
	function success(data){
		// on affiche l'image
		$('#img_ref').replaceWith(data);
	});

}
