function load_page(page)
{
    console.log(page);
    $.ajax({
        url: page,
        type: 'GET',
        dataType: 'html',
        timeout: 2000,
        error: function(){
            window.open(page);
        },
        success: function(html){
            var main_content = $('#main_content');
            main_content.empty().append(html);
            $('.toggler', main_content);
            ajaxify_links();
        }
    });
};

function ajaxify_links()
{
    $('a.next, a.prev').click(function(event){
        var href = $(this).attr('href');
    console.log(href);
        
        event.preventDefault();
		
        $('.toggler').fadeOut('slow', function(){
            load_page(href+'/ajax')
        });
    });
}


$(document).ready(function()
{
    ajaxify_links();
});
