$(document).ready(function(){
	
	$('.socialicon').live({
		mouseover : function() {
			$(this).animate({'opacity':'0.3'}, 250);
		},
		mouseout : function() {
			$(this).animate({'opacity':'1'}, 250);
		}
	});
	
	var affiche_exp = "";
	var affiche_sect = "";
	var affiche = "";
	
	$('#filtre-expertise a').click(function(e) {
		
		$('#filtre-expertise a').each(function() {
			$(this).removeClass("filtre");
		});
		$(this).addClass("filtre");
		
		if ($(this).attr('rel') != affiche_exp) {
			affiche_exp = $(this).attr('rel');
			affichage();
			return false;
		}
	});
	
	$('#filtre-secteur a').click(function(e) {
		
		$('#filtre-secteur a').each(function() {
			$(this).removeClass("filtre");
		});
		$(this).addClass("filtre");
		
		if ($(this).attr('rel') != affiche_sect) {
			affiche_sect = $(this).attr('rel');
			affichage();
			return false;
		}
	});
	 

	function affichage (){
		
		var vit = 1000;
		
		affiche = affiche_exp +"-"+affiche_sect;
		
		var cpt = 0;
			$("#works-list div.bloc").each(function() {
				if($(this).css('display')=="block") {
					$(this).fadeOut(500);
				}
			});
			$("#works-list div.bloc").delay(500).each(function() {
				if($(this).attr("rel") == affiche) {
					$(this).fadeIn(vit);
					cpt++;
				} else if( $(this).attr("rel").split('-')[0] == affiche_exp && affiche_sect=="") {
					$(this).fadeIn(vit);
					cpt++;
				} else if( $(this).attr("rel").split('-')[1] == affiche_sect && affiche_exp=="") {
					$(this).fadeIn(vit);
					cpt++;
				} 
				else if(affiche == "" || affiche == "-") {
					$(this).fadeIn(vit);
					cpt++;
				}
				
				/* if(cpt%2==0) {
					$(this).addClass("last");
				} else {
					$(this).removeClass("last");
				} */
			});
	}
	
	
	
	
	jQuery('a.reload').live("click", function(event){
		var url = jQuery(this).attr('href');

		jQuery("#news").addClass('loading');
		jQuery("#news").html('<h2>+ de News</h2>');
		
		jQuery.ajax({
			"url":url,
			"success":function(data){
				var $corps = jQuery(data);
				jQuery("#news").removeClass('loading');
				jQuery("#news").html($corps.find("#news").html());
			}	
		});
	
		event.preventDefault();
		return false;
	});
	
	
});
