// {{MadCap}} //////////////////////////////////////////////////////////////////
// Copyright: MadCap Software, Inc - www.madcapsoftware.com ////////////////////
////////////////////////////////////////////////////////////////////////////////
// <version>1.0.0.0</version>
////////////////////////////////////////////////////////////////////////////////

var gInit   = false;

function Init()
{
    if ( gInit )
    {
        return;
    }
    
    gInit = true;
    
    //
    
    var masterHS	= parent.parent.GetMasterHelpSystem();
    
    masterHS.LoadGlossary();
    
    // IE 6.0+ bug. When loading the glossary, we replace the document's body with XML. For some reason, this causes
    // the 11th line of the document to not render in IE. This works around that issue.
    
    if ( document.body.currentStyle && masterHS.IsMerged() )
    {
        setTimeout( "SetGlossaryIFrameWidth();", 50 );
    }
}

function SetGlossaryIFrameWidth()
{
    parent.document.getElementById( "glossary" ).style.width = "100%";
}

function DropDownTerm( anchorName )
{
    var anchors = document.getElementsByTagName( "a" );
    
    for ( var i = 0; i < anchors.length; i++ )
    {
        var anchor  = anchors[i];
        
        if ( anchor.name == anchorName )
        {
            if ( FMCGetChildNodesByTagName( anchor.parentNode.parentNode, "DIV" )[1].style.display == "none" )
            {
                FMCDropDown( anchor.parentNode.getElementsByTagName( "a" )[0] );
            }
            
            break;
        }
    }
}

function ScrollToVisible( node )
{
    var oldPosition     = FMCGetComputedStyle( node, "position" );
    
    node.style.position = "";
    
    //
    
    var scrollTop       = FMCGetScrollTop( window );
    var scrollBottom    = scrollTop + FMCGetClientHeight( window );
    var scrollLeft      = FMCGetScrollLeft( window );
    var scrollRight     = scrollLeft + FMCGetClientWidth( window );
    var nodeTop         = node.offsetTop;
    var nodeLeft        = node.offsetLeft;
    var nodeHeight      = node.offsetHeight;
    var nodeWidth       = node.getElementsByTagName( "a" )[0].offsetWidth;
    
    if ( nodeTop < scrollTop )
    {
        FMCSetScrollTop( window, nodeTop );
    }
    else if ( nodeTop + nodeHeight > scrollBottom )
    {
        FMCSetScrollTop( window, Math.min( nodeTop, nodeTop - FMCGetClientHeight( window ) + nodeHeight ) );
    }
    
    if ( nodeLeft < scrollLeft )
    {
        FMCSetScrollLeft( window, nodeLeft );
    }
    else if ( nodeLeft + nodeWidth > scrollRight )
    {
        FMCSetScrollLeft( window, Math.min( nodeLeft, node.offsetLeft - FMCGetClientWidth( window ) + nodeWidth ) );
    }
    
    //
    
    node.style.position = oldPosition;
}

