var IS_IE = ( navigator.appName.indexOf( "Microsoft Internet Explorer" ) > -1 );



var currChap = null;

function switchChapter( chap )
{
    var elem = document.getElementById( chap );
    
    if ( currChap == null )
        currChap = document.getElementById( "no_chapter" );
    
    currChap.style.display = "none";
    currChap = elem;
    currChap.style.display = "block";
}



var eventHandlersApplied = false;

function applyAdditionalEventHandlers( menuElem )
{
    if ( eventHandlersApplied )
        return;
    
    eventHandlersApplied = true;
    
    var tds = menuElem.getElementsByTagName( "td" );
    
    for ( var i = 0; i < tds.length; i++ )
    {
        tds[ i ].onmouseover = showPopup;
        tds[ i ].onmouseout = markPopupHidden;
    }
}

var popupVisible = false;
var nextOverIgnored = false;

function showPopup()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "book-popup" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}

function showPopup2()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "book-popup2" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}

function showPopup3()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "book-popup3" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}

function showPopup3b()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "book-popup4" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}

function markPopupHidden()
{
    popupVisible = false;
    window.setTimeout( "applyPopupHidden()", 10 );
    
    // IE-fix!
    if ( IS_IE )
    {
        nextOverIgnored = true;
    }
}

function hidePopup()
{
    var menuElem = document.getElementById( "book-popup" );
    menuElem.style.display = "none";
    var menuElem2 = document.getElementById( "book-popup2" );
    menuElem2.style.display = "none";
    var menuElem3 = document.getElementById( "book-popup3" );
    menuElem3.style.display = "none";
    var menuElem3b = document.getElementById( "book-popup4" );
    menuElem3b.style.display = "none";
    var menuElem4 = document.getElementById( "home-popup" );
    menuElem4.style.display = "none";
    var menuElem5 = document.getElementById( "faq-popup" );
    menuElem5.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup2()
{
    var menuElem2 = document.getElementById( "book-popup2" );
    menuElem2.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup3()
{
    var menuElem3 = document.getElementById( "book-popup3" );
    menuElem3.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup3b()
{
    var menuElem3b = document.getElementById( "book-popup4" );
    menuElem3b.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup4()
{
    var menuElem = document.getElementById( "book-popup" );
    menuElem.style.display = "none";
    var menuElem2 = document.getElementById( "book-popup2" );
    menuElem2.style.display = "none";
    var menuElem3 = document.getElementById( "book-popup3" );
    menuElem3.style.display = "none";
    var menuElem3b = document.getElementById( "book-popup4" );
    menuElem3b.style.display = "none";
    var menuElem4 = document.getElementById( "faq-popup" );
    menuElem4.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup5()
{
    var menuElem = document.getElementById( "book-popup" );
    menuElem.style.display = "none";
    var menuElem2 = document.getElementById( "book-popup2" );
    menuElem2.style.display = "none";
    var menuElem3 = document.getElementById( "book-popup3" );
    menuElem3.style.display = "none";
    var menuElem3b = document.getElementById( "book-popup4" );
    menuElem3b.style.display = "none";
    var menuElem4 = document.getElementById( "home-popup" );
    menuElem4.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function hidePopup6()
{
    var menuElem = document.getElementById( "faq-popup" );
    menuElem.style.display = "none";
    var menuElem2 = document.getElementById( "home-popup" );
    menuElem2.style.display = "none";
    
    // IE-fix!
    nextOverIgnored = false;
}

function applyPopupHidden()
{
    if ( popupVisible )
        return;
    
    hidePopup();
}

function hidePopu()
{
  window.setTimeout("hidePopup()", 400);
}

function showPopup_home()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "home-popup" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}

function showPopup_faq()
{
    // IE-fix!
    if ( nextOverIgnored )
    {
        nextOverIgnored = false;
        return;
    }
    
    var menuElem = document.getElementById( "faq-popup" );
    
    menuElem.style.display = "block";
    
    popupVisible = true;
    
    //applyAdditionalEventHandlers( menuElem );
}



