$(document).ready(function(){

	//PSC - pdf in new window
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});
	
	
	///////////////////////////////////////////////////////////////////////////////////////
	// MENU LEFT + SECTION ACCORDION
	///////////////////////////////////////////////////////////////////////////////////////
	
	$('.li_first > a').click(function(){
		$('.li_first > a').css({'color' : '#bababa'});
		$(this).css({'color' : '#4d4d4d'});
		$(this).next('ul').removeClass('active');

		$('#menu_left ul li .active, #menu_left ul li .off').slideUp();
		$('#menu_left ul li ul').addClass('active');
		
		$(this).next('ul').slideDown();
		
		//return false;
	});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// PATRIMOINE IMMOBILIER + LIEN
	///////////////////////////////////////////////////////////////////////////////////////
	
	$('.sub_title').click(function(){
		$('.sub_title').removeClass('sub_title_active');
		$(this).addClass('sub_title_active');
		
		$('.sub_title').next('.content_section').slideUp();
		$(this).next().slideDown();
	});
	
	$('.immeuble_title_container').click(function(){
		$('.immeuble_desc_container').slideUp();
		$('#desc_immeuble_' + this.id).slideDown();
	});
	
	$('.link_all').fadeOut();
	$('.link_ref_6').fadeIn();
	
	$('.link_cat').click(function(){
		$('.sub_title').removeClass('sub_title_active');
		$(this).addClass('sub_title_active');
	
		$('.link_all').fadeOut();
		$('.link_' + this.id).fadeIn();
	});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// SLIDESHOW OPTION
	///////////////////////////////////////////////////////////////////////////////////////
	
	var COOKIE_NAME = 'slideshow';
	if($.cookie(COOKIE_NAME) == "hide") {
		$('#flash_baner').hide();
		$('.hide_slideshow').hide();
		$('.show_slideshow').show();
	}

	$('.hide_slideshow').click(function(){
		$('#flash_baner').slideUp();
		$(this).hide();
		$('.show_slideshow').show();
		var COOKIE_NAME = 'slideshow';
        var options = { path: '/', expires: 360 };
        $.cookie(COOKIE_NAME, 'hide', options);
        return false;
	});
	
	$('.show_slideshow').click(function(){
		$('#flash_baner').slideDown();
		$(this).hide();
		$('.hide_slideshow').show();
		var COOKIE_NAME = 'slideshow';
        var options = { path: '/', expires: 360 };
        $.cookie(COOKIE_NAME, 'show', options);
        return false;
	});
	
	$('#notre_mandat').toggle(function(){
		$('#mandat_container').slideDown();
	}, function(){
		$('#mandat_container').slideUp();
	});
	
	$("#date_de_depot").colorbox({width:"800px", height:"80%", iframe:true});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// GROWL NEWSLETTER
	///////////////////////////////////////////////////////////////////////////////////////
	
	 var newsletter_options = { 
        success:       showResponseNewsletter,  // post-submit callback
        beforeSubmit: validateNewsletter
    }; 
	
	$('#newsletter_inscription').ajaxForm(newsletter_options);
	
	function showResponseNewsletter(responseText, statusText)  {  
	    $.gritter.add({
			title: 'Courriel enregistré',
			text: "Merci de vous êtres inscrit au bulletin d'information",
			sticky: false, 
			time: 4000
		});
	} 
	
	function validateNewsletter(formData, jqForm, options){
		var form = jqForm[0]; 
		if (!form.courriel.value) { 
		    $.gritter.add({
				title: 'Erreur',
				text: "Veuillez inscrire votre courriel",
				sticky: false, 
				time: 4000
			});
	        return false; 
	    }
		var pattern = 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);
		if(!pattern.test(form.courriel.value)) {
			 $.gritter.add({
					title: 'Erreur',
					text: "Vous devez entrer une adresse de courriel valide",
					sticky: false, 
					time: 4000
				});
			 	
		        return false; 
		}
		form.courriel.value = '';
	}

	///////////////////////////////////////////////////////////////////////////////////////
	// LIGHTBOX + GALLERY EVENEMENT
	///////////////////////////////////////////////////////////////////////////////////////
	
	$("#video_colorbox").colorbox();
	
	$(".link_colorbox").colorbox({
		opacity: 0.65
	}); 
	
	$(".thumbnails_event").hover(function(){
		$(this).animate({'opacity' : 0.7});
		}, function() {
		$(this).animate({'opacity' : 1});
	});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// LIGHTBOX COMMUNIQUE EVENT + SEND MAIL
	///////////////////////////////////////////////////////////////////////////////////////
	/*
	$(".communique_title").each(function(){
			$(this).colorbox({
			width: "800px",
			inline: true, 
			href: "#" + $(this).next().children().attr('id'),
			rel: "group_evenement",
			current: "Communiqué {current} de {total}",
			opacity: 0.65
		})
	});
	*/
	$("#link_send_to_friend").colorbox({width:"50%", inline:true, href:"#send_to_friend_container"});
	
	$('#send_to_friend').ajaxForm(function(){
		alert("Merci ! Votre ami(e) a bien reçu votre message.\nVous pouvez envoyer cette page à un(e) autre amie(e).");
		$('#send_to_friend .clearme').val('');
	});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// RECHERCHE ONGLET
	///////////////////////////////////////////////////////////////////////////////////////
	
	$(".title_search").click(function(){
		$(".my_search_tab").fadeOut();
		$("#tab_" + this.id).fadeIn();
		
		$('.title_search').removeClass('title_search_actif');
		$(this).addClass('title_search_actif');
	});
	
	///////////////////////////////////////////////////////////////////////////////////////
	// TEXT RESIZE
	///////////////////////////////////////////////////////////////////////////////////////
	
	/*// Reset Font Size
	var originalFontSize = $('body').css('font-size');
	$(".resetFont").click(function(){
		$('body').css('font-size', originalFontSize);
	});
	
	// Increase Font Size
	$("#size_switch_max").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('body').css('font-size', newFontSize);
		return false;
	});
		
	// Decrease Font Size
	$("#size_switch_min").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('body').css('font-size', newFontSize);
		return false;
	});*/
	
	$('.size_switcher').toggle(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = 14;
		$('body').css('font-size', newFontSize);
		return false;
	}, function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = 11;
		$('body').css('font-size', newFontSize);
		return false;
	});
	  
	///////////////////////////////////////////////////////////////////////////////////////
	// PRINT
	///////////////////////////////////////////////////////////////////////////////////////
	 
	$('#print').click(function() {
		window.print();
		return false;
	});


	
});

