$(document).ready(function() {

n=0;$('.bigforum').each(function( n ) {$(this).attr('rel',n++);});

$('.down').css('cursor','pointer').click(function() {
    $('.down').hide();
    $('.up').hide();
    var parent=$(this).parent().parent().parent();
    $('.bigsep').remove();
    if(parent.attr('rel')<21) {
        //déplacement de l'élément suivant :
        parent.next().insertAfter($('.bigforum').eq(parseInt(parent.attr('rel'))+1));
        parent.hide().insertAfter($('.bigforum').next().eq(parseInt(parent.attr('rel'))+1)).show('slow');
        
        $('.bigforum').eq(parseInt(parent.attr('rel'))).attr('rel',parent.attr('rel'));
        parent.attr('rel',parseInt(parent.attr('rel'))+1);
        //$('.bigforum').each(function() {console.log($(this).attr('rel'));});
        save_ordre_home();
    }
    $('.down').show();
    $('.up').show();
});

$('.up').css('cursor','pointer').click(function() {
    $('.down').hide();
    $('.up').hide();
    var parent=$(this).parent().parent().parent();
    $('.bigsep').remove();
    if(parent.attr('rel')>=0) {
        //deplacement de l'element précedant
        parent=parent.prev().prev();
        parent.next().insertAfter($('.bigforum').eq(parseInt(parent.attr('rel'))+1));
        parent.hide().insertAfter($('.bigforum').next().eq(parseInt(parent.attr('rel'))+1)).show('slow');
        
        $('.bigforum').eq(parseInt(parent.attr('rel'))).attr('rel',parent.attr('rel'));
        parent.attr('rel',parseInt(parent.attr('rel'))+1);
        //$('.bigforum').each(function() {console.log($(this).attr('rel'));});
        save_ordre_home();
    }
    $('.down').show();
    $('.up').show();
});

});

save_ordre_home=function() {
    var ordreforum=""; 
    $('.bigforum').each(function() {if(ordreforum!="") ordreforum+=",";ordreforum += $(this).attr('id');});
    setCookie(document, 'nfordrehome', ordreforum, rdate());
    $.ajax({
        url: '/api/forum/ajax.php?act=save_ordre_home',
        type: 'post',
        data : 'ordreforum='+ordreforum
        });
};
unsave_ordre_home=function() {
    setCookie(document, 'nfordrehome', '', rdate());
    $.ajax({
        url: '/api/forum/ajax.php?act=save_ordre_home',
        type: 'post',
        data : 'ordreforum=&empty=1',
        success:function(){document.location='index.php';}
        });
};
