document.getElementById('content').style.minHeight = document.getElementById('sidenav').offsetHeight + 'px';

var text = g_text[g_cursec];

if(text) {
    document.title += ' - ' + text.name;

    // Output the section headers
    if(text.sectionName)
        document.write('<h1>' + text.sectionName + '</h1>');
    if(text.subsectionName)
        document.write('<h2>' + text.subsectionName + '</h2>');
    if(text.contentName)
        document.write('<h3>' + text.contentName + '</h3>');
    
    // Output the content for the selected section
    if(text.html) {
        // Real section; output the html
        document.write(text.html);
    } else if(text.section) {
        // Output available subsections
        document.write('<ul>');
        for(var i = 0; i < text.section.subsections.length; ++i) {
            if(text.section.subsections[i].name) {
                document.write('<li><h2><a href="#" onClick="LoadSection(\'' + text.section.subsections[i].id + '\'); return false;">' +
                               text.section.subsections[i].name + '</a></h2></li>');
            }
        }
        document.write('</ul>');
    } else if(text.subsection) {
        if(text.subsection.contents.length == 1 && !text.subsection.contents[0].name && g_text[text.subsection.contents[0].id]) {
            if(g_text[text.subsection.contents[0].id].html) {
                document.write(g_text[text.subsection.contents[0].id].html);
            }
        } else {
            // Output available contents
            document.write('<ul>');
            for(var i = 0; i < text.subsection.contents.length; ++i) {
                if(text.subsection.contents[i].name) {
                    document.write('<li><h3><a href="#" onClick="LoadSection(\'' + text.subsection.contents[i].id + '\'); return false;">' +
                                   text.subsection.contents[i].name + '</a></h3></li>');
                }
            }
            document.write('</ul>');
        }
    }
} else {
    // Output the full table of contents
    for(var iSec = 0; iSec < g_sections.length; ++iSec) {
        document.write('<h1><a href="#" onClick="LoadSection(\'' + g_sections[iSec].id + '\'); return false;">' +
                       g_sections[iSec].name + '</a></h1>');
        
        document.write('<ul>');
        // Subsections
        for(var iSub = 0; iSub < g_sections[iSec].subsections.length; ++iSub) {
            if(g_sections[iSec].subsections[iSub].name) {
                document.write('<li><h2><a href="#" onClick="LoadSection(\'' + g_sections[iSec].subsections[iSub].id + '\'); return false;">' +
                               g_sections[iSec].subsections[iSub].name + '</a></h2></li>');
            }
            
            // Subcontents
            if(g_sections[iSec].subsections[iSub].contents.length > 0 && g_sections[iSec].subsections[iSub].contents[0].name) {
                document.write('<ul>');
                for(var iCnt = 0; iCnt < g_sections[iSec].subsections[iSub].contents.length; ++iCnt) {
                    document.write('<li><h3><a href="#" onClick="LoadSection(\'' + g_sections[iSec].subsections[iSub].contents[iCnt].id + '\'); return false;">' +
                                   g_sections[iSec].subsections[iSub].contents[iCnt].name + '</a></h3></li>');
                }
                document.write('</ul>');
            }
        }
        document.write('</ul>');
    }
}
