//= require vendor/toc/jquery.tableofcontents.js
//= require controllers/style_pages/dialogs.js

(function()
{
    var page = jQuery(document);

    page.on('contentloaded', function(e)
    {
        var target = jQuery(e.target);
        if (target[0] != page[0])
        {
            return;
        }

        var h1 = target.find('main h1').first();
        if (h1.length < 1)
        {
            return;
        }

        var toc = jQuery('<ul />').addClass('table-of-contents').insertAfter(h1);

        toc.tableOfContents( jQuery('main'), { startLevel: 2 } );

    });



}());
