var allPopups = new Array(
  'book-popup', 'book-popup2', 'book-popup3', 'book-popup4', 'home-popup', 'faq-popup', 'bestellendownloads-popup', 'faq-popup2', 'faq-popup3', 
  'faq-popup4', 'faq-popup5', 'faq-popup6', 'faq-popup_intoleranzen'
);

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;

/* open popup with given name */
function openPopup(elem) {
   if ( nextOverIgnored ) {
        nextOverIgnored = false;
        return;
    }
    var menuElem = document.getElementById( elem );
    menuElem.style.display = "block";
    popupVisible = true;
}

/* hide all popups in given names array */
function hidePopups(elemArray) {
  for(var z = 0; z < elemArray.length; z++) {
    var menuElem = document.getElementById( elemArray[z] );
    menuElem.style.display = "none";
  }  
}

/* hides all popups on page, if name is in array on top of this script */
function hideAllPopups() {
  hidePopups(allPopups);  
}

function markPopupHidden() {
    popupVisible = false;
    window.setTimeout( "applyPopupHidden()", 10 );
    
    // IE-fix!
    if ( IS_IE ) {
        nextOverIgnored = true;
    }
}

function applyPopupHidden() {
    if ( popupVisible )
        return;
    hideAllPopups();
}

function hidePopu() {
  window.setTimeout("hideAllPopups()", 400);
}




