/// <summary>
        /// Builds the link to the related item
        /// </summary>
        /// <param name="relatedCMSNode">The related CMS node.</param>
        /// <returns></returns>
        private HtmlGenericControl BuildLinkToRelated(CMSNode relatedCMSNode)
        {
            HtmlGenericControl li = new HtmlGenericControl("li");

            if (this.options.RepeatDirection == RepeatDirection.Horizontal)
            {
                li.Attributes.Add("style", "float:left;margin-right:5px;");
            }

            HtmlAnchor a = new HtmlAnchor();

            string img = string.Empty;

            switch (uQuery.GetUmbracoObjectType(relatedCMSNode.nodeObjectType))
            {
                case uQuery.UmbracoObjectType.Document:

                    a.HRef = "javascript:jumpToEditContent(" + relatedCMSNode.Id + ");";

                    // WARNING - getting the content icon cia the document api may potentially be slow
                    img = "/umbraco/images/umbraco/" + uQuery.GetDocument(relatedCMSNode.Id).ContentTypeIcon;

                    break;

                case uQuery.UmbracoObjectType.Media:

                    a.HRef = "javascript:jumpToEditMedia(" + relatedCMSNode.Id + ");";
                    img = "/umbraco/images/umbraco/" + uQuery.GetMedia(relatedCMSNode.Id).ContentTypeIcon;

                    break;

                case uQuery.UmbracoObjectType.Member:

                    a.HRef = "javascript:jumpToEditMember(" + relatedCMSNode.Id + ");";
                    img = "/umbraco/images/umbraco/" + uQuery.GetMember(relatedCMSNode.Id).ContentTypeIcon;

                    break;
            }

            // is there a macro ?
            if (string.IsNullOrWhiteSpace(this.options.MacroAlias))
            {
                // default - no macro set
                a.Controls.Add(new HtmlImage() { Src = img });
                a.Controls.Add(new LiteralControl(relatedCMSNode.Text));
            }
            else
            {
                // use macro for markup - to execute a macro, at least one item must be published - as context needed to execute macro ?

                // get the node for the current page
                Node contextNode = uQuery.GetCurrentNode();

                // if the node is null (either document is unpublished, or rendering from outside the content section)
                if (contextNode == null)
                {
                    // then get the first child node from the XML content root
                    contextNode = uQuery.GetNodesByXPath(string.Concat("descendant::*[@parentID = ", uQuery.RootNodeId, "]")).FirstOrDefault();
                }

                if (contextNode != null)
                {
                    // load the page reference
                    HttpContext.Current.Items["pageID"] = contextNode.Id;
                    //HttpContext.Current.Items["pageElements"] = new page(contextNode.Id, contextNode.Version).Elements;
                }
                else
                {
                    // nothing published ! so can't run a macro
                }

                Macro macro = new Macro() { Alias = this.options.MacroAlias };
                macro.MacroAttributes.Add("id", relatedCMSNode.Id);
                a.Controls.Add(new LiteralControl(macro.RenderToString()));
            }

            li.Controls.Add(a);

            return li;
        }