

(function($) {
	
jQuery(document).ready(function(){
		
	dst_unfolding_div();

});


//ouverture ou fermeture d'une div si besoin

function dst_unfolding_div(){
	
	dst_size_post();
	
};// end function dst_unfolding_div



//récupération de la taille de la div
function dst_size_post(){
	
	$.each( $('#primary .equipe') , function(index, value){
		
		//postid = $(this).attr('data-postid');
		var post = $(this);
		
		//calcul de la taille du masque et du contenant
		var post_height = $(this).children('.mask').height();
		var inner_height = $(this).find('.mask p.equipe-presentation').height();
		
		//création d'un tableau associatif (s'utilise comme un objet) pour stocker les dimensions du masque et du contenant
		var data = {
			
			'postheight' : post_height,
			'innerheight' : inner_height
		
		};
		
		//pasage des données en data
		$(this).data('dst_unfolding', data);
		
		//on vérifie la taille des 2 div
		var read_more = $(this).find('.readmore');
		
		//si taille contenant plus petite que le masque alors on enlève le lien lire la suite
		if(post_height > inner_height){ 
			
			read_more.addClass('not-readmore'); 
			post.find('sep-featured').addClass('sep_read');
			
			//réattribue la taille par défaut de .post_inner + 10px d'espace en-dessous
			$(this).children('.mask').height( inner_height + 10 );
		}
		
		
		//fonction executée lors du click	
		var dst_unfold_post = function(e){
							   
		    var pdata = $(this).data('dst_unfolding');
			
			
			// si article fermé
			if(!post.hasClass('dstxo_layout_open') ){
				
				post.children('.mask').animate({ height: pdata.innerheight + 'px' }, 250, function(){
																								   
						$(this).children('.mask').css({height : pdata.innerheight + 'px'});
				});
				
				post.addClass('dstxo_layout_open');
				
			}// sinon...
			else{
				
				post.children('.mask').animate({ height: pdata.postheight + 'px' }, 250, function(){
																								   
						$(this).children('.mask').css({height : pdata.postheight + 'px'});
				});
				
				post.removeClass('dstxo_layout_open');	
				
			}
			
			//return false pour éviter de rediriger vers le lien actuel
			return false;
			
		}; // end function dst_unfold_post
	
		
		
		//click sur le lien lire la suite
		$(this).find('.readmore').click(function(e){ 
			
			dst_unfold_post.call($(this).parents('.equipe')); 
			e.preventDefault();
		
		});
		
	});//end each
	
}//end function dst_size_post


})(jQuery);
