$(document).ready(function(){
	$(window).load(function(){
		$('.document div').slideUp({'duation' : 'fast', 'easing' : 'easeOutBounce'});
	});
	
	//Pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	
	//Formulaire
	$('.required', $(this)).each(function(){
		if($(this).val() == '' || $(this).val() == $(this).attr('title'))
			$(this).css('color', 'gray');
	});
	
	$('form').submit(function(){
		var passed = true;
		$('.required', $(this)).each(function(){
			$(this).css('background-color', 'white');
			if($(this).val() == '' || $(this).val() == $(this).attr('title')){
				$(this).css('background-color', '#B4FF8F').animate({opacity : '0.5'}, 'slow', function(){
					$(this).animate({opacity : '1'}, 'fast');
				});
				passed = false;
			}
		});
		if(!passed){
			$('.errorleft, .errorright').slideUp(function(){
				$(this).remove();
			});
			$('<p class="error'+$(this).css('text-align')+'">Formulaire incomplet.</p>').insertBefore($('input[type=submit]', $(this))).hide().slideDown();
		}
		return passed;
	});
	
	$('.required').focus(function(){
		if($(this).val() == $(this).attr('title'))
			$(this).val('');
		$(this).css('color', 'black');
	}).blur(function(){
		if($(this).val() == '')
			$(this).val($(this).attr('title')).css('color', 'gray');
	});
	
	$('#objet').change(function(){
		if($(this).val() != $(this).attr('title'))
			$(this).css('color', 'black');
		else
			$(this).css('color', 'gray');
	});
	
	$('.document p a.toggleShow').click(function(){
		if($(this).parent().next().css('display') == 'none'){
			$('.document p a.toggleShow').parent().next().slideUp({'duation' : 'slow', 'easing' : 'easeOutBounce'});
			$(this).parent().next().slideDown({'duation' : 'slow', 'easing' : 'easeOutBounce'});
		}else{
			$(this).parent().next().slideUp({'duation' : 'slow', 'easing' : 'easeOutBounce'});
		}
	});
	
	$('#ajouterUpload').click(function(){
		$("#nbUpload").attr('value', parseInt($('#nbUpload').attr('value'))+1);
		$('<p><input type="file" id="upload'+$('#nbUpload').attr('value')+'" name="upload'+$('#nbUpload').attr('value')+'" /></p>').insertBefore($(this));
	});
});