$(function() { // On appelle la fonction au chargement de la page
	
	// Elements graphiques (corner)
	$('#videos-gratuites').corner('keep 5px');
    $('#autres-videos').corner('keep 5px');
    $('.side-bloc').corner('keep 5px');
    $('.cadre').corner('keep 3px');   
    $('#view-video-content').dialog({ autoOpen: false, width:890, height:1110, zindex: 3999, maxHeight:500, bgiframe: true, position:'bottom'});
    $('.telecharger a').click(openPdv);    
	
    // Ajax
    registerAjaxSetUp(); // Fonction qui gère automatiquement les gif de chargement ajax
    $('.numeros-pagination a').live('click',changeList);
    
});

function openPdv(){
    $('#view-video-content').dialog('open');
    $('#view-video-content iframe').height("1110px");
    return false;    
}

function registerAjaxSetUp(){ 
    $('#loader').ajaxSend(function(){
        $(this).show();
    });
    $('#loader').ajaxSuccess(function(){
        $(this).hide();
    });    
}

function changeList(){      
    var params=$(this).attr('href');
    // Fondu de la div actuelle
    $('#fonduJquery').animate({
        opacity:0
    },500);
    $.ajax({url:params,
            data:'',
            success:function(response){
                $('#liste-videos-gratuites').html(response);
                $('#fonduJquery').animate({
                    opacity:1
                },300);
                registerAjaxSetUp();
            }
    });
    return false;    
}

