$(document).ready(function(){
	
	// Rend la box entierement cliquable
	boxHomeEncart = $('.box-home-encart');
	boxHomeEncart.click(function(){
		window.location.href = $('a',this).attr('href');
	});
	boxHomeEncart.hover(function(){
		$(this).css('cursor','pointer');
		$('a',this).css('text-decoration','underline');
	}, function(){
		$('a',this).css('text-decoration','none');
	});
	
	// Adapte la hauteur des colonnes du milieu et de droite 
	heightColLeft = $('#col-left').height()-parseInt($('.box-home-encart').css('margin-bottom'));
	if($('#col-main').height() < heightColLeft)
		$('#col-main').height(heightColLeft-parseInt($('#col-main').css('padding-top'))-parseInt($('#col-main').css('padding-bottom')));
	if($('#col-right').height() < $('#col-main').height())
		$('#col-right').height($('#col-main').height()+parseInt($('#col-main').css('padding-top'))+parseInt($('#col-main').css('padding-bottom'))-
				parseInt($('#col-right').css('padding-top'))-parseInt($('#col-right').css('padding-bottom')));
	
	// Initialisation fancybox
	$(".realisation-zoomed").fancybox({
		margin:10,
		centerOnScroll : true,
		scrolling:'no'
	});
	
	// Rend la box entierement cliquable
	boxPrds = $('.box-prd');
	boxPrds.click(function(){
		window.location.href = $('a',this).attr('href');
	});
	boxPrds.hover(function(){
		$(this).css('cursor','pointer');
		$('a',this).css('text-decoration','underline');
	}, function(){
		$('a',this).css('text-decoration','none');
	});
	
	boxActus = $('.box-actu');
	boxActus.click(function(){
		window.location.href = $('a',this).attr('href');
	});
	boxActus.hover(function(){
		$(this).css('cursor','pointer');
		$('a',this).css('text-decoration','underline');
	}, function(){
		$('a',this).css('text-decoration','none');
	});
	
	// Initialisation fancybox
	$(".prd-zoomed").fancybox({
		margin:10,
		centerOnScroll : true,
		scrolling:'no'
	});
	$(".fancyimg").fancybox({
		margin:10,
		centerOnScroll : true,
		scrolling:'no'
	});
	
	var firstClickDevis = true;
	$('a.lnk-ask-infos').click(function(){
		if( $('.contact-field').css('display') == 'none'){
			$('#col-main').css('height','');
			$('.contact-field').slideDown('slow');
			if(firstClickDevis){
				firstClickDevis = false;
				pageTracker._trackPageview("/devis");
			}
		}
		else
			$('.contact-field').slideUp('slow');
	});
	
	function onChangeDep(){
		if( $('select#dep option:selected').attr("value") == '' )
			$('select#ville option').show();
		else{
			$('select#ville option').hide();
			$('select#ville option.dep-'+ $('select#dep option:selected').attr("value") ).show();
			$('select#ville option.all' ).show();
			if( $('select#ville option:selected' ).attr("class") != 'dep-'+ $('select#dep option:selected').attr("value") )
			   $('select#ville option:selected' ).removeAttr("selected");
		}
	}
	
	onChangeDep();
	$('select#dep').change(function(){3
		onChangeDep();
	});
	
	$(".box-actu-paire").hide()
	$(".box-actu-paire.current").show()
	var currentActu = 0;
	function nextActu(){
		currentActu++;
		if( currentActu == $(".box-actu-paire").length)
			currentActu = 0;
		$(".box-actu-paire.current").fadeOut("500",function(){
			$(this).removeClass("current");
			var box = $(".box-actu-paire");
			$(box[currentActu]).fadeIn("500").addClass("current");
		});
	}
	var timer  = setInterval(nextActu, 7000);
	
	$("#menu .contact").prev().css("background-image","none");
	
	/* Validation w3C */
	$('.addthis_button_google_plusone').attr("g:plusone:count","false");
	$('.addthis_button_google_plusone').attr("g:plusone:size","medium");
	$('.addthis_button_facebook_like').attr("fb:like:action","recommend");
	$('.addthis_button_facebook_like').attr("fb:like:width","100");
	$('.addthis_button_tweet').attr("tw:via","@delrieuherve");
	$('.addthis_button_tweet').attr("tw:count","none");
	
	
});
