/// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Determine the label to show on the menu
            string label = "Map It!";
            if (!String.IsNullOrEmpty(CurrentRequest.Coordinates))
            {
                if (CurrentRequest.ViewerCode == "mapsearch")
                {
                    label = "Map Search";
                }
                else
                {
                    if (((CurrentItem.Images != null ) && ( CurrentItem.Images.Count > 1)) || ( String.Compare(CurrentItem.Type, "map", StringComparison.OrdinalIgnoreCase) != 0 ))
                    {
                        label = "Search Results";
                    }
                    else
                    {
                        label = "Map Coverage";
                    }
                }
            }

            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Allow the label to be implemented for this viewer from the database as an override
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                label = thisViewerInfo.Label;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest">  Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem("Description", "MARC View", null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Start with an empty label
            string first_label = String.Empty;

            // First, look at the viewer information from the database
            BriefItem_BehaviorViewer thisViewer = CurrentItem.Behaviors.Get_Viewer("HTML");
            if (!String.IsNullOrWhiteSpace(thisViewer.Label))
                first_label = thisViewer.Label;

            // Next, look for a page name in the METS
            if (String.IsNullOrEmpty(first_label))
            {
                foreach (BriefItem_FileGrouping thisPage in CurrentItem.Downloads)
                {
                    // Look for a HTML file on each page
                    foreach (BriefItem_File thisFile in thisPage.Files)
                    {
                        if (thisFile.File_Extension.IndexOf(".HTM", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            if (!String.IsNullOrWhiteSpace(thisPage.Label))
                                first_label = thisPage.Label;
                            break;
                        }
                    }
                }
            }

            // Finally, just default to HTML otherwise
            if (String.IsNullOrEmpty(first_label))
                first_label = "HTML";

            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Allow the label to be implemented for this viewer from the database as well
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                first_label = thisViewerInfo.Label;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(first_label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted)
        {
            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Start with the default label on the menu
            string label = "Video";

            // Allow the label to be implemented for this viewer
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                label = thisViewerInfo.Label;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted)
        {
            // Get the label
            string first_label = "FLASH";
            foreach (BriefItem_FileGrouping thisPage in CurrentItem.Downloads)
            {
                // Look for a flash file on each page
                foreach (BriefItem_File thisFile in thisPage.Files)
                {
                    if (String.Compare(thisFile.File_Extension, ".SWF", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        first_label = thisPage.Label;
                        break;
                    }
                }
            }

            // Allow the label to be implemented for this viewer from the database as well
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                first_label = thisViewerInfo.Label;

            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(first_label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        private static void HTML_Helper(TextWriter Output, Item_MenuItem MenuItem, Navigation_Object Current_Mode, string CurrentViewerCode, Dictionary<string, List<Item_MenuItem>> topMenuToChildren )
        {
            // If there are NO matches, left this top-level menu part was already taken care of
            if ((!topMenuToChildren.ContainsKey(MenuItem.MenuStripText)) || (topMenuToChildren[MenuItem.MenuStripText].Count == 0))
                return;

            // Is there only one menu part here
            List<Item_MenuItem> children = topMenuToChildren[MenuItem.MenuStripText];
            if ((children.Count == 1) && ( String.IsNullOrEmpty(MenuItem.MidMenuText )))
            {
                if (String.Compare(MenuItem.Code, CurrentViewerCode, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    Output.WriteLine("\t\t<li class=\"selected-sf-menu-item\">" + MenuItem.MenuStripText + "</li>");
                    return;
                }

                // When rendering for robots, provide the text and image, but not the link
                if (Current_Mode.Is_Robot)
                {
                    Output.WriteLine("\t\t<li class=\"selected-sf-menu-item\">" + MenuItem.MenuStripText + "</li>");
                }

                Output.WriteLine("\t\t<li><a href=\"" + MenuItem.Link + "\">" + MenuItem.MenuStripText + "</a></li>");
            }
            else
            {
                // Step through and see if this is selected
                bool selected = false;
                foreach (Item_MenuItem childMenu in children)
                {
                    if (String.Compare(childMenu.Code, CurrentViewerCode, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        selected = true;
                        break;
                    }
                }

                // Add the top-level
                string url = children[0].Link;
                if (selected)
                {
                    Output.WriteLine("\t\t<li class=\"selected-sf-menu-item-link\"><a href=\"" + url + "\">" + MenuItem.MenuStripText + "</a><ul>");
                }
                else
                {
                    Output.WriteLine("\t\t<li><a href=\"" + url + "\">" + MenuItem.MenuStripText + "</a><ul>");
                }

                // Add all the children
                foreach (Item_MenuItem childMenu in children)
                {
                    //if ((String.Compare(childMenu.Code, CurrentViewerCode, StringComparison.OrdinalIgnoreCase) == 0) || (Current_Mode.Is_Robot))
                    //{
                    //    Output.WriteLine("            <li class=\"selected-sf-menu-item\">" + childMenu.MidMenuText + "</li>");
                    //}
                    //else
                    //{
                    Output.WriteLine("\t\t\t<li><a href=\"" + childMenu.Link + "\">" + childMenu.MidMenuText + "</a></li>");
                    //}
                }

                // Close this top-level list and menu
                Output.WriteLine("\t\t</ul></li>");
            }

            // Clear this
            topMenuToChildren[MenuItem.MenuStripText].Clear();
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Determine the label to show
            string resource_type_upper = CurrentItem.Type.ToUpper();
            string label = "All Volumes";
            if (resource_type_upper.IndexOf("NEWSPAPER") >= 0)
            {
                label = "All Issues";
            }
            else if (resource_type_upper.IndexOf("MAP") >= 0)
            {
                label = "Related Maps";
            }
            else if (resource_type_upper.IndexOf("AERIAL") >= 0)
            {
                label = "Related Flights";
            }

            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Allow the label to be implemented for this viewer from the database override value
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                label = thisViewerInfo.Label;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public override void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode.Replace("#","1");
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem("Page Images", "Standard", null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted )
        {
            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Allow the label to be implemented for this viewer
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is null, or no label, use the default
            if ((thisViewerInfo == null) || (String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
            {
                // Add the item menu information using the default label
                Item_MenuItem menuItem = new Item_MenuItem("Video", null, null, url, ViewerCode);
                MenuItems.Add(menuItem);
            }
            else
            {
                // Add the item menu information using the custom level
                Item_MenuItem menuItem = new Item_MenuItem(thisViewerInfo.Label, null, null, url, ViewerCode);
                MenuItems.Add(menuItem);
            }
        }
        /// <summary> Gets the menu items related to this viewer that should be included on the main item (digital resource) menu </summary>
        /// <param name="CurrentItem"> Digital resource object, which can be used to ensure if and how this viewer should appear 
        /// in the main item (digital resource) menu </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="MenuItems"> List of menu items, to which this method may add one or more menu items </param>
        /// <param name="IpRestricted"> Flag indicates if this item is IP restricted AND if the current user is outside the ranges </param>
        public void Add_Menu_items(BriefItemInfo CurrentItem, User_Object CurrentUser, Navigation_Object CurrentRequest, List<Item_MenuItem> MenuItems, bool IpRestricted)
        {
            // Try to get the TEI file name
            string tei_file = CurrentItem.Behaviors.Get_Setting("TEI.Source_File");
            if (tei_file == null)
            {
                // Ensure the TEI file really exists
                return;
            }

            // Ensure the TEI file really exists
            if (!SobekFileSystem.FileExists(CurrentItem, tei_file))
                return;

            // Look for the label in the METS structure map
            string first_label = "TEI";
            if (CurrentItem.Downloads != null)
            {
                foreach (BriefItem_FileGrouping thisPage in CurrentItem.Downloads)
                {
                    // Look for a flash file on each page
                    foreach (BriefItem_File thisFile in thisPage.Files)
                    {
                        if (String.Compare(thisFile.Name, tei_file, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            first_label = thisPage.Label.Replace(".xml", "").Replace(".XML", "");
                            break;
                        }
                    }
                }
            }

            // Allow the label to be implemented for this viewer from the database as well
            BriefItem_BehaviorViewer thisViewerInfo = CurrentItem.Behaviors.Get_Viewer(ViewerCode);

            // If this is found, and has a custom label, use that
            if ((thisViewerInfo != null) && (!String.IsNullOrWhiteSpace(thisViewerInfo.Label)))
                first_label = thisViewerInfo.Label;

            // Get the URL for this
            string previous_code = CurrentRequest.ViewerCode;
            CurrentRequest.ViewerCode = ViewerCode;
            string url = UrlWriterHelper.Redirect_URL(CurrentRequest);
            CurrentRequest.ViewerCode = previous_code;

            // Add the item menu information
            Item_MenuItem menuItem = new Item_MenuItem(first_label, null, null, url, ViewerCode);
            MenuItems.Add(menuItem);
        }
        private static void HTML_Helper(TextWriter Output, Item_MenuItem MenuItem, Navigation_Object Current_Mode, string CurrentViewerCode, Dictionary <string, List <Item_MenuItem> > TopMenuToChildren, bool Include_Links)
        {
            // If there are NO matches, left this top-level menu part was already taken care of
            if ((!TopMenuToChildren.ContainsKey(MenuItem.MenuStripText)) || (TopMenuToChildren[MenuItem.MenuStripText].Count == 0))
            {
                return;
            }

            // Is there only one menu part here
            List <Item_MenuItem> children = TopMenuToChildren[MenuItem.MenuStripText];

            if ((children.Count == 1) && (String.IsNullOrEmpty(MenuItem.MidMenuText)))
            {
                if (String.Compare(MenuItem.Code, CurrentViewerCode, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    Output.WriteLine("\t\t<li class=\"selected-sf-menu-item\">" + MenuItem.MenuStripText + "</li>");
                    return;
                }

                // When rendering for robots, provide the text and image, but not the link
                if (!Include_Links)
                {
                    Output.WriteLine("\t\t<li><a href=\"\">" + MenuItem.MenuStripText + "</a></li>");
                }
                else
                {
                    Output.WriteLine("\t\t<li><a href=\"" + MenuItem.Link + "\">" + MenuItem.MenuStripText + "</a></li>");
                }
            }
            else
            {
                // Step through and see if this is selected
                bool selected = false;
                foreach (Item_MenuItem childMenu in children)
                {
                    if (String.Compare(childMenu.Code, CurrentViewerCode, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        selected = true;
                        break;
                    }
                }

                // Add the top-level
                string url = children[0].Link;
                if (selected)
                {
                    if (!Include_Links)
                    {
                        Output.WriteLine("\t\t<li class=\"selected-sf-menu-item-link\"><a href=\"\">" + MenuItem.MenuStripText + "</a><ul>");
                    }
                    else
                    {
                        Output.WriteLine("\t\t<li class=\"selected-sf-menu-item-link\"><a href=\"" + url + "\">" + MenuItem.MenuStripText + "</a><ul>");
                    }
                }
                else
                {
                    if (!Include_Links)
                    {
                        Output.WriteLine("\t\t<li><a href=\"\">" + MenuItem.MenuStripText + "</a><ul>");
                    }
                    else
                    {
                        Output.WriteLine("\t\t<li><a href=\"" + url + "\">" + MenuItem.MenuStripText + "</a><ul>");
                    }
                }

                // Add all the children
                foreach (Item_MenuItem childMenu in children)
                {
                    if (!Include_Links)
                    {
                        Output.WriteLine("\t\t\t<li><a href=\"\">" + childMenu.MidMenuText + "</a></li>");
                    }
                    else
                    {
                        Output.WriteLine("\t\t\t<li><a href=\"" + childMenu.Link + "\">" + childMenu.MidMenuText + "</a></li>");
                    }
                }

                // Close this top-level list and menu
                Output.WriteLine("\t\t</ul></li>");
            }

            // Clear this
            TopMenuToChildren[MenuItem.MenuStripText].Clear();
        }