// {{MadCap}} //////////////////////////////////////////////////////////////////
// Copyright: MadCap Software, Inc - www.madcapsoftware.com ////////////////////
////////////////////////////////////////////////////////////////////////////////
// <version>1.0.0.0</version>
////////////////////////////////////////////////////////////////////////////////

var gInit					= false;
var gVisibleItems           = 6;
var gcMaxVisibleItems       = 6;
var gcAccordionItemHeight   = 28;
var gActiveItem             = null;
var gActiveIcon             = null;
var gActiveIFrame           = null;
var gAccordionItems         = new Array();
var gAccordionIcons         = new Array();
var gIFrames                = new Array();
var gcDefaultID             = 0;
var gcDefaultTitle          = "Table of Contents";

window.onresize = BodyOnResize;

function BodyOnResize()
{
    parent.frames["toolbar"].document.getElementById( "AccordionTitle" ).style.width = Math.max( FMCGetClientWidth( window ), 0 ) + "px";
    SetIFrameHeight();
}

function CalcVisibleItems( y )
{
    var accordionTop  = (gVisibleItems + 1) * gcAccordionItemHeight;
    var itemOffset    = (y - accordionTop >= 0) ? Math.floor( (y - accordionTop) / gcAccordionItemHeight ) : Math.ceil( (y - accordionTop) / gcAccordionItemHeight );
    
    gVisibleItems = Math.max( Math.min( gVisibleItems + itemOffset, gcMaxVisibleItems ), 0 );
    
    // Debug
    //window.status = accordionTop + ", " + y + ", " + itemOffset + ", " + gVisibleItems;
}

function RefreshAccordion()
{
    SetIFrameHeight();
    
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
        gAccordionItems[i].style.display = (i < gVisibleItems) ? "block" : "none";
        gAccordionIcons[i].style.visibility = (i < gVisibleItems) ? "hidden" : "visible";
    }
}

function ExpandAccordionDrag( e )
{
    // Debug
    //window.status += "d";
    
    if ( !e ) { e = window.event; }
    
    var currY = FMCGetClientHeight( window ) - e.clientY;
    
    CalcVisibleItems( currY );
    RefreshAccordion();
}

function ExpandAccordionEnd( e )
{
    // Debug
    //window.status += "e";
    
    if ( document.body.releaseCapture )
    {
        document.body.releaseCapture();
        
        document.body.onmousemove = null;
        document.body.onmouseup = null;
    }
    else if ( document.removeEventListener )
    {
        document.removeEventListener( "mouseover", ExpandAccordionMouseover, true );
        document.removeEventListener( "mousemove", ExpandAccordionDrag, true );
        document.removeEventListener( "mouseup", ExpandAccordionEnd, true );
        frames[gActiveIFrame.id].document.removeEventListener( "mousemove", ExpandAccordionDrag, true );
        frames[gActiveIFrame.id].document.removeEventListener( "mouseup", ExpandAccordionEnd, true );
    }
    
    var accordionExpander	= document.getElementById( "AccordionExpander" );
    
    accordionExpander.style.backgroundImage = "url(" + FMCGetMCAttribute( accordionExpander, "MadCap:outImage" ) + ")";
    
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
        gAccordionItems[i].style.cursor = (navigator.appVersion.indexOf( "MSIE 5.5" ) == -1) ? "pointer" : "hand" ;
    }
    
    SetupAccordion();
}

function ExpandAccordionMouseover( e )
{
    e.stopPropagation();
}

function ExpandAccordionStart()
{
    // Debug
    //window.status += "s";
    
    if ( document.body.setCapture )
    {
        document.body.setCapture();
        
        document.body.onmousemove = ExpandAccordionDrag;
        document.body.onmouseup = ExpandAccordionEnd;
    }
    else if ( document.addEventListener )
    {
        document.addEventListener( "mouseover", ExpandAccordionMouseover, true );
        document.addEventListener( "mousemove", ExpandAccordionDrag, true );
        document.addEventListener( "mouseup", ExpandAccordionEnd, true );
        frames[gActiveIFrame.id].document.addEventListener( "mousemove", ExpandAccordionDrag, true );
        frames[gActiveIFrame.id].document.addEventListener( "mouseup", ExpandAccordionEnd, true );
    }
    
    var accordionExpander	= document.getElementById( "AccordionExpander" );
    
    accordionExpander.style.backgroundImage = "url(" + FMCGetMCAttribute( accordionExpander, "MadCap:selectedImage" ) + ")";
    
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
        gAccordionItems[i].style.cursor = "n-resize";
    }
    
    SetupAccordion();
}

function SetupAccordion()
{
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
        var accordionItem   = gAccordionItems[i];
        var accordionIcon   = gAccordionIcons[i];
        
        if ( accordionItem != gActiveItem )
        {
			accordionItem.onmouseover = function() { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:overImage" ) + " )"; };
			accordionItem.onmouseout = function() { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:outImage" ) + " )"; };
			accordionIcon.onmouseover = function() { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:overImage" ) + " )"; };
			accordionIcon.onmouseout = function() { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:outImage" ) + " )"; };
        }
    }
}

function AccordionItemClick( node )
{
    SetActiveIFrame( parseInt( FMCGetMCAttribute( node, "MadCap:itemID" ) ), node.getElementsByTagName( "a" )[0].childNodes[0].nodeValue );
    SetIFrameHeight();
}

function AccordionIconClick( node )
{
    SetActiveIFrame( parseInt( FMCGetMCAttribute( node, "MadCap:itemID" ) ), node.title );
    SetIFrameHeight();
}

function ItemOnkeyup( e )
{
	var target	= null;
	
	if ( !e ) { e = window.event; }
	
	if ( e.srcElement ) { target = e.srcElement; }
	else if ( e.target ) { target = e.target; }
	
	if ( e.keyCode == 13 && target && target.onclick )
	{
		target.onclick();
	}
}

function Init()
{
	document.body.tabIndex = 1;
	
    frames["index"].document.getElementById( "searchField" ).value = "";
    frames["search"].document.forms["search"].searchField.value = "";
    
    LoadSkin();
    
    SetActiveIFrame( gcDefaultID, gcDefaultTitle );
    SetIFrameHeight();
    SetupAccordion();
    
    // For Safari
    
    if ( document.clientHeight != null )
    {
        setTimeout( "BodyOnResize();", 10 );
    }
    
    //
    
    gInit = true;
}

function SetupMouseEffectDefaults()
{
	var accordionExpander	= document.getElementById( "AccordionExpander" );
	
	accordionExpander.style.backgroundImage = "url( Images/NavigationBottomGradient.jpg )";
	accordionExpander.setAttribute( "MadCap:outImage", "Images/NavigationBottomGradient.jpg" );
    accordionExpander.setAttribute( "MadCap:selectedImage", "Images/NavigationBottomGradient_selected.jpg" );
    
    FMCPreloadImage( "Images/NavigationBottomGradient_selected.jpg" );
    
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
		var accordionItem	= gAccordionItems[i];
		var id				= accordionItem.id;
		var name			= id.charAt( 0 ).toUpperCase() + id.substring( 1 );
		
		accordionItem.style.backgroundImage = "url(" + "Images/" + name + "Background.jpg" + ")";
		accordionItem.setAttribute( "MadCap:outImage", "Images/" + name + "Background.jpg" );
		accordionItem.setAttribute( "MadCap:overImage", "Images/" + name + "Background_over.jpg" );
		
		FMCPreloadImage( "Images/" + name + "Background_over.jpg" );
    }
    
    for ( var i = 0; i < gAccordionIcons.length; i++ )
    {
		var accordionIcon	= gAccordionIcons[i];
		var id				= accordionIcon.id;
		var name			= id.charAt( 0 ).toUpperCase() + id.substring( 1, id.length - "Icon".length ) + "Accordion";
		
		accordionIcon.style.backgroundImage = "url(" + "Images/" + name + "Background.jpg" + ")";
		accordionIcon.setAttribute( "MadCap:outImage", "Images/" + name + "Background.jpg" );
		accordionIcon.setAttribute( "MadCap:overImage", "Images/" + name + "Background_over.jpg" );
		
		FMCPreloadImage( "Images/" + name + "Background_over.jpg" );
    }
}

function LoadSkin()
{
	var xmlParser       = new CMCXmlParser();
    var xmlDoc          = xmlParser.Load( parent.gRootFolder + parent.gSkinFolder + "Skin.xml", false, null );
    var xmlHead         = xmlDoc.documentElement;
    var tabsAttribute	= xmlHead.getAttribute( "Tabs" );
    var tabs			= null;
    
    if ( tabsAttribute && tabsAttribute != "" )
    {
		tabs = xmlHead.getAttribute( "Tabs" ).split( "," );
    }
    else
    {
		return;
    }
    
    var defaultTab      = (xmlHead.getAttribute( "Tabs" ).indexOf( xmlHead.getAttribute( "DefaultTab" ) ) == -1) ? tabs[0] : xmlHead.getAttribute( "DefaultTab" );
    var accordionID     = null;
    var iconID          = null;
    var iframeID        = null;
    
    gcMaxVisibleItems = tabs.length;
    
    LoadWebHelpOptions( xmlDoc );
    
    //
    
    gTabIndex = 3;
    
    //
    
    for ( var i = 0; i < tabs.length; i++ )
    {
        var id		= null;
        var title	= null;
        
        switch ( tabs[i] )
        {
            case "TOC":
                id = "toc";
                title = "Table of Contents";
                
                break;
            case "Index":
                id = "index";
                title = "Index";
                
                break;
            case "Search":
                id = "search";
                title = "Search";
                
                break;
            case "Glossary":
                id = "glossary";
                title = "Glossary";
                
                break;
            case "Favorites":
                id = "favorites";
                title = "Favorites";
                
                break;
            case "BrowseSequences":
                id = "browsesequence";
                title = "Browse Sequence";
                
                break;
        }
        
        gAccordionItems[i] = document.getElementById( id + "Accordion" );
        gAccordionItems[i].setAttribute( "MadCap:itemID", i );
        gAccordionItems[i].getElementsByTagName( "a" )[0].tabIndex = gTabIndex++;
        
        var trAccordionIcons    = document.getElementById( "AccordionIcons" ).getElementsByTagName( "tr" )[0];
        var currIcon            = document.getElementById( id + "Icon" );
        var currIconClone       = currIcon.cloneNode( true );
        
        currIconClone.setAttribute( "MadCap:itemID", i );
        gAccordionIcons[i] = currIconClone;
        trAccordionIcons.removeChild( currIcon );
        trAccordionIcons.appendChild( currIconClone );
        gAccordionIcons[i].tabIndex = 0;
        
        gIFrames[i] = document.getElementById( id );
        
        if ( i < gVisibleItems )
        {
            gAccordionItems[i].style.display = "block";
        }
        else
        {
            gAccordionIcons[i].style.visibility = "visible";
        }
        
        gAccordionIcons[i].style.display = "inline";
        
        if ( !defaultTab )
        {
            defaultTab = tabs[i];
        }
        
        if ( tabs[i] == defaultTab )
        {
            accordionID = id + "Accordion";
            iconID = id + "Icon";
            iframeID = id;
            
            gcDefaultID = i;
            gcDefaultTitle = title;
            
            document.getElementById( id ).style.zIndex = "2";
        }
    }
    
    gActiveItem = document.getElementById( accordionID );
    gActiveIcon = document.getElementById( iconID );
    gActiveIFrame = document.getElementById( iframeID );
    
    //
    
    SetupMouseEffectDefaults();
    LoadStyles( xmlDoc );
}

function LoadWebHelpOptions( xmlDoc )
{
    var webHelpOptions  = xmlDoc.getElementsByTagName( "WebHelpOptions" )[0];
    
    if ( webHelpOptions )
    {
        var visibleItems    = webHelpOptions.getAttribute( "VisibleAccordionItemCount" );
        
        if ( visibleItems )
        {
            gVisibleItems = parseInt( visibleItems );
        }
    }
}

function LoadStyles( xmlDoc )
{
    var styleSheet	= xmlDoc.getElementsByTagName( "Stylesheet" )[0];
    
    if ( !styleSheet )
    {
		return;
	}
	
    var styleSheetLink	= styleSheet.getAttribute( "Link" );
    
    if ( !styleSheetLink )
    {
		return;
	}
	
	var xmlParser	= new CMCXmlParser();
    var styleDoc	= xmlParser.Load( parent.gRootFolder + parent.gSkinFolder + styleSheetLink, false, null );
    var styles		= styleDoc.getElementsByTagName( "Style" );
    
    for ( var i = 0; i < styles.length; i++ )
    {
        var styleName	= styles[i].getAttribute( "Name" );
        
        if ( styleName == "AccordionItem" )
        {
            LoadAccordionItemStyle( styles[i] );
        }
        else if ( styleName == "Frame" )
        {
            LoadFrameStyle( styles[i] );
        }
        else if ( styleName == "IndexEntry" )
        {
            LoadIndexEntryStyle( styles[i] );
        }
        else if ( styleName == "Control" )
        {
            LoadControlStyle( styles[i] );
        }
    }
}

function LoadAccordionIconsStyle( properties )
{
	var accordionIcons	= document.getElementById( "AccordionIcons" );

	for ( var j = 0; j < properties.length; j++ )
	{
		var cssName     = properties[j].getAttribute( "Name" );
		var cssValue    = properties[j].childNodes[0].nodeValue;

		cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

		if ( cssName == "itemHeight" )
		{
			accordionIcons.style.height = FMCConvertToPx( document, cssValue, null, 28 ) + "px";
		}
        else if ( cssName == "backgroundGradient" )
        {
			accordionIcons.style.backgroundImage = "url( " + parent.gRootFolder + parent.gSkinFolder + "AccordionIconsBackground.jpg )";
        }
        else
        {
            accordionIcons.style[cssName] = cssValue;
        }
	}
}

function LoadAccordionItemStyle( accordionItemStyle )
{
    var styleClasses    = accordionItemStyle.getElementsByTagName( "StyleClass" );
    
    for ( var i = 0; i < styleClasses.length; i++ )
    {
        var styleName		= styleClasses[i].getAttribute( "Name" );
        var properties		= styleClasses[i].getElementsByTagName( "Property" );
        
        if ( styleName == "IconTray" )
        {
			LoadAccordionIconsStyle( properties );
			
			continue;
        }
        
        var accordionItem	= document.getElementById( styleName.toLowerCase() + "Accordion" );
        var accordionANode	= accordionItem.getElementsByTagName( "a" )[0];
        var accordionIcon	= document.getElementById( styleName.toLowerCase() + "Icon" );
        
        for ( var j = 0; j < properties.length; j++ )
        {
            var cssName     = properties[j].getAttribute( "Name" );
            var cssValue    = properties[j].childNodes[0].nodeValue;
            
            cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );
            
            if ( cssName == "label" )
            {
                accordionANode.childNodes[0].nodeValue = cssValue;
                accordionIcon.title = cssValue;
                accordionIcon.firstChild.alt = cssValue;
                frames[styleName.toLowerCase()].document.title = cssValue;
                
                if ( FMCGetMCAttribute( accordionItem, "MadCap:itemID" ) == gcDefaultID )
                {
                    gcDefaultTitle = cssValue;
                }
            }
            else if ( cssName == "icon" )
            {
                var accordionItemImg    = accordionItem.getElementsByTagName( "img" )[0];
                var iconImg             = document.getElementById( styleName.toLowerCase() + "Icon" ).getElementsByTagName( "img" )[0];
                
                if ( cssValue == "none" )
                {
                    accordionItemImg.parentNode.removeChild( accordionItemImg );
                }
                else
                {
                    accordionItemImg.src = parent.gRootFolder + parent.gSkinFolder + cssValue.substring( 4, cssValue.length - 1 );
                    accordionItemImg.style.width = "auto";
                    accordionItemImg.style.height = "auto";
                    
                    iconImg.src = parent.gRootFolder + parent.gSkinFolder + cssValue.substring( 4, cssValue.length - 1 );
                    iconImg.style.width = "auto";
                    iconImg.style.height = "auto";
                }
            }
            else if ( cssName == "itemHeight" )
            {
                accordionItem.style.height = FMCConvertToPx( document, cssValue, null, 28 ) + "px";
            }
            else if ( cssName == "backgroundGradient" )
            {
				var id		= accordionItem.id;
				var name	= id.charAt( 0 ).toUpperCase() + id.substring( 1 );
				
				accordionItem.style.backgroundImage = "url( " + parent.gRootFolder + parent.gSkinFolder + name + "Background.jpg )";
                accordionItem.setAttribute( "MadCap:outImage", parent.gRootFolder + parent.gSkinFolder + name + "Background.jpg" );
                accordionIcon.style.backgroundImage = "url( " + parent.gRootFolder + parent.gSkinFolder + name + "Background.jpg )";
                accordionIcon.setAttribute( "MadCap:outImage", parent.gRootFolder + parent.gSkinFolder + name + "Background.jpg" );
            }
            else if ( cssName == "backgroundGradientHover" )
            {
				var id		= accordionItem.id;
				var name	= id.charAt( 0 ).toUpperCase() + id.substring( 1 );
				
				accordionItem.setAttribute( "MadCap:overImage", parent.gRootFolder + parent.gSkinFolder + name + "Background_over.jpg" );
                accordionIcon.setAttribute( "MadCap:overImage", parent.gRootFolder + parent.gSkinFolder + name + "Background_over.jpg" );
                
                FMCPreloadImage( parent.gRootFolder + parent.gSkinFolder + name + "Background_over.jpg" );
            }
            else if ( cssName == "color" )
            {
                accordionANode.style[cssName] = cssValue;
            }
            else
            {
                accordionItem.style[cssName] = cssValue;
            }
        }
    }
}

function LoadFrameStyle( frameStyle )
{
    var styleClasses	= frameStyle.getElementsByTagName( "StyleClass" );
    
    for ( var i = 0; i < styleClasses.length; i++ )
    {
        var styleName	= styleClasses[i].getAttribute( "Name" );
        
        if ( styleName == "NavigationTopDivider" )
        {
			var navigationTop	= document.getElementById( "NavigationTop" );
			var properties		= styleClasses[i].getElementsByTagName( "Property" );
			
            for ( var j = 0; j < properties.length; j++ )
			{
				var cssName     = properties[j].getAttribute( "Name" );
				var cssValue    = properties[j].childNodes[0].nodeValue;
	            
				if ( cssName == "Height" )
				{
					navigationTop.style.height = cssValue;
				}
				else if ( cssName == "BackgroundGradient" )
				{
					navigationTop.style.backgroundImage = "url( " + parent.gRootFolder + parent.gSkinFolder + "NavigationTopGradient.jpg )";
				}
			}
        }
        else if ( styleName == "NavigationDragHandle" )
        {
			var accordionExpander	= document.getElementById( "AccordionExpander" );
			var properties			= styleClasses[i].getElementsByTagName( "Property" );
			
            for ( var j = 0; j < properties.length; j++ )
			{
				var cssName     = properties[j].getAttribute( "Name" );
				var cssValue    = properties[j].childNodes[0].nodeValue;
	            
				if ( cssName == "Height" )
				{
					accordionExpander.style.height = cssValue;
				}
				else if ( cssName == "BackgroundGradient" )
				{
					accordionExpander.style.backgroundImage = "url( " + parent.gRootFolder + parent.gSkinFolder + "NavigationBottomGradient.jpg )";
					accordionExpander.setAttribute( "MadCap:outImage", parent.gRootFolder + parent.gSkinFolder + "NavigationBottomGradient.jpg" );
				}
				else if ( cssName == "BackgroundGradientPressed" )
				{
					accordionExpander.setAttribute( "MadCap:selectedImage", parent.gRootFolder + parent.gSkinFolder + "NavigationBottomGradient_selected.jpg" );
					
					FMCPreloadImage( parent.gRootFolder + parent.gSkinFolder + "NavigationBottomGradient_selected.jpg" );
				}
			}
        }
        else if ( styleName.substring( 0, "Accordion".length ) == "Accordion" )
        {
			var name		= styleName.substring( "Accordion".length ).toLowerCase();
			var properties	= styleClasses[i].getElementsByTagName( "Property" );
			
            for ( var j = 0; j < properties.length; j++ )
			{
				var cssName		= properties[j].getAttribute( "Name" );
				var cssValue	= properties[j].childNodes[0].nodeValue;
	            
				if ( cssName == "BackgroundColor" )
				{
					var accordionFrame	= frames[name];
					
					accordionFrame.document.body.style.backgroundColor = cssValue;
				}
			}
        }
    }
}

function LoadIndexEntryStyle( indexEntryStyle )
{
    var indexFrame  = frames["index"];
    var properties  = indexEntryStyle.getElementsByTagName( "Property" );
    
    for ( var j = 0; j < properties.length; j++ )
    {
        var cssName     = properties[j].getAttribute( "Name" );
        var cssValue    = properties[j].childNodes[0].nodeValue;
        
        cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );
        
        if ( cssName == "selectionColor" )
        {
            indexFrame.gSelectionColor = cssValue;
        }
        else if ( cssName == "selectionBackgroundColor" )
        {
            indexFrame.gSelectionBackgroundColor = cssValue;
        }
        
        indexFrame.gStylesMap.SetItem( cssName, cssValue );
    }
}

function LoadControlStyle( style )
{
	var styleClasses	= style.getElementsByTagName( "StyleClass" );
	
	for ( var i = 0; i < styleClasses.length; i++ )
    {
		var styleClass	= styleClasses[i];
        var styleName	= styleClass.getAttribute( "Name" );
        
        if ( styleName == "EmptySearchFavoritesLabel" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
				var favoritesFrame	= frames["favorites"];
		        
				if ( cssName == "Label" )
				{
					favoritesFrame.gEmptySearchFavoritesLabel = cssValue;
				}
				else if ( cssName == "Tooltip" )
				{
					favoritesFrame.gEmptySearchFavoritesTooltip = cssValue;
				}
				else
				{
					cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

					favoritesFrame.gEmptySearchFavoritesStyleMap.SetItem( cssName, cssValue );
				}
			}
		}
		else if ( styleName == "EmptyTopicFavoritesLabel" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
				var favoritesFrame	= frames["favorites"];
		        
				if ( cssName == "Label" )
				{
					favoritesFrame.gEmptyTopicFavoritesLabel = cssValue;
				}
				else if ( cssName == "Tooltip" )
				{
					favoritesFrame.gEmptyTopicFavoritesTooltip = cssValue;
				}
				else
				{
					cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

					favoritesFrame.gEmptyTopicFavoritesStyleMap.SetItem( cssName, cssValue );
				}
			}
        }
        else if ( styleName == "SearchButton" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
			var button		= frames["search"].document.getElementById( "SearchButton" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
		        
				if ( cssName == "Label" )
				{
					button.value = cssValue;
				}
				else
				{
					cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

					button.style[cssName] = cssValue;
				}
			}
        }
        else if ( styleName == "SearchBox" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
			var searchBox	= frames["search"].document.forms["search"].searchField;
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
		        
				if ( cssName == "Tooltip" )
				{
					searchBox.title = cssValue;
				}
			}
        }
        else if ( styleName == "SearchFavoritesDeleteButton" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property	= properties[j];
				var cssName		= property.getAttribute( "Name" );
				var cssValue	= property.firstChild.nodeValue;

		        if ( cssName == "Tooltip" )
				{
					frames["favorites"].gDeleteSearchFavoritesTooltip = cssValue;
				}
			}
        }
        else if ( styleName == "SearchFavoritesLabel" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
				var favoritesFrame	= frames["favorites"];
		        
				if ( cssName == "Label" )
				{
					favoritesFrame.gSearchFavoritesLabel = cssValue;
				}
				else
				{
					cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

					favoritesFrame.gSearchFavoritesLabelStyleMap.SetItem( cssName, cssValue );
				}
			}
        }
        else if ( styleName == "SearchFiltersLabel" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
			var filterCell	= frames["search"].document.getElementById( "SearchFilterCell" );
			
			if ( filterCell )
			{
				for ( var j = 0; j < properties.length; j++ )
				{
					var property	= properties[j];
					var cssName		= property.getAttribute( "Name" );
					var cssValue	= property.firstChild.nodeValue;

					if ( cssName == "Label" )
					{
						filterCell.firstChild.nodeValue = cssValue;
					}
					else
					{
						cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

						filterCell.style[cssName] = cssValue;
					}
				}
			}
        }
        else if ( styleName == "TopicFavoritesDeleteButton" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property	= properties[j];
				var cssName		= property.getAttribute( "Name" );
				var cssValue	= property.firstChild.nodeValue;

		        if ( cssName == "Tooltip" )
				{
					frames["favorites"].gDeleteTopicFavoritesTooltip = cssValue;
				}
			}
        }
        else if ( styleName == "TopicFavoritesLabel" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property		= properties[j];
				var cssName			= property.getAttribute( "Name" );
				var cssValue		= property.firstChild.nodeValue;
				var favoritesFrame	= frames["favorites"];
		        
				if ( cssName == "Label" )
				{
					favoritesFrame.gTopicFavoritesLabel = cssValue;
				}
				else
				{
					cssName = cssName.charAt( 0 ).toLowerCase() + cssName.substring( 1, cssName.length );

					favoritesFrame.gTopicFavoritesLabelStyleMap.SetItem( cssName, cssValue );
				}
			}
        }
        else if ( styleName == "AddSearchToFavoritesButton" )
        {
			var properties	= styleClass.getElementsByTagName( "Property" );
		    
			for ( var j = 0; j < properties.length; j++ )
			{
				var property	= properties[j];
				var cssName		= property.getAttribute( "Name" );
				var cssValue	= property.firstChild.nodeValue;

		        if ( cssName == "Tooltip" )
				{
					frames["search"].gAddSearchLabel = cssValue;
				}
			}
        }
	}
}

function SetActiveIFrameByName( name )
{
    for ( var i = 0; i < gAccordionItems.length; i++ )
    {
        var accordionItem   = gAccordionItems[i];
        var id              = accordionItem.id;
        
        if ( id.substring( 0, id.lastIndexOf( "Accordion" ) ) == name )
        {
            var itemID  = parseInt( FMCGetMCAttribute( accordionItem, "MadCap:itemID" ) );
            var title   = accordionItem.getElementsByTagName( "a" )[0].firstChild.nodeValue;
            
            SetActiveIFrame( itemID, title );
            SetIFrameHeight();
        }
    }
}

function SetActiveIFrame( id, title )
{
	if ( !gActiveItem )
	{
		return;
	}
	
	if ( gInit )
	{
		parent.frames["toolbar"].document.getElementById( "AccordionTitle" ).childNodes[0].nodeValue = title;
	}
    
    gActiveItem.style.backgroundImage = "url( " + FMCGetMCAttribute( gActiveItem, "MadCap:outImage" ) + " )";
    gActiveItem.onmouseout = function () { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:outImage" ) + " )"; };
    gActiveIcon.style.backgroundImage = "url( " + FMCGetMCAttribute( gActiveIcon, "MadCap:outImage" ) + " )";
    gActiveIcon.onmouseout = function () { this.style.backgroundImage = "url( " + FMCGetMCAttribute( this, "MadCap:outImage" ) + " )"; };
    gActiveIFrame.style.zIndex = "1";
    gActiveIFrame.scrolling = "no";
    
    gActiveItem = gAccordionItems[id];
    gActiveItem.onmouseout = null;
    gActiveItem.style.backgroundImage = "url( " + FMCGetMCAttribute( gActiveItem, "MadCap:overImage" ) + " )";
    gActiveIcon = gAccordionIcons[id];
    gActiveIcon.onmouseout = null;
    gActiveIcon.style.backgroundImage = "url( " + FMCGetMCAttribute( gActiveIcon, "MadCap:overImage" ) + " )";
    gActiveIFrame = gIFrames[id];
    gActiveIFrame.style.zIndex = "2";
    gActiveIFrame.scrolling = "auto";
    
    //
    
    // Do this to work around issue with setting focus to text fields in Firefox 1.5. This breaks IE so don't do it there.
    
    if ( gActiveIFrame.focus && !gActiveIFrame.currentStyle )
    {
        gActiveIFrame.focus();
    }
    
    var searchForm	= frames["search"].document.forms["search"];
    
    if ( gActiveIFrame.id == "index" )
    {
        frames["index"].document.getElementById( "searchField" ).focus();
    }
    else if ( gActiveIFrame.id == "search" )
    {
        searchForm.searchField.focus();
        
        if ( searchForm.searchFilter )
        {
			searchForm.searchFilter.style.display = "inline";
        }
    }
    
    //
    
    if ( gActiveIFrame.id != "search" )
    {
		if ( searchForm.searchFilter )
        {
			searchForm.searchFilter.style.display = "none";
		}
    }
    
    var iframe    = frames[gIFrames[id].id];
    
    iframe.Init();
    
    SetupAccordion();
}

function SetIFrameHeight()
{
    var height  = FMCGetClientHeight( window );
    var currTop = height;
    
    var accordionIcons	= document.getElementById( "AccordionIcons" );
    
    var borderTopWidth		= accordionIcons.style.borderTopWidth ? parseInt( accordionIcons.style.borderTopWidth ) : 0;
    var borderBottomWidth	= accordionIcons.style.borderBottomWidth ? parseInt( accordionIcons.style.borderBottomWidth ) : 0;
    
    currTop -= (borderTopWidth + borderBottomWidth + parseInt( FMCGetComputedStyle( accordionIcons, "height" ) ));
    accordionIcons.style.top = currTop + "px";
    
    for ( var i = gAccordionItems.length - 1; i >= 0; i-- )
    {
        if ( i > gVisibleItems - 1 )
        {
            continue;
        }
        
        var accordionItem       = gAccordionItems[i];
        var borderTopWidth      = accordionItem.style.borderTopWidth ? parseInt( accordionItem.style.borderTopWidth ) : 0;
        var borderBottomWidth   = accordionItem.style.borderBottomWidth ? parseInt( accordionItem.style.borderBottomWidth ) : 0;
        
        currTop -= (borderTopWidth + borderBottomWidth + (accordionItem.style.height ? parseInt( accordionItem.style.height ) : gcAccordionItemHeight))
        accordionItem.style.top = currTop + "px";
    }
    
    var accordionExpander	= document.getElementById( "AccordionExpander" );
    
    currTop -= parseInt( FMCGetComputedStyle( accordionExpander, "height" ) );
    accordionExpander.style.top = currTop + "px";
    
    var navigationTop	= document.getElementById( "NavigationTop" );
    
    currTop -= parseInt( FMCGetComputedStyle( navigationTop, "height" ) );
    
    for ( var i = 0; i < gIFrames.length; i++ )
    {
        var iframe  = gIFrames[i];
        
        if ( iframe == gActiveIFrame )
        {
            iframe.style.height = Math.max( currTop, 0 ) + "px";
            iframe.tabIndex = "2";
        }
        else
        {
            iframe.style.height = "1px";
            iframe.tabIndex = "-1";
        }
    }
    
    var indexFrame  = frames["index"];
    
    indexFrame.document.getElementById( "CatapultIndex" ).parentNode.style.height = Math.max( currTop - 20, 0 ) + "px";
    indexFrame.RefreshIndex();
    
    var searchFrame				= frames["search"];
    var searchResultsTable		= searchFrame.document.getElementById( "searchResultsTable" );
    var searchResultsContainer	= searchFrame.document.getElementById( "SearchResults" ).parentNode;
    
    searchResultsContainer.style.height = Math.max( currTop - searchResultsContainer.offsetTop - 2, 0 ) + "px";
    
    if ( searchResultsTable )
    {
        searchResultsTable.style.width = Math.max( FMCGetClientWidth( window ) - 25, 0 ) + "px";
    }
}

