/// <reference path="OwcBinding.js" />
/// <reference path="OwcToc.js" />
/// <reference path="OwcFlashViewer.js" />
/// <reference path="OwcMenu.js" />
/// <reference path="OwcSearchForm.js" />
/// <reference path="OwcSearchRes.js" />
Olive.Controls.controlTypeNames.DocViewerAgg = "doc-viewer-agg";

/*=============================================================================
 Class   : Olive.Controls.DocViewerAgg
 Summary : Complex control for document viewer.  Contains two panes: TOC and 
           content.  TOC pane contains tabs: TOC, search, thumbnails and 
           special pages.  Content pane contains customizable toolbar and 
           document (content) viewer.
=============================================================================*/
if (!Olive.Controls.DocViewerAgg)
{
	Olive.Controls.DocViewerAgg = function OwcDocViewerAgg()
	{
	}; // Olive.Controls.DocViewerAgg()
	
	// Pane names
	Olive.Controls.DocViewerAgg.panes = 
	{
		TocPane : "TOC",
		SearchPane : "Search",
		ThumbnailsPane : "Thumbnails",
		FeaturedPagesPane : "FeaturedPages"
	};

	// Pane names
	Olive.Controls.DocViewerAgg.UIElements = 
	{
		UIViewerRootPanel : "ViewerRootPanel",
		UIViewerNavigationPanel : "ViewerNavigationPanel",
		UIViewerSplitter : "ViewerSplitter",
		UIViewerContentPanel : "ViewerContentPanel",
		UIViewerBar : "ViewerBar",
		UINavigationTabStrip : "NavigationTabs",
		UINavigationPages : "NavigationPages"
	};

	Olive.Controls.DocViewerAgg.Commands = 
	{
		ViewPane : "ViewPane"
	};

	Olive.Controls.DocViewerAgg.NavigationCodes = 
	{
		PreviousPage : -100, 
		NextPage : -101
	};
	
	// Custom HTML attributes
	Olive.Controls.DocViewerAgg.attributes = 
	{		
		BindPageThumbnails : Olive.Controls.prefix + ":" + "bind-page-thumbnails",
		BindFeaturedPages : Olive.Controls.prefix + ":" + "bind-featured-pages",
		DoubleModeOnGotopage : Olive.Controls.prefix + ":" + "double-mode-on-gotopage",
		DoubleModeOnFlipping : Olive.Controls.prefix + ":" + "double-mode-on-flipping"
	};

	Olive.Controls.DocViewerAgg.DeclareType = function OwcDocViewerAgg_DeclareType()
	{
		/// <summary>
		///		Declares methods and properties of DocViewerAgg class
		/// </summary>
		
		// Fields
		this.DeclareField("m_arrPanes", null);
		this.DeclareField("m_oNavigationPane", null);
		this.DeclareField("m_oRootPaneSplitter", null);
		this.DeclareField("m_oViewerPane", null);
		this.DeclareField("m_oNavPageSwitcher", null);
		this.DeclareField("m_oNavTabStrip", null);
		this.DeclareField("m_oViewerCtrl", null);
		this.DeclareField("m_oTOCCtrl", null);
		this.DeclareField("m_oSearchResCtrl", null);
		this.DeclareField("m_oPageThumbnailsCtrl", null);
		this.DeclareField("m_oFeaturedPagesCtrl", null);
		this.DeclareField("m_bBindPageThumbnails", true);
		this.DeclareField("m_bBindFeaturedPages", true);
		this.DeclareField("m_bDoubleModeOnGotopage", false);
		this.DeclareField("m_bDoubleModeOnFlipping", false);
		this.DeclareField("m_bGlobalDoublePageMode", true);

		this.DeclareField("m_oBindTocToDocViewer", null);
		this.DeclareField("m_oBindSearchResToDocViewer", null);		

		// Properties
		this.DeclareMethod("get_BindPageThumbnails", OwcDocViewerAgg_get_BindPageThumbnails);
		this.DeclareMethod("set_BindPageThumbnails", OwcDocViewerAgg_set_BindPageThumbnails);
		this.DeclareMethod("get_BindFeaturedPages", OwcDocViewerAgg_get_BindFeaturedPages);
		this.DeclareMethod("set_BindFeaturedPages", OwcDocViewerAgg_set_BindFeaturedPages);
		this.DeclareMethod("get_DoubleModeOnGotopage", OwcDocViewerAgg_get_DoubleModeOnGotopage);
		this.DeclareMethod("set_DoubleModeOnGotopage", OwcDocViewerAgg_set_DoubleModeOnGotopage);
		this.DeclareMethod("get_DoubleModeOnFlipping", OwcDocViewerAgg_get_DoubleModeOnFlipping);
		this.DeclareMethod("set_DoubleModeOnFlipping", OwcDocViewerAgg_set_DoubleModeOnFlipping);
		this.DeclareMethod("get_GlobalDoublePageMode", OwcDocViewerAgg_get_GlobalDoublePageMode);
		this.DeclareMethod("set_GlobalDoublePageMode", OwcDocViewerAgg_set_GlobalDoublePageMode);

		this.DeclareMethod("get_TocControl", OwcDocViewerAgg_get_TocControl);
		this.DeclareMethod("set_TocControl", OwcDocViewerAgg_set_TocControl);
		this.DeclareMethod("get_SearchResControl", OwcDocViewerAgg_get_SearchResControl);
		this.DeclareMethod("set_SearchResControl", OwcDocViewerAgg_set_SearchResControl);
		this.DeclareMethod("get_PageThumbnailsControl", OwcDocViewerAgg_get_PageThumbnailsControl);
		this.DeclareMethod("set_PageThumbnailsControl", OwcDocViewerAgg_set_PageThumbnailsControl);
		this.DeclareMethod("get_FeaturedPagesControl", OwcDocViewerAgg_get_FeaturedPagesControl);
		this.DeclareMethod("set_FeaturedPagesControl", OwcDocViewerAgg_set_FeaturedPagesControl);

		// Methods
		this.DeclareMethod("PreparePrintData", OwcDocViewerAgg_PreparePrintData);
        this.DeclareMethod("CancelDoubleModeOnGotopage", OwcDocViewerAgg_CancelDoubleModeOnGotopage);
        this.DeclareMethod("ApplyDoubleModeOnGotopage", OwcDocViewerAgg_ApplyDoubleModeOnGotopage);
        
		// Overrides
		this.OverrideMethod("initControl", OwcDocViewerAgg_initControl);
		this.OverrideMethod("contentLoad", OwcDocViewerAgg_contentLoad);
		this.OverrideMethod("parseControlHtmlAttr", OwcDocViewerAgg_parseControlHtmlAttr);

		// Event handlers
		this.DeclareMethod("_onTabActivating", OwcDocViewerAgg_onTabActivating);
		this.DeclareMethod("_onNavigationPageStateChanged", OwcDocViewerAgg_onNavigationPageStateChanged);
		this.DeclareMethod("_onFlashGotoPage", OwcDocViewerAgg_onFlashGotoPage);
		this.DeclareMethod("_onFlipAreaOrPageButtonClicked", OwcDocViewerAgg_onFlipAreaOrPageButtonClicked);				
		this.DeclareMethod("_onSearchRequest", OwcDocViewerAgg_onSearchRequest);
		this.DeclareMethod("_onPageThumbnailContentItemClicked", OwcDocViewerAgg_onPageThumbnailContentItemClicked);
		this.DeclareMethod("_onFeaturedPagesContentItemClicked", OwcDocViewerAgg_onFeaturedPagesContentItemClicked);		
		this.DeclareMethod("_onErrorStatusReceived", OwcDocViewerAgg_onErrorStatusReceived);
		
		this.DeclareMethod("_onPagesModeChanged", OwcDocViewerAgg_onPagesModeChanged);		
		this.DeclareMethod("_HoldGateFoldEvents", OwcDocViewerAgg_HoldGateFoldEvents);		

		// Implementation:
		this.DeclareMethod("_FindViewerParts", OwcDocViewerAgg_FindViewerParts);
		this.DeclareMethod("_getAbsolutePageNo", OwcDocViewerAgg_getAbsolutePageNo);
		this.DeclareMethod("_FindPanesByUIType", OwcDocViewerAgg_FindPanesByUIType);
		this.DeclareMethod("_FindNavigationPane", OwcDocViewerAgg_FindNavigationPane);
		this.DeclareMethod("_FindUiControl", OwcDocViewerAgg_FindUiControl);
		this.DeclareMethod("_ViewPane", OwcDocViewerAgg_ViewPane);
		this.DeclareMethod("_ViewPane_updateUiState", OwcDocViewerAgg_ViewPane_updateUiState);
		this.DeclareMethod("_HideNavigationPane", OwcDocViewerAgg_HideNavigationPane);
		this.DeclareMethod("_ShowNavigationPane", OwcDocViewerAgg_ShowNavigationPane);
	}; // Olive.Controls.DocViewerAgg.DeclareType()

	Olive.Controls.DocViewerAgg.ApplyPrototype = function OwcDocViewerAgg_ApplyPrototype(rObject, bDynamic)
	{
		/// <summary>
		///		Registers commands and events for DocViewerAgg class.
		/// </summary>
		/// <param name="rObject" type="Object">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    /// <param name="bDynamic" type="Boolean">	    
	    /// </param>
		
		// Register commands
		Olive.CmdTarget.RegisterCommand(rObject, this.Commands.ViewPane, rObject._ViewPane, rObject._ViewPane_updateUiState);
		
		// Register events
		rObject.registerOwcEventsClass2("pageThumbnailClicked", "onPageThumbnailClicked", true, OwcDocViewerAgg_onContentItemClickedDefault);
		rObject.registerOwcEventsClass2("featuredPageClicked", "onFeaturedPageClicked", true, OwcDocViewerAgg_onContentItemClickedDefault);
		rObject.registerOwcEventsClass2("navigationPaneVisibilityChanged", "onNavigationPaneVisibilityChanged", true);		
		rObject.registerOwcEventsClass2("globalDoublePageModeChanged", "onGlobalDoublePageModeChanged", true);		
	}; // Olive.Controls.DocViewerAgg.ApplyPrototype()

	function OwcDocViewerAgg_get_BindPageThumbnails()
	{
		/// <summary>
		///		Get method for the property m_bBindPageThumbnails.
		/// </summary>
		/// <returns type="Boolean">
		///     Returns the value of the property.
		/// </returns>
		/// <remarks>
		///		Property m_bBindPageThumbnails is a boolean property that defines 
		///     whether to use the default binding between the Page Thumbnails and 
		///     the Flash Viewer controls of the DocViewerAgg; 
		///     true by default. 
		/// </remarks>
		
		return this.m_bBindPageThumbnails;
	}

	function OwcDocViewerAgg_set_BindPageThumbnails(value)
	{
		/// <summary>
		///		Set method for the property m_bBindPageThumbnails.
		/// </summary>
		/// <param name="value" type="Boolean">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    
		this.m_bBindPageThumbnails = value;
	}
	
	function OwcDocViewerAgg_get_BindFeaturedPages()
	{
		/// <summary>
		///		Get method for the property m_bBindFeaturedPages.
		/// </summary>
		/// <returns type="Boolean">
		///     Returns the value of the property.
		/// </returns>
		/// <remarks>
		///		Property m_bBindFeaturedPages is a boolean property that defines 
		///     whether to use the default binding between the Featured Pages and 
		///     the Flash Viewer controls of the DocViewerAgg; 
		///     true by default. 
		/// </remarks>
		
		return this.m_bBindFeaturedPages;
	}

	function OwcDocViewerAgg_set_BindFeaturedPages(value)
	{
		/// <summary>
		///		Set method for the property m_bBindFeaturedPages.
		/// </summary>
		/// <param name="value" type="Boolean">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    
		this.m_bBindFeaturedPages = value;
	}
	
	function OwcDocViewerAgg_get_DoubleModeOnGotopage()
	{
		/// <summary>
		///		Get method for the property m_bDoubleModeOnGotopage.
		/// </summary>
		/// <returns type="Boolean">
		///     Returns the value of the property.
		/// </returns>
		/// <remarks>
		///		Property m_bDoubleModeOnGotopage is a boolean property that defines 
		///     whether to switch to double page mode in the Flash Viewer
		///     when the user uses one of the commands - "gotopage", "gotonextpage", "gotoprevpage" etc.; 
		///     false by default. 
		/// </remarks>
		
		return this.m_bDoubleModeOnGotopage;
	}

	function OwcDocViewerAgg_set_DoubleModeOnGotopage(value)
	{
		/// <summary>
		///		Set method for the property m_bDoubleModeOnGotopage.
		/// </summary>
		/// <param name="value" type="Boolean">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    
		this.m_bDoubleModeOnGotopage = value;
	}
	
	function OwcDocViewerAgg_get_DoubleModeOnFlipping()
	{
		/// <summary>
		///		Get method for the property m_bDoubleModeOnFlipping.
		/// </summary>
		/// <returns type="Boolean">
		///     Returns the value of the property
		/// </returns>
		/// <remarks>
		///		Property m_bDoubleModeOnFlipping is a boolean property that defines 
		///     whether to switch to double page mode in the Flash Viewer
		///     when the user clicks on the Flippinf area of the Flash Viewer; 
		///     false by default. 
		/// </remarks>
		
		return this.m_bDoubleModeOnFlipping;
	}

	function OwcDocViewerAgg_set_DoubleModeOnFlipping(value)
	{
		/// <summary>
		///		Set method for the property m_bDoubleModeOnFlipping.
		/// </summary>
		/// <param name="value" type="Boolean">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    
		this.m_bDoubleModeOnFlipping = value;
	}
	
	function OwcDocViewerAgg_get_GlobalDoublePageMode()
	{
		/// <summary>
		///		Get method for the property m_bGlobalDoublePageMode.
		/// </summary>
		/// <returns type="Boolean">
		///     Returns the value of the property
		/// </returns>
		/// <remarks>
		///		if we are using automatic switching between single/double mode
		///    ( m_bDoubleModeOnGotopage || m_bDoubleModeOnFlipping ) and we are on page 1,
		///     this specifies what "global" double-page-mode is in effect
		///     if it is true, then when you navigate to another page, the viewer will go into 2 page mode
		///     and close the navigation panel. Default value: true.
		/// </remarks>
		
		return this.m_bGlobalDoublePageMode;
	}

	function OwcDocViewerAgg_set_GlobalDoublePageMode(value)
	{
		/// <summary>
		///		Set method for the property m_bGlobalDoublePageMode.
		/// </summary>
		/// <param name="value" type="Boolean">
	    ///		Reference to the prototype of the class.
	    /// </param>
	    
		var bPrevValue = this.m_bGlobalDoublePageMode;
		if (bPrevValue != value)
		{
		    this.m_bGlobalDoublePageMode = value;
    		
		    var oEvent = this.createOwcEventObject("globalDoublePageModeChanged");
	        oEvent.bGlobalDoublePageMode = value;
	        this.fireOwcEvent(oEvent);
	        Object_Destroy(oEvent);
	    }
	}

	function OwcDocViewerAgg_PreparePrintData()
	{
		/// <summary>
		///		Prepares data for printing pages of currently displayed document.
		/// </summary>
		/// <returns type="Olive.Data.PrintFormData">
		///		The <see cref="Olive.Data.PrintFormData" /> object with information
		///		about document being displayed and state of the viewer or <c>null</c>
		///		if no document is being displayed.
		///	</returns>
		if (!this.m_oViewerCtrl)
			return null;
		var docContentItem = this.getContentItem();
		if (!docContentItem)
			return null;

        var isTwoPageView = this.m_oViewerCtrl.getModeDoublePage();
        var docPagesCount = this.m_oViewerCtrl.getTotalPagesCount();
        var currentPageNo = this.m_oViewerCtrl.getPageNo();
		var currentPageLabel = this.m_oViewerCtrl.getPageLabelForPageNo(currentPageNo);
        var lastVisiblePageNo = this.m_oViewerCtrl.getLastVisiblePageNo();
		var lastVisiblePageLabel = this.m_oViewerCtrl.getPageLabelForPageNo(lastVisiblePageNo);

		if (docPagesCount < 0 || currentPageLabel === null || lastVisiblePageLabel === null)
            return null;	// Invalid data
        if (isTwoPageView == null || isTwoPageView == undefined)
            isTwoPageView = false;

		var printData = new Olive.Data.PrintFormData();
		printData.setPrintItemType(OwcContentItem_Document);
        printData.setTotalPagesCount(String(docPagesCount));
        printData.setCurrentPage(String(currentPageLabel));
		printData.setDoubleMode(isTwoPageView);
		printData.setLastVisiblePage(String(lastVisiblePageLabel));
		return printData;
	}

	function OwcDocViewerAgg_parseControlHtmlAttr()
	{
		/// <summary>
		///		Parses custom HTML attributes.
		/// </summary>
		
		if (this.BaseClassMethod)
			this.BaseClassMethod.apply(this, arguments);

		this.set_BindPageThumbnails(DHTML.getAttrBoolean(this.HtmlElement, 
		        Olive.Controls.DocViewerAgg.attributes.BindPageThumbnails, this.m_bBindPageThumbnails));
		this.set_BindFeaturedPages(DHTML.getAttrBoolean(this.HtmlElement, 
		        Olive.Controls.DocViewerAgg.attributes.BindFeaturedPages, this.m_bBindFeaturedPages));
		this.set_DoubleModeOnGotopage(DHTML.getAttrBoolean(this.HtmlElement, 
		        Olive.Controls.DocViewerAgg.attributes.DoubleModeOnGotopage, this.m_bDoubleModeOnGotopage));
		this.set_DoubleModeOnFlipping(DHTML.getAttrBoolean(this.HtmlElement, 
		        Olive.Controls.DocViewerAgg.attributes.DoubleModeOnFlipping, this.m_bDoubleModeOnFlipping));
	}
	
	function OwcDocViewerAgg_initControl()
	{
		/// <summary>
		///		Initializes the control.
		/// </summary>
		/// <remarks>
		///		Finds the main parts of the DocViewerAgg; 
		///     binds controls, attaches event handlers.
		/// </remarks>
		
		// Initialize controls
		if (this.BaseClassMethod)
			this.BaseClassMethod.apply(this, arguments);

		// Find significant parts of the viewer control
		this._FindViewerParts();

		// Attach event handlers to significant parts of the viewer control
		if (this.m_oNavigationPane)
			this.m_oNavigationPane.attachOwcEventHandler("stateChanged", this._onNavigationPageStateChanged, this);		

		// Synchronize tab and page switcher (if both present in control)
		if (this.m_oNavTabStrip && this.m_oNavPageSwitcher)
		{
			this.m_oNavTabStrip.attachOwcEventHandler("itemActivating", this._onTabActivating, this);
			Olive.Binding.SyncActiveItems.BindControls(this.m_oNavTabStrip, this.m_oNavPageSwitcher);
		}

		// Bind controls to viewer
        if (this.m_oViewerCtrl)
        {
			// Bind search forms
			var searchFormControls = this.findControlsByType(Olive.Controls.controlTypeNames.SearchForm);
			if (searchFormControls)
			{
				for (var i=0; i < searchFormControls.length; i++)
					searchFormControls[i].attachOwcEventHandler("searchRequest", this._onSearchRequest, this);
			}

			// Bind command bar to the viewer
			var viewerCommandBar = this._FindUiControl(Olive.Controls.DocViewerAgg.UIElements.UIViewerBar,
														Olive.Controls.controlTypeNames.Menu);
			if (viewerCommandBar)
				viewerCommandBar.setCmdTarget(this.m_oViewerCtrl);

			// Redirect all command bars in the viewer pane to the viewer control
			if (this.m_oViewerPane)
				Olive.ICmdSource.BindCommandBars(this.m_oViewerPane, this.m_oViewerCtrl);
			
			// Attach "flipAreaClicked" and "flashGotoPage" event handler
		    if (this.get_DoubleModeOnGotopage())
		    {
		        this.ApplyDoubleModeOnGotopage();
		        this.m_oViewerCtrl.attachOwcEventHandler("gatefoldStatusChanged", this._HoldGateFoldEvents, this);
		    }
		    
		    if (this.get_DoubleModeOnGotopage() && !this.get_DoubleModeOnFlipping())
		        this.m_oViewerCtrl.attachOwcEventHandler("flipAreaOrPageButtonClicked", this._onFlipAreaOrPageButtonClicked, this);

            // Attach for the errorStatusReceived event to catch access restrictions events from Flash Viewer.
            this.m_oViewerCtrl.attachOwcEventHandler("errorStatusReceived", this._onErrorStatusReceived, this);
        }

		// Update state of all command bars and command buttons
		Olive.ICmdSource.UpdateAll(this);
	}
	
	function OwcDocViewerAgg_CancelDoubleModeOnGotopage()
	{
	    /// <summary>
		///		Detaches handler for "flashGotoPage" event.
		/// </summary>
	    this.m_oViewerCtrl.detachOwcEventHandler("flashGotoPage", this._onFlashGotoPage, this);
	}
	
	function OwcDocViewerAgg_ApplyDoubleModeOnGotopage()
	{
	    /// <summary>
		///		Attaches handler for "flashGotoPage" event.
		/// </summary>
	    this.m_oViewerCtrl.attachOwcEventHandler("flashGotoPage", this._onFlashGotoPage, this);
	}

	function OwcDocViewerAgg_contentLoad()
	{
		/// <summary>
		///		Scans the controls and loads the content for all of them.
		/// </summary>
		
		function callback_loadData(ctxScanner, oDataBoundControl)
		{
			// Erase previous content item to force using content item from the parent
			oDataBoundControl.m_oContentItem = null;
			oDataBoundControl.contentLoad();
		}

		function callback_filterDataBoundControl(ctxScanner, oControl)
		{
			// Process this control, skip children
			if (Olive.Controls.IDataBound.IsImplementedBy(oControl))
			{
				// Do not include FlashViewer - for FlashViewer call another method
				if (oControl.controlType == Olive.Controls.controlTypeNames.ThumbList
					|| oControl.controlType == Olive.Controls.controlTypeNames.TOC)
					return Olive.Controls.Scanner.FilterMode.Process;
				return Olive.Controls.Scanner.FilterMode.Skip;
			}

			// Skip this control, scan children
			return (Olive.Controls.Scanner.FilterMode.Reject + Olive.Controls.Scanner.FilterMode.StopFilter);
		}

		var oScanner = new Olive.Controls.Scanner();
		oScanner.setProcessControlCallback(callback_loadData);
		oScanner.addFilter(callback_filterDataBoundControl);
		oScanner.scan(this);

		// For FlashViewer control call displayDocument method instead of contentLoad
		if (this.m_oViewerCtrl)
		{
			this.m_oViewerCtrl.m_oContentItem = null;
			this.m_oViewerCtrl.displayDocument(true);
		}
	}

    function OwcDocViewerAgg_ViewPane(sPaneName)
	{
		/// <summary>
		///		Shows the requested pane to the user.
		/// </summary>
		/// <param name="sPaneName" type="String">
	    ///		Name of a pane.
	    /// </param>
		/// <remarks>
		///		Shows the Novigation pane as well, if the requested pane 
		///     is in the Navigation pane and the Navigation pane was invisible. 
		/// </remarks>
		
		if (!this.m_arrPanes || !sPaneName || !(sPaneName in this.m_arrPanes))
			return;

		// Find page item control for requested pane:
		var nPanePageIndex = this.m_arrPanes[sPaneName];
		this.m_oNavPageSwitcher.setActiveItem(nPanePageIndex);

		if (this.m_oNavigationPane && !this.m_oNavigationPane.isVisible())
			this.m_oNavigationPane.show();
	}

	function OwcDocViewerAgg_ViewPane_updateUiState(oCmdUiState)
	{
		/// <summary>
		///		Updates the UI state of the command Olive.Controls.DocViewerAgg.Commands.ViewPane.
		/// </summary>
		/// <param name="oCmdUiState" type="Olive.CmdUiState">
	    ///		Reference to object storing command's UI state.
	    /// </param>
		
		// Find page item control for requested pane:
		var nPanePageIndex = -1;
		if (this.m_arrPanes && 
			oCmdUiState.commandParams && 
			(oCmdUiState.commandParams in this.m_arrPanes))
			nPanePageIndex = this.m_arrPanes[oCmdUiState.commandParams];

		if (nPanePageIndex >= 0)
		{
			oCmdUiState.enableCommand(true);
			oCmdUiState.checkCommand(this.m_oNavPageSwitcher.getActiveItemIndex() == nPanePageIndex);
		}
		else
		{
			oCmdUiState.enableCommand(false);
			oCmdUiState.checkCommand(false);
		}
	}
	
	function OwcDocViewerAgg_ShowNavigationPane(bDoNotNotify)
	{ 
	    /// <summary>
		///		Shows the navigation pane and the pane splitter.
		/// </summary>

		if (!bDoNotNotify && !this.m_oNavigationPane.isVisible() )
		{   
	        // inform about showing navigation pane
	        var oEvent = this.createOwcEventObject("navigationPaneVisibilityChanged");
		    oEvent.bPaneVisible = true;
		    this.fireOwcEvent(oEvent);
		    Object_Destroy(oEvent);
		}
			        
	    if (this.m_oNavigationPane && !this.m_oNavigationPane.isVisible())
	        this.m_oNavigationPane.show();
	        
	    if (this.m_oRootPaneSplitter && !this.m_oRootPaneSplitter.isVisible())
	        this.m_oRootPaneSplitter.show();    
	}
	
	function OwcDocViewerAgg_HideNavigationPane(bDoNotNotify)
	{
	    /// <summary>
		///		Hides the navigation pane and the pane splitter.
		/// </summary>
		
	    if (!bDoNotNotify && this.m_oNavigationPane.isVisible() )
		{	
	        // inform about hiding navigation pane
	        var oEvent = this.createOwcEventObject("navigationPaneVisibilityChanged");
		    oEvent.bPaneVisible = false;
		    this.fireOwcEvent(oEvent);
		    Object_Destroy(oEvent);	
		}  
	    
	    if (this.m_oRootPaneSplitter && this.m_oRootPaneSplitter.isVisible())
	        this.m_oRootPaneSplitter.hide();
	        
	    if (this.m_oNavigationPane && this.m_oNavigationPane.isVisible())
	        this.m_oNavigationPane.hide();   
	}

	function OwcDocViewerAgg_onTabActivating(eventData)
	{
		/// <summary>
		///		Handler of the "itemActivating" event for the Navigation Tab Strip.
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		Shows the hidden navigation pane for activated tab item.
		/// </remarks>
		
		if (eventData.activeItem)
		    this._ShowNavigationPane(false);
	}

	function OwcDocViewerAgg_onNavigationPageStateChanged(eventData)
	{
		/// <summary>
		///		Handler of the "stateChanged" event for the Navigation pane.
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		Changes the double page mode for the Flash Viewer according to 
		///     the state of the Navigation pane:
		///         - set double page mode, if the navigation pane is hidden;
		///         - set single page mode, otherwise.
		/// </remarks>
		
		if (eventData.srcObject != this.m_oNavigationPane)
			return;
	
		var stateChanged = eventData.prevState ^ eventData.newState;
		if ((stateChanged & Olive.IState.State.VisibleMask) != 0)
		{
			var paneVisible = ((eventData.newState & Olive.IState.State.VisibleMask) == Olive.IState.State.Visible);

			if (this.m_oViewerCtrl)
			{
				var bDoubleMode = this.m_oViewerCtrl.getModeDoublePage();
				var bGlobalDoublePageMode = this.get_GlobalDoublePageMode();
				if (bDoubleMode == paneVisible && (bGlobalDoublePageMode || (!bGlobalDoublePageMode && bDoubleMode)))
				{
					this.m_oViewerCtrl.cmdChangeModeDoublePage(!paneVisible);
				}
			}
		}
	}	
	
	function OwcDocViewerAgg_onFlipAreaOrPageButtonClicked(eventData)
	{		
		/// <summary>
		///		Handler of the "flipAreaClicked" event of the Flash Viewer object (comes from Action Script).		
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///     The handler cancel default action of FlashViewer component handler, and replaces its functionality call to gotoPageWithHighlighting
		///     In place of gotoPage. So The PageMode will not be changed for navigation events from flash.
		/// </remarks>

        if(!eventData)
            return;
	    eventData.cancelDefaultAction = true;
	    var oNavigation = this.m_oViewerCtrl.calculateDestinationPage(eventData.sDirection, eventData.nDestinationPage);
	    this.m_oViewerCtrl.gotoPageWithHighlighting(oNavigation.nPageNo, null, null, oNavigation.bRelativeNavigation, eventData.nContinuousScroll, eventData.bOpenGatefold);
	}
	
	function OwcDocViewerAgg_onSearchRequest(eventData)
    {
	    /// <summary>
		///		Handler of the "searchRequest" event of the Search Form control.		
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		If the search results control is defined, 
		///     adds the search in document parameter to the search parameters of the original event
		///     and loads the search results.
		/// </remarks>
	    
	    if (this.m_oSearchResCtrl)
	    {
	        eventData.cancelBubbling = true;
	        var contentItem = this.getContentItem();
	        if (!contentItem)
	            return;
	        eventData.SearchParams.addSearchInDocument(contentItem);
	        this.m_oSearchResCtrl.loadSearchResults(eventData.SearchParams);
	    }
    }
    
    function OwcDocViewerAgg_onPageThumbnailContentItemClicked(eventData)
    {
	    /// <summary>
		///		Handler of the "contentItemClicked" event in case of not default binding 
		///     between the Page Thumbnails and the Flash Viewer controls.		
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		Fires the own event "pageThumbnailClicked" for application customization.
		///     There is a default event handler OwcDocViewerAgg_onContentItemClickedDefault.
		/// </remarks>
	    
	    // inform about clicking on a page thumbnail
	    var oEvent = this.createOwcEventObject("pageThumbnailClicked");
		oEvent.OlvContentItem = eventData.OlvContentItem;
		this.fireOwcEvent(oEvent);
		Object_Destroy(oEvent);
    }
    
    function OwcDocViewerAgg_onFeaturedPagesContentItemClicked(eventData)
    {	    
	    /// <summary>
		///		Handler of the "contentItemClicked" event in case of not default binding 
		///     between the Featured Pages and the Flash Viewer controls.		
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		Fires the own event "featuredPageClicked" for application customization.
		///     There is a default event handler OwcDocViewerAgg_onContentItemClickedDefault.
		/// </remarks>
	    
	    // inform about clicking on a featured page
	    var oEvent = this.createOwcEventObject("featuredPageClicked");
		oEvent.OlvContentItem = eventData.OlvContentItem;
		this.fireOwcEvent(oEvent);
		Object_Destroy(oEvent);
    }
    
    function OwcDocViewerAgg_onContentItemClickedDefault(eventData)
    {
        /// <summary>
		///		The default handler for the "pageThumbnailClicked" and "featuredPageClicked" events.		
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///		Navigates to a corresponding page;
		///     Hide the navigation pane (if it is not the first page);		
		/// </remarks>
        
        // default event handler for "pageThumbnailClicked" and "featuredPageClicked" events
        if (!eventData)
            return;            
        eventData.cancelBubbling = true;
        
        if (!this.m_oViewerCtrl)
            return;
        
        // navigate to a corresponding page
        var oContentItem = eventData.OlvContentItem;
        var sDataType = oContentItem.getDataType();
        if (sDataType == OwcContentItem_Page)
        {
            var nPageNo = oContentItem.m_nPageNo;
            var sPrimitiveId = oContentItem.m_sPrimId;
            this.m_oViewerCtrl.gotoPageWithHighlighting(nPageNo, sPrimitiveId, null, null, null, true);
        }
        
    }

    function OwcDocViewerAgg_onFlashGotoPage(eventData)
    {
	    /// <summary>
		///		Handler for the "flashGotoPage" event of the Flash Viewer object. comes before action of gotopage is taken.
		/// </summary>
		/// <param name="eventData" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///     The handler is activated if m_bDoubleModeOnGotopage is set to true.
		///     The event handler
		///     Switches to from one page mode to two pages mode for any navigation event.
		///     Switches from two pages mode to one page mode whan navigating to first page.
		/// </remarks>
    
	    if (!this.m_oViewerCtrl || !this.m_oNavigationPane || !eventData) 
		    return;

        var bOnePageMode = !this.m_oViewerCtrl.getModeDoublePage();
        var nCurrentPage = this.m_oViewerCtrl.getPageNo();  // current page number.
        var nDestinationPage = eventData.nPageNo; // the page number where to go
        var nFirstPage = 1; // first page number

        if (this.get_GlobalDoublePageMode())
        {
            if(bOnePageMode) // Viewer has ONE page view.
            {
                var bNext = ((nDestinationPage - nCurrentPage) == 1) ?  true : false;
                var bPrevious = ((nDestinationPage - nCurrentPage) == -1) ?  true : false;
                var bCurrentPageIsEven = ((nCurrentPage % 2) == 0)? true : false;
                
                if((bCurrentPageIsEven && bNext) || (!bCurrentPageIsEven && bPrevious && nDestinationPage != nFirstPage)) //(evenPage && Next) || (oddPage && Previous && DestinationPage != First)
                {
                    eventData.cancelDefaultAction = true;   // cancel flipping
                    // attach event onPageModeChanged which synchronizes panes with pages mode
		            this.m_oViewerCtrl.attachOwcEventHandler("pageModeChanged", this._onPagesModeChanged, this); //The event handler will hide navigation pane          
                    this.m_oViewerCtrl.cmdChangeModeDoublePage(true, nDestinationPage);  //switch to TWO pages mode
                }
                else if(nDestinationPage != nFirstPage)//allow normal pages flipping
                {                
                    this.m_oViewerCtrl.attachOwcEventHandler("pageModeChanged", this._onPagesModeChanged, this); //The event handler will hide navigation pane                                         
                    
                    // do not call this.m_oViewerCtrl.cmdChangeModeDoublePage(true) but add the command to "gotoPageById" (from event),
                    // because of unability to send more than 1 command to Flash if you are in the event handler that came from flash
                    // ("flipAreaOrPageButtonClicked" - currently problematic place)
                    // TODO: the solution is not nice, should be changed by implementation of transactions
                    eventData.addCommand = {commandName:"cmdChangeModeDoublePage", params:{'newState': true}};
                 }
                //else do nothing, allow normal pages flipping
            }
            else // Viewer has TWO pages view
            {
                if (nDestinationPage == nFirstPage)//allow normal pages flipping
                {                
                    this.m_oViewerCtrl.attachOwcEventHandler("pageModeChanged", this._onPagesModeChanged, this); //The event handler will show navigation pane                         
                    
                    // TODO: see comment for the same action above
                    eventData.addCommand = {commandName:"cmdChangeModeDoublePage", params:{'newState': false}};
                }
                //else do nothing, allow normal pages flipping
            }
        }
		//else{......} // navigation-pane update for global-1-pg-mode was removed in TFS changeset 1932
    }
    
    function OwcDocViewerAgg_onPagesModeChanged(oEvent)
    {
	    /// <summary>
		///		Handler for the "pageModeChanged" event of the Flash Viewer object (comes from Action Script).
		/// </summary>
		/// <param name="oEvent" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///     The handler is activated from navigation event handler _onFlashGotoPage
		///		Detaches the "pageModeChanged" event.
		///     The event handler synchronizes navigation pane mode (visible / hidden) to pages mode of viewer (one page / two pages)
		/// </remarks>
    
		if (!oEvent)
			return;

        // detach onPagesModeChanged event
        this.m_oViewerCtrl.detachOwcEventHandler("pageModeChanged", this._onPagesModeChanged, this);          

        // synchronize panes to pages mode
	    var bIsNavPaneVisible = this.m_oNavigationPane.isVisible();
		if (oEvent.bDoublePageMode == bIsNavPaneVisible) // synchronize state of navigation pane to pages mode of viewer.
		{
		    //(onePageMode, navigation pane Visible) <-> (twoPageMode, navigation pane Hidden)
		    if (bIsNavPaneVisible)
		        this._HideNavigationPane(false);
		    else
		        this._ShowNavigationPane(false);
		}
    }
    
    function OwcDocViewerAgg_HoldGateFoldEvents(oEvent)
    {
	    /// <summary>
		///		Handler for the "gatefoldStatusChanged" event of the Flash Viewer object (comes from Action Script).		
		/// </summary>
		/// <param name="oEvent" type="Olive.Event">
	    ///		Event arguments object.
	    /// </param>
		/// <remarks>
		///     Toggles viewer page mode to two pages mode for unfold opperation
		///     Toggles viewer page mode to one pages mode for fold opperation on first page of document.
		/// </remarks>

        var bDoubleMode = this.m_oViewerCtrl.getModeDoublePage();
        var bGlobalDoublePageMode = this.get_GlobalDoublePageMode();
        var First = 1;
		var nDestinationPage = null;

        if (oEvent.nGatefoldStatus !== Olive.Controls.Viewer.GatefoldMode.closed) // gatefold is unfolded
        {
			if(bGlobalDoublePageMode && !oEvent.bAutomaticAction)
			{
				var bIsNavPaneVisible = this.m_oNavigationPane.isVisible();
				if (bIsNavPaneVisible)
					this._HideNavigationPane();
			}
        }
        else
        {
            // Gatefold is closed
            if (bDoubleMode && oEvent.nPageNo == First) 
            {
                // it is first page => change to one page mode and switch pane
                this.m_oViewerCtrl.attachOwcEventHandler("pageModeChanged", this._onPagesModeChanged, this);          
                this.m_oViewerCtrl.cmdChangeModeDoublePage(false); 
            }

			else if(bDoubleMode && bGlobalDoublePageMode && oEvent.nPageNo != First && this.m_oNavigationPane.isVisible())
			{//2pgMode + navPane open + not p.1: we opened GF from navPane, now we go back to 1pgMode
				nDestinationPage = this._getAbsolutePageNo(oEvent.nNextNavigation, oEvent.nPageNo);
                this.m_oViewerCtrl.cmdChangeModeDoublePage(false, nDestinationPage); 
			}

            else if (!bGlobalDoublePageMode)
            {
                // do not keep double page mode for closed gatefolds => change to one page mode
				nDestinationPage = this._getAbsolutePageNo(oEvent.nNextNavigation, oEvent.nPageNo);
                this.m_oViewerCtrl.cmdChangeModeDoublePage(false, nDestinationPage);
            }
        }
    }

	function OwcDocViewerAgg_getAbsolutePageNo( nRelativePageNo, nAbsolutePageNo )
	{
		/// <summary>
		///		Converts page number, possibly by relative navigation, to absolute page number.
		/// </summary>
		/// <param name="nRelativePageNo" type="number">
	    ///		Page number, or -100 (previous page) or -101 (next). If >0, then it overrides nAbsolutePageNo.
	    /// </param>
		/// <param name="nAbsolutePageNo" type="number">
	    ///		Page number to which previous/next in nRelativePageNo is relative.
	    /// </param>
		/// <returns type="number">
		///		nAbsolutePageNo adjusted by nRelativePageNo (if <0), or nRelativePageNo.
		///	</returns>
		var nRetValue = null;
		if("number" == typeof nRelativePageNo)
		{
			if(nRelativePageNo == Olive.Controls.DocViewerAgg.NavigationCodes.PreviousPage)
			{
				nRetValue = nAbsolutePageNo - 1; // Does not work for Heb?, but Heb has no gatefolds now
			}
			else if(nRelativePageNo == Olive.Controls.DocViewerAgg.NavigationCodes.NextPage)
			{
				nRetValue = nAbsolutePageNo + 1;
			}
			else
			{
				nRetValue = nRelativePageNo;
			}
		}
		else
			nRetValue = nAbsolutePageNo;//not in use
		return nRetValue;
	}
    
	function OwcDocViewerAgg_FindViewerParts()
	{
		/// <summary>
		///		Finds the main parts of the DocViewerAgg control.		
		/// </summary>
		/// <remarks>
		///		     
		/// </remarks>

		// Find viewer control:
		var arrControls = this.findControlsImplementing(Olive.Controls.IDocViewer);
		if (arrControls && (arrControls.length > 0))
			this.m_oViewerCtrl = arrControls[0];
		
		// Find root panes
		var oRootPane = this._FindUiControl(Olive.Controls.DocViewerAgg.UIElements.UIViewerRootPanel, 
											Olive.Controls.controlTypeNames.PaneList);
		
		// try to find navigation pane, splitter and viewer pane by UI elements
		this._FindPanesByUIType(oRootPane);
					
		if (oRootPane)
		{ 
			if (!this.m_oNavigationPane)
			    this.m_oNavigationPane = oRootPane.get_PaneItem(0);
			if (!this.m_oRootPaneSplitter)
			    this.m_oRootPaneSplitter = oRootPane.get_PaneItem(1);
			if (!this.m_oViewerPane)
			    this.m_oViewerPane = oRootPane.get_PaneItem(2);
		}

		this.m_oNavPageSwitcher = this._FindUiControl(Olive.Controls.DocViewerAgg.UIElements.UINavigationPages,
														Olive.Controls.controlTypeNames.PageSwitcher);
		this.m_oNavTabStrip = this._FindUiControl(Olive.Controls.DocViewerAgg.UIElements.UINavigationPages,
													Olive.Controls.controlTypeNames.TabStrip);

		if (this.m_oNavigationPane)
		{
			this.set_TocControl(this.m_oNavigationPane.findControlByType(Olive.Controls.controlTypeNames.TOC));
			this.set_SearchResControl(this.m_oNavigationPane.findControlByType(Olive.Controls.controlTypeNames.SearchRes));
            var arrThumblistControls = this.m_oNavigationPane.findControlsByType(Olive.Controls.controlTypeNames.ThumbList);
			if (arrThumblistControls)
			{
				for (var i=0; i < arrThumblistControls.length; i++)
				{
				    var oThumblistControl = arrThumblistControls[i];
				    var sEventKind = "";
				    var sKind = oThumblistControl.m_sKind.toLowerCase();						    
				    switch (sKind)
				    {
				        case Olive.Controls.ThumbList.ThumbListKind.DocPages:
				            this.set_PageThumbnailsControl(oThumblistControl);
				            break;
				        case Olive.Controls.ThumbList.ThumbListKind.QuickNavigation:
				            this.set_FeaturedPagesControl(oThumblistControl);
				            break;
				    }
				}
			}					   
		} // {if} Find navigation panes

		if (this.m_oNavPageSwitcher)
		{
			this.m_arrPanes = new Array();
			this._FindNavigationPane(Olive.Controls.DocViewerAgg.panes.TocPane, "ctrlPaneToc");
			this._FindNavigationPane(Olive.Controls.DocViewerAgg.panes.SearchPane, "ctrlPaneSearch");
			this._FindNavigationPane(Olive.Controls.DocViewerAgg.panes.ThumbnailsPane, "ctrlPaneThumbnails");
			this._FindNavigationPane(Olive.Controls.DocViewerAgg.panes.FeaturedPagesPane, "ctrlPaneFeaturedPages");
		}
	}
	
	function OwcDocViewerAgg_FindPanesByUIType(oRootPane)
	{
	    /// <summary>
		///		Finds main parts for DocViewerAgg - Navigation pane, Splitter and Viewer pane by UI elements if specified.		
		/// </summary>
		/// <param name="oRootPane" type="Olive.Controls.PaneList">
	    ///		Root pane-list control.
	    /// </param>
	    
	    var controlList = oRootPane.findControlsImplementing(Olive.Controls.IPaneListItem);
		if (!controlList || controlList.length < 1)
			return null;

		for (var i=0; i < controlList.length; ++i)
		{
			var control = controlList[i];
			var controlHtmlElement = control.get_HtmlElement();
			var uiElement = DHTML.getAttr(controlHtmlElement, Olive.Controls.attributes.Ui, "").toLowerCase();
			switch (uiElement)
			{
			    case Olive.Controls.DocViewerAgg.UIElements.UIViewerNavigationPanel.toLowerCase():
			        this.m_oNavigationPane = control;
			        break;
			    case Olive.Controls.DocViewerAgg.UIElements.UIViewerSplitter.toLowerCase():
			        this.m_oRootPaneSplitter = control;
			        break;
			    case Olive.Controls.DocViewerAgg.UIElements.UIViewerContentPanel.toLowerCase():
			        this.m_oViewerPane = control;
			        break;			    
			}
		}
	}

	function OwcDocViewerAgg_FindNavigationPane(sPaneName, sPaneId)
	{
		/// <summary>
		///		Finds a pane control in the Navigation pane by ID and adds it to the array of panes.		
		/// </summary>
		/// <param name="sPaneName" type="String">
	    ///		Name of the pane form the Control object Olive.Controls.DocViewerAgg.panes.
	    /// </param>
	    /// <param name="sPaneId" type="String">
	    ///		ID of the control in HTML. 
	    /// </param>
		
		var oPanePage = OwcGetControl(sPaneId);
		this.m_arrPanes[sPaneName] = 
			(oPanePage ? this.m_oNavPageSwitcher.indexOfItem(oPanePage) : -1);
	}

	function OwcDocViewerAgg_FindUiControl(uiElementType, controlType, parent)
	{
		/// <summary>
		///		Finds a control with a specified UI element type.
		///     If the control is not found, tries to find the first control with the specified control type. 		
		/// </summary>
		/// <param name="uiElementType" type="String">
	    ///		Name of the UI element type.
	    /// </param>
	    /// <param name="controlType" type="String">
	    ///		Name of the control type. 
	    /// </param>
		/// <param name="parent" type="Object">
	    ///		A parent object for the control. Set to DocViewerAgg object, if not specified. 
	    /// </param>
		
		var uiHtmlElement = this.getUiElement(uiElementType);
		if (uiHtmlElement)
			return OwcGetControlFromHtmlElem(uiHtmlElement, true);

		if (!controlType)
			return null;
		if (!parent)
			parent = this;
		var controlList = parent.findControlsByType(controlType);
		if (!controlList || controlList.length < 1)
			return null;

		for (var i=0; i < controlList.length; ++i)
		{
			var control = controlList[i];
			var controlHtmlElement = control.get_HtmlElement();
			var uiElement = DHTML.getAttr(controlHtmlElement, Olive.Controls.attributes.Ui, "").toLowerCase();
			if (uiElement == uiElementType.toLowerCase())
				return control;
		}

		return controlList[0];
	}
	
	function OwcDocViewerAgg_get_TocControl()
	{
		return this.m_oTOCCtrl;
	}

	function OwcDocViewerAgg_set_TocControl(control)
	{
		if (this.m_oTOCCtrl == control)
			return;

		// TODO: Detach previous binding
		this.m_oTOCCtrl = control;

		// Bind TOC to viewer
        if (control && this.m_oViewerCtrl)
	        this.m_oBindTocToDocViewer = Olive.Binding.BindToDocNavigation.BindControls(this.m_oTOCCtrl, this.m_oViewerCtrl);
	}

	function OwcDocViewerAgg_get_SearchResControl()
	{
		return this.m_oSearchResCtrl;
	}

	function OwcDocViewerAgg_set_SearchResControl(control)
	{
		if (this.m_oSearchResCtrl == control)
			return;

		// TODO: Detach previous binding
		this.m_oSearchResCtrl = control;

		// Bind TOC to viewer
        if (control && this.m_oViewerCtrl)
			this.m_oBindSearchResToDocViewer = Olive.Binding.BindSearchResultsToDocViewer.BindControls(this.m_oSearchResCtrl, this.m_oViewerCtrl);
	}

	function OwcDocViewerAgg_get_PageThumbnailsControl()
	{
		return this.m_oPageThumbnailsCtrl;
	}

	function OwcDocViewerAgg_set_PageThumbnailsControl(control)
	{
		if (this.m_oPageThumbnailsCtrl == control)
			return;

		// TODO: Detach previous binding
		this.m_oPageThumbnailsCtrl = control;

		// Bind page thumbnails list to viewer
        if (control && this.m_oViewerCtrl)
        {
			if (this.get_BindPageThumbnails())
				Olive.Binding.BindToDocNavigation.BindControls(this.m_oPageThumbnailsCtrl, this.m_oViewerCtrl);
			else   
				this.m_oPageThumbnailsCtrl.attachOwcEventHandler("contentItemClicked", this._onPageThumbnailContentItemClicked, this);
		}
	}

	function OwcDocViewerAgg_get_FeaturedPagesControl()
	{
		return this.m_oFeaturedPagesCtrl;
	}

	function OwcDocViewerAgg_set_FeaturedPagesControl(control)
	{
		if (this.m_oFeaturedPagesCtrl == control)
			return;

		// TODO: Detach previous binding
		this.m_oFeaturedPagesCtrl = control;

		// Bind page thumbnails list to viewer
        if (control && this.m_oViewerCtrl)
        {
			if (this.get_BindFeaturedPages())
				Olive.Binding.BindToDocNavigation.BindControls(this.m_oFeaturedPagesCtrl, this.m_oViewerCtrl);
			else   
				this.m_oFeaturedPagesCtrl.attachOwcEventHandler("contentItemClicked", this._onFeaturedPagesContentItemClicked, this);
		}
	}

    // Event handler to catch access restrictions events from Flash Viewer.
	function OwcDocViewerAgg_onErrorStatusReceived(eventData)
	{
	    // Change the TOC content to an error text.
	    this.m_oTOCCtrl.clearContent("<b style='color:red'>" + eventData.sErrorMessage + "</b>");
        
        // Display an error message.
        var descStart = "<description>";
        var descEnd = "</description>";
		var nStart = eventData.sErrorMessage.indexOf(descStart) + descStart.length;
		var nEnd = eventData.sErrorMessage.indexOf(descEnd, nStart);
		var sDesc = eventData.sErrorMessage.substr(nStart, nEnd-nStart);
	    this.displayMessage(sDesc);
	}

	JScript.Type.RegisterClass("Olive.Controls.DocViewerAgg", Olive.Controls.DocViewerAgg, Olive.Controls.Control, [Olive.Controls.IDataBound, Olive.IUiElements]);
	Olive.Controls.RegisterControlType(Olive.Controls.controlTypeNames.DocViewerAgg, Olive.Controls.DocViewerAgg);
} // Define Olive.Controls.DocViewerAgg class
