$(function() {
	
	/*Diaporama*/
	var slshow = $('#slideshow');
	
	if ( slshow.length ) {
		slshow.slides({
			preload : false,
			play : 5000,
			pause : 2500,
			container : 'slideshow-container',
			hoverPause : true,
			generatePagination : false,
			generateNextPrev : true
		});
	};
	
	/*slide news*/
	var slnews = $('#slide-news');
	
	if ( slnews.length ) {
		slnews.slides({
			preload : false,
			play : 5000,
			pause : 2500,
			container : 'slide-container',
			hoverPause : true,
			generatePagination : true,
			paginationClass : 'slide-pagination'
		});
	};
	
	/*slide témoignages*/
	var sltesti = $('#slide-testimonial');
	
	if ( sltesti.length ) {
		sltesti.slides({
			preload : false,
			play : 5000,
			pause : 2500,
			container : 'slide-container',
			hoverPause : true,
			generatePagination : true,
			paginationClass : 'slide-pagination'
		});
	};
	
	$('.fb').fancybox({titlePosition: 'inside'});
	
	$('.fbiframe, .fbmap').fancybox({
		'width'			: 800,
		'height'		: 600,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'type'			: 'iframe'
	});
	
	$('.sub-section').click( function(e) {
		var n = $(this).next();
		if(!n.is(':visible')) {
			n.show('fast');
			$(this).addClass('open');
		}else{
			n.hide('fast');
			$(this).removeClass('open');
		}
		e.preventDefault();
	});
	
	/* Intéraction page d'accueil */
	var initialZipCode = '';
	$('.home-bloc #zipcode').focus(function(){
		if(initialZipCode == ''){
			initialZipCode = $(this).val();
		}
		if ($(this).val() == initialZipCode) {
			$(this).val('');
		}
	});
	
	$('.home-bloc #zipcode').blur(function(){
		if($(this).val() == ''){
			$(this).val(initialZipCode);
		}
	});
	
//Recherche d'une agence via le code postal
	var initialNetworkSearch = '';
	$('#networkSearch').focus(function(){
		if(initialNetworkSearch == ''){
			initialNetworkSearch = $(this).val();
		}
		if ($(this).val() == initialNetworkSearch) {
			$(this).val('');
		}
	});
	
	$('#networkSearch').blur(function(){
		if($(this).val() == ''){
			$(this).val(initialNetworkSearch);
		}
	});
	
//Recherche textuelle
	var initialSearch = '';
	$('.search').focus(function(){
		if(initialSearch == ''){
			initialSearch = $(this).val();
		}
		if ($(this).val() == initialSearch) {
			$(this).val('');
		}
	});
	
	$('.search').blur(function(){
		if($(this).val() == ''){
			$(this).val(initialSearch);
		}
	});
	
//Message offre d'emploi
	$('#candidature #message').focus(function(){
		if($(this).val() == 'Insérez un message si vous le souhaitez'){
			$(this).val('');
		}
	});
	
//Formulaire de rappel
	var initialPhoneNumber = '';
	$('.home-bloc #phoneNumber').focus(function(){
		if(initialPhoneNumber == ''){
			initialPhoneNumber = $(this).val();
		}
		if ($(this).val() == initialPhoneNumber) {
			$(this).val('');
		}
	});
	
	$('.home-bloc #phoneNumber').blur(function(){
		if($(this).val() == ''){
			$(this).val(initialPhoneNumber);
		}
	});
	
	/* Formulaire FAQ */
	$('#selectFAQ').change(function(){
		$(this).parents('form:first').submit();
	});
	
	$('.faq .response').hide();
	$('.faq h4').click(function(e){
		e.preventDefault();
		$(this).next('.response:first').slideToggle(500)
	});
	
	/* Formulaire "Près de chez vous" */
	$('#deptcode').change(function(){
		$(this).parents('form:first').submit();
	});
	
	/* Grossir, rétrécir le texte */
	if( $('.size-plus').length ) {
		var zone = ($('.text-news').length ? $('.text-news') : $('.news-detail') );
		$('.size-plus').click( function() {
			var fontSize = parseInt(zone.css('font-size'))+1;
			var lineHeight = parseInt(zone.css('line-height'))+2;
			zone.css({
					'font-size' 	: fontSize+'px',
					'line-height' 	: lineHeight+'px'
					});
			return false;
		});
		$('.size-minus').click( function() {
			var fontSize = parseInt(zone.css('font-size'));
			if( fontSize === 12 ) { return false };
			fontSize = --fontSize;
			var lineHeight = parseInt(zone.css('line-height'))-2;
			zone.css({
						'font-size' 	: fontSize+'px',
						'line-height' 	: lineHeight+'px'
					});
			return false;
		});
	}

});
