$(document).ready(function(){
    $('#morenews_href').click(function(){
        $.post('modules/news.php', {older : ''}, function(output){
            $('#morenews').html(output).animate({
                height : 'toggle'
            }, 'normal');
        });
    });

     //Ajoute les animations de slide à chaque news
    $(function(){
       var slideHeight = 60;
       $('.news').each(function(index){
            var defHeight =  $(this).find('.news-content').height();
            if(defHeight >= slideHeight){
                $(this).find('.news-content').css('height' , slideHeight + 'px');
                $(this).find('.read-more').append('<a href="#">Lire la suite</a>');
                $(this).find('.read-more a').click(function(){
                        var ref = $(this).parent().parent();
                        var curHeight = ref.find('.news-content').height();
                        if(curHeight == slideHeight){
                                ref.find('.news-content').animate({
                                  height: defHeight
                                }, "normal");
                                ref.find('.read-more a').html('Masquer');
                                //$('#gradient').fadeOut();
                        }else{
                                ref.find('.news-content').animate({
                                  height: slideHeight
                                }, "normal");
                                ref.find('.read-more a').html('Lire la suite');
                                //$('#gradient').fadeIn();
                        }
                        return false;
                });
            }
       })
    });

    $(function(){
        $('#oldnews').hide();
        $('#read-more-news a').click(function(){
            //Animation d'apparition
            $('#oldnews').animate({
                height : 'toggle'
            }, 'normal');

            //Changement du texte
            $('#read-more-news a').html($('#read-more-news a').html() == 'Voir plus de news' ? 'Masquer' : 'Voir plus de news');

        })
    })
});
