function isEmailValid(email){

	var e = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

	return e.test(email);

}

$(document).ready(function(){


	/* MESSAGE DE CONFIRMATION */

	setTimeout(function(){$('#confirmMsg').slideDown();setTimeout(function(){$('#confirmMsg').slideUp()},10000);},500);

	$('#closeConfirmMsg').click(function(){

		$('#confirmMsg').slideUp();

		return false;

	})

	/* JQDOCK sur les pictos du header */
	var dockOptions =
	{ size: 30  // set the maximum minor axis (horizontal) image dimension to 36px
    , labels: 'tc' 
    };
	$('#menuHaut').jqDock(dockOptions);


	/* GESTION HAUTEUR SIDEBAR */

	setTimeout(function(){

		if ($('aside').height() < $('#mainSection').height()){

			$('aside').css({'height':''+$('#mainSection').height()+'px'});

		}

	},100);

	$('.tabs a').click(function(){

		setTimeout(function(){

			if ($('aside').height() < $('#mainSection').height()){

				$('aside').css({'height':''+$('#mainSection').height()+'px'});

			}

		},50);

	})

					

	

	/* PRINT FRIENDLY */

	if ($('#headlines-infos').length){

		$('#container').prepend('<div id="listItems"><h2>A la une</h2><ul>'+$('#headlines-infos ul').html()+'</ul></div>');

	}

	

	/* OPERATIONS SUR MENU DE NAVIGATION */

	$('#menuHeader li ul li').find('a').hover(function(){

		$(this).stop().animate({'text-indent':'5px'},500)},

			function(){

			$(this).stop().animate({'text-indent':'0'},500)

	});

	

	new menu(); // pour l'effet slidedown

	

	

	/* CHAMPS DE RECHERCHE */

	$('#search').focus(function(){

		$(this).val('');									   

	}).blur(function(){

		if ($(this).val() == ""){

			$(this).val('rechercher');	

		}

	});

	

	/* CAROUSEL ACTUS */

	$("#headlines-images").jCarouselLite({

			visible: 1,

			speed: 800,

			easing: "easeInOutCubic",

			easeTime:500,
			
			auto:true,

			timeout:8000,

			beforeStart: function(){$('.bulletWrap').animate({'background-color':'#95c1e6'},500).find('a').animate({'color':'#fff'},500);},

			afterEnd: function(e){

				var slideNmbr = e.prevObject.selector.replace(/[a-z]|\(|\)|\./g,"");

				var totalSlides = $('.slide').size();

				slideNmbr = (slideNmbr == totalSlides-1 || slideNmbr == 1) ? 1 : slideNmbr;

				$('.bulletWrap').has('#slide'+slideNmbr+'').animate({'background-color':'#fff','color':'#000'},500).find('a').animate({'color':'#000'},500);

			},

			btnGo:["#externalControl #slide1", "#externalControl #slide2", "#externalControl #slide3", "#externalControl #slide4", "#externalControl #slide5", "#externalControl #slide6", "#externalControl #slide7", "#externalControl #slide8", "#externalControl #slide9", "#externalControl #slide10"]

	});

	$("#headlines-infos").jCarouselLite({

			visible: 1,

			speed: 800,

			easing: "easeInOutCubic",

			easeTime:500,

			auto:true,
			
			timeout: 8000,

			btnGo:["#externalControl #slide1", "#externalControl #slide2", "#externalControl #slide3", "#externalControl #slide4", "#externalControl #slide5", "#externalControl #slide6", "#externalControl #slide7", "#externalControl #slide8", "#externalControl #slide9", "#externalControl #slide10"]

	});

	

	/* CAROUSEL AGENDA */

	$("#agendaCarousel").jCarouselLite({

			visible: 3,

			speed: 400,

			easing: "easeInOutCubic",

			easeTime:200,

			auto:false,

			scroll:3,

			mouseWheel: true,

			circular: true,

			btnNext: "#nextEvent",

        	btnPrev: "#prevEvent"

			

	});

	

	/* CHANGER LA TAILLE DE LA POLICE */

	$('.fontChanger').click(function(){

		var ourTextP = $('p').not('.noresize');

		var currFontSizeP = ourTextP.css('fontSize');

		var finalNumP = parseFloat(currFontSizeP, 10);

		var stringEndingP = currFontSizeP.slice(-2);

		

		var ourTextH2 = $('h2').not('.noresize');

		var currFontSizeH2 = ourTextH2.css('fontSize');

		var finalNumH2 = parseFloat(currFontSizeH2, 10);

		var stringEndingH2 = currFontSizeH2.slice(-2);

		

		var ourTextH3 = $('h3').not('.noresize');

		var currFontSizeH3 = ourTextH3.css('fontSize');

		var finalNumH3 = parseFloat(currFontSizeH3, 10);

		var stringEndingH3 = currFontSizeH3.slice(-2);

		

		if(this.id == 'largerFont') {

			finalNumP *= 1.1;

			finalNumH2 *= 1.1;

			finalNumH3 *= 1.1;

		}

		else if (this.id == 'smallerFont'){

			finalNumP /=1.1;

			finalNumH2 /= 1.1;

			finalNumH3 /= 1.1;

		}

		ourTextP.css('fontSize', finalNumP + stringEndingP);

		ourTextH2.css('fontSize', finalNumH2 + stringEndingH2);

		ourTextH3.css('fontSize', finalNumH3 + stringEndingH3);

	});

	$('#fontReset').click(function(){

		$('p').not('.noresize').css({'font-size':'12px'});

		$('h2').not('.noresize').css({'font-size':'18px'});

		$('#zoom h2').css({'font-size':'14px'});

		$('#headlines-infos h2').css({'font-size':'16px'});

		$('.actuPlusItem h2').not('.noresize').css({'font-size':'12px'});

		$('h3').not('.noresize').css({'font-size':'14px'});

		$('#zoom h3').not('.noresize').css({'font-size':'12px'});

		$('#headlines-infos h3').css({'font-size':'14px'});

		$('.actuPlusItem h3').not('.noresize').css({'font-size':'10px'});

	});

	

	/* TABS */

	$(".tab_content").hide();

	$("ul.tabs li:first").addClass("active").show();

	$(".tab_content:first").show();

	

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active");

		$(this).addClass("active");

		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href");

		$('#'+activeTab+'').fadeIn();

		

		/* PREVISIONS METEO */

		$('#forecastWeather').hide();

		$('#triggerPrevisions').text('voir les prévisions sur 3 jours');

		$('#triggerPrevisions').unbind('click').toggle(function(){

			$(this).text('masquer les prévisions');

			$('aside').css({'height':'auto'});

			$('#forecastWeather').slideDown('fast');},

		function(){

			$(this).text('voir les prévisions sur 3 jours');

			$('#forecastWeather').slideUp('fast');

			$(this).text('voir les prévisions sur 3 jours');

			if ($('aside').height() < $('#mainSection').height()){

				$('aside').css({'height':''+$('#mainSection').height()+'px'});

			}

		});

		return false;

	});

	

	/* LINKING FROM SELECTBOXES */

	$('#annuaires').change(function(){

		var url = $(this).val();
		if (url == "associations"){
			window.location.href="/decouvrir-nemours/associations";
		}
		else {
			window.location.href="/economie/annuaire-des-entreprises";	
		}

	})
	
	$('#teleprocedures').change(function(){

		window.location.href = $(this).val();
		
	})

	/* LANGUES 
	$('#langue').click(function(){
		if (!$('#google_translate_element:visible').length){
		$('#google_translate_element').fadeIn();
		$('.goog-te-combo').after('<span id="closeTranslate" title="close">X</span>')
		$(this).effect("transfer", { to: $("#google_translate_element")}, 1000).fadeOut();
		}
		else {
		$('#google_translate_element').fadeOut();	
		}
		return false;
	})
	$('#closeTranslate').live("click", function(){
		$('#google_translate_element').fadeOut();	
		$('#langue').fadeIn();
		$(this).remove();
	})
	*/	

	/* STYLE */

	$('#mainFooterMenu li:last').html($('#mainFooterMenu li:last').html().replace(" | ",""));

	$('#secondFooterMenu li:last').html($('#secondFooterMenu li:last').html().replace(" | ",""));

	if ($.browser.msie){$('#sommaire .vignetteSommaire:last').css({'border-bottom':'none'});}

	if (!$.browser.webkit){

		$('#sommaireRubrique li a').not('.current_page_item a').hover(function(){

			$(this).stop().animate({'color':'#003b81'},500)},

			function(){

			$(this).stop().animate({'color':'#fff'},500)

		});
		
		$('#sommaireRubrique li.current_page_item .children  a').hover(function(){
			var color = $(this).css('color');
			$(this).stop().animate({'color':'#003b81'},500)},

			function(){

			$(this).stop().animate({'color':'#006699'},500)

		});

		$('#acces_direct li a').hover(function(){

			$(this).stop().animate({'color':'#000'},500)},

			function(){

			$(this).stop().animate({'color':'#666'},500)

		});

	}

	$('#menuHeader ul li ul li a:last').hover(function(){

		$(this).css({'border-bottom':'none','margin':'0'});

	});

	

	/* FORMULAIRES */

		/* état-civil */

		var etatcivil = $('input[id*=acte_naissance]').not('input[id*=acte_naissance]:first').parent();

		etatcivil.hide();

		$('#acte_naissance').click(function(){

			$('#acte_naissance:checked').length ? etatcivil.fadeIn() : etatcivil.fadeOut();

		})

		var actemariage = $('input[id*=acte_mariage]').not('input[id*=acte_mariage]:first').parent();

		actemariage.hide();

		$('#acte_mariage').click(function(){

			$('#acte_mariage:checked').length ? actemariage.fadeIn() : actemariage.fadeOut();

		})

		var actedeces = $('input[id*=acte_deces]').not('input[id*=acte_deces]:first').parent();

		actedeces.hide();

		$('#acte_deces').click(function(){

			$('#acte_deces:checked').length ? actedeces.fadeIn() : actedeces.fadeOut();

		})

	

	/* COLORBOXES */
	var pattern= /desinscription/gi;
  var pattern2= /desinscriptionNewsletter/gi;
	if (window.location.href.match(pattern) && !window.location.href.match(pattern2)){
		$.colorbox({

		width:"300px",

		inline:true,

		href:"#newsletterSubscr",

		onClosed: function(){

			$('#newsletterSubscr fieldset').show();

			$('#emailInscrNewsletter').val('');

			$('#emailInscrNewsletter').removeClass('invalidField').parent().find('label').html('Tapez une adresse e-mail SVP');

			$('#callbackNewsletterMsg').html('');

		}

	});	
	}
	
	
	$('#newsletterRegisterBt').colorbox({

		width:"300px",

		inline:true,

		href:"#newsletterSubscr",

		onClosed: function(){

			$('#newsletterSubscr fieldset').show();

			$('#emailInscrNewsletter').val('');

			$('#emailInscrNewsletter').removeClass('invalidField').parent().find('label').html('Tapez une adresse e-mail SVP');

			$('#callbackNewsletterMsg').html('');

		}

	});

	

	$('a.thickbox, a.colorbox').colorbox({current:"{current} / {total}",maxWidth:"800px"}); // Effet sur images galeries
	
	$('a[href$="jpg"], a[href$="gif"], a[href$="png"]').colorbox({maxWidth:"800px",maxHeight:"900px"});

	

		/* PROCESSUS DANS COLORBOXES */

		

			/* INSCRIPTION NEWSLETTER */

			$('#inscrireNewsletter, #desinscrireNewsletter').click(function(){

				var action = $(this).attr('id');

				var email = $('#emailInscrNewsletter').val();

				var pattern= /localhost/gi;

				var root = location.protocol + '//' + location.host;

				var url;

				window.location.href.match(pattern) ? url = root+'/'+'nemours_start' : url = root;



				if (!isEmailValid(email)){

					$('#emailInscrNewsletter').addClass('invalidField').parent().find('label').html('<span>Tapez une adresse valide SVP</span>');

					return false;

				}

				$.ajax({

				   type: "POST",

				   url: ""+url+"/wp-content/themes/nemours/ajax/operations.php",

				   data: "action="+action+"&email="+email+"",

				   beforeSend: function(){$('#newsletterSubscr').append('<img src="'+url+'/wp-content/themes/nemours/habillage/ajax-loader.gif" class="loader">')},

				   success: function(msg){

					 $('#newsletterSubscr fieldset').hide();

					 $('.loader').remove();

					 $('#callbackNewsletterMsg').html(msg);

				   }

				});

			})

			$('#emailInscrNewsletter').keyup(function(){

				var curentVal = $(this).val();

				if (isEmailValid(curentVal) && $('#emailInscrNewsletter').hasClass('invalidField')){

					$('#emailInscrNewsletter').removeClass('invalidField').parent().find('label').html('Votre adresse est maintenant valide');															   

				}

			})

		
				// alerte home page
			// Add Scroller Object
			 if(document.getElementById('scroller_container')){
			  $jScroller.add("#scroller_container","#scroller","left",2);

			  // Start Autoscroller
			  $jScroller.start();
			 }
			
	// formulaire d'alerte		
	if(document.getElementById('alerteform')){
		$('#objet').change( function() {
			if($('#objet').val() == 'Nuisances animales'){
				$('#nuisances-animales').show().fadeIn(1500);
				$('#nuisances-olfactives').hide();
				$('#nuisances-voie-publique').hide();
			}
			else if($('#objet').val() == 'Nuisances sur la voie publique'){
				$('#nuisances-animales').hide();
				$('#nuisances-olfactives').hide();
				$('#nuisances-voie-publique').show().fadeIn(1500);
			}			
			else if($('#objet').val() == 'Nuisances olfactives'){
				$('#nuisances-animales').hide();
				$('#nuisances-olfactives').show().fadeIn(1500);
				$('#nuisances-voie-publique').hide();
			}
			else{
				$('#nuisances-animales').hide();
				$('#nuisances-olfactives').hide();
				$('#nuisances-voie-publique').hide();
			}
		});
		jQuery('.close').click(function(){
		    jQuery(this).parent().fadeOut(1500);
		    jQuery(this).parent().hide();
		    return false;
			
		});
	 }

})
