$(function(){
	// Mascotte
	$('.mascotte').flash({
		swf: 'themes/flash/mascotte.swf',
		width:120,
		height:150,
		wmode: 'transparent',
		flashvars: { 
			url: 'pages/testciterne/'
		}
	});
	
	// Test
	var question = 1;
	var left = 0;
	var boxwidth = 440;
	var maxleft = ( 5 * boxwidth );
	$('.quest input').not('[type=submit]').bind('click',function(e){
		left -= boxwidth;
		valeur = $(this).val();		
		$(this).parent().find('input[type=hidden]').val( valeur );
		idreponse = '#question-' + question;
		$(idreponse + ' .' + valeur).show();
		$('#answers .a' + question).addClass('valid');
		$('.a'+question+valeur).addClass('validAnswer');
		
		if(question == 1 && valeur == "b")
		{
			left = ( -4 * boxwidth );
			$('#question-2,#question-3,#question-4').hide();
		}
		else
		{
			$('.pointeur a:lt('+(question+1)+')').addClass('actif');
			question++;
		}
		$('.maxwidth').animate({ left : left +'px' },{ duration : "slow" , easing: 'easeOutBack' });
		e.preventDefault();
	});
	
	$('#getAnswer').bind('click',function(event){
		if($('#question-1 .b').css('display') == 'block')
		{
			event.preventDefault();
			window.open("http://test-citerne.be/docs/ft_hydrocarbures.pdf");
		}
	});

	
	$('.pointeur a').bind('click',function(e){ e.preventDefault(); });
	
		
	// Notions pratiques
	var slidedDown = null;
	$('.slideDown').hide();
	$('h4 a').bind('click',function(e){
		var id = this.hash;
		$('.slideDown').slideUp();
		$('.question').addClass('no-print');
		if(id != slidedDown) {
			$(id).slideToggle();
			slidedDown = id;
			$(id + 'h4').removeClass('no-print');
		}
		
		e.preventDefault();
	});
	$('.slideDown a').bind('click',function(e){
		var id = this.hash;
		$('.slideDown').slideUp();
		$('.question').addClass('no-print');
		if(id != slidedDown) {
			$(id).slideToggle();
			slidedDown = id;
			$(id + 'h4').removeClass('no-print');
		}
		e.preventDefault();
	});
	
	$('.pointeur a').bind('click',function(e){ e.preventDefault(); });

	//Commande
	$('.no-js').hide();
	if($('#oui:not(:checked)').length == 1){
		$('#addEcheance').hide();
	}

	var statut = ($('#form_statut input:not(:checked)').val());
	$('#form_' + statut).hide();
		
	$('#entreprise').bind('click', function(){
		$('#form_entreprise').show();
		$('#form_particulier').hide();
	});
	
	$('#particulier').bind('click', function(){
		$('#form_entreprise').hide();
		$('#form_particulier').show();
	});

	$('#oui').bind('click', function(){
		$('#addEcheance').show();
	});

	$('#non').bind('click', function(){
		$('#addEcheance').hide();
	});

	$('#fournisseur').bind('change', function(){
		if($(this).val()=='autre'){
			$('#autre_fournisseur').show();
		}else{
			$('#autre_fournisseur').hide();
		}
	});

	if($('#fournisseur').val()=='autre'){
		$('#autre_fournisseur').show();
	}

	$('#printCommande').bind('click', function(e){
		window.print();
		e.preventDefault();
	})
	
});
